initial commit
This commit is contained in:
49
app/Model/AccessInfo.php
Normal file
49
app/Model/AccessInfo.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
class AccessInfo extends AppModel
|
||||
{
|
||||
var $name='AccessInfo';
|
||||
|
||||
|
||||
public function saveAccessInfo($formData){
|
||||
|
||||
$error = "";
|
||||
|
||||
$form["id"] = trim($formData["id"]);
|
||||
$form["unique_url"] = trim($formData["unique_url"]);
|
||||
$form["access_time"] = date('Y-m-d H:i:s');
|
||||
|
||||
$fileds = array('id','unique_url','access_time');
|
||||
|
||||
$data["AccessInfo"] = $form;
|
||||
if(!empty($form["id"]) && !empty($form["unique_url"])){
|
||||
if(!$this->save($data,false,$fileds)){
|
||||
$error = "22";
|
||||
}
|
||||
}else{
|
||||
$error = "23";
|
||||
}
|
||||
|
||||
return $error;
|
||||
}
|
||||
|
||||
public function getExpiredExpenses($month,$type=1){
|
||||
$type_value = $type==1?"months":"days";
|
||||
date_default_timezone_set("UTC");
|
||||
$range = date('Y-m-d H:i:s', strtotime("-{$month} {$type_value}"));
|
||||
$result = $this->find('all',
|
||||
array(
|
||||
'conditions' => array('AccessInfo.access_time < ' => $range
|
||||
)
|
||||
));
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function deleteAllExpiredExpenses($deleteList){
|
||||
$result = $this->deleteAll(
|
||||
array(array('id' => $deleteList))
|
||||
);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
52
app/Model/AccessKey.php
Normal file
52
app/Model/AccessKey.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
class AccessKey extends AppModel
|
||||
{
|
||||
var $name='AccessKey';
|
||||
|
||||
public function saveAccessKey($formData){
|
||||
|
||||
$error = "";
|
||||
|
||||
$form["device_id"] = trim($formData["device_id"]);
|
||||
$form["secret_key"] = trim($formData["secret_key"]);
|
||||
|
||||
$form["created_on"] = trim($formData["created_on"]);
|
||||
|
||||
$fileds = array('device_id', 'secret_key', 'created_on');
|
||||
|
||||
$data["AccessKey"] = $form;
|
||||
if(!empty($form["device_id"]) && !empty($form["secret_key"])){
|
||||
if(!$this->save($data,false,$fileds)){
|
||||
$error = "22";
|
||||
}
|
||||
}else{
|
||||
$error = "23";
|
||||
}
|
||||
|
||||
return $error;
|
||||
}
|
||||
|
||||
public function getAccessToken($device_id)
|
||||
{
|
||||
$error = "";
|
||||
$access_key = $this->find('first', array(
|
||||
'conditions' => array('device_id' => $device_id),
|
||||
'order'=> array('created_on'=>'desc')
|
||||
) );
|
||||
if(empty($access_key)) {
|
||||
$error = "23";
|
||||
return $error;
|
||||
} else {
|
||||
return $access_key['AccessKey']['secret_key'];
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteAccessKey($device_id)
|
||||
{
|
||||
$access_key = $this->find('first', array(
|
||||
'conditions' => array('device_id' => $device_id),
|
||||
'order'=> array('created_on'=>'desc')
|
||||
) );
|
||||
$this->delete($access_key['AccessKey']['id']);
|
||||
}
|
||||
}
|
||||
37
app/Model/AppModel.php
Normal file
37
app/Model/AppModel.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* Application model for CakePHP.
|
||||
*
|
||||
* This file is application-wide model file. You can put all
|
||||
* application-wide model-related methods here.
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package app.Model
|
||||
* @since CakePHP(tm) v 0.2.9
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('ExtraGroupExpenseTrait', 'Controller/Traits');
|
||||
App::uses('Model', 'Model');
|
||||
|
||||
/**
|
||||
* Application model for Cake.
|
||||
*
|
||||
* Add your application-wide methods in the class below, your models
|
||||
* will inherit them.
|
||||
*
|
||||
* @package app.Model
|
||||
*/
|
||||
class AppModel extends Model {
|
||||
|
||||
use ExtraGroupExpenseTrait;
|
||||
|
||||
}
|
||||
1039
app/Model/Backup.php
Normal file
1039
app/Model/Backup.php
Normal file
File diff suppressed because it is too large
Load Diff
0
app/Model/Behavior/empty
Normal file
0
app/Model/Behavior/empty
Normal file
7
app/Model/Category.php
Normal file
7
app/Model/Category.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
class Category extends AppModel
|
||||
{
|
||||
var $name='Category';
|
||||
|
||||
|
||||
}
|
||||
34
app/Model/Comment.php
Normal file
34
app/Model/Comment.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
class Comment extends AppModel
|
||||
{
|
||||
var $name='Comment';
|
||||
|
||||
function createFeedback($inputData){
|
||||
|
||||
$result = NULL;
|
||||
|
||||
|
||||
$form["email"] = trim($inputData["feedbackemail"]);
|
||||
$form["comment"] = trim($inputData["comment"]);
|
||||
$form["ip"] = trim($inputData["ip"]);
|
||||
$form["create_date"] = trim($inputData["create_date"]);
|
||||
|
||||
|
||||
$fileds = array('email','comment','ip','create_date');
|
||||
|
||||
|
||||
$dbData["Comment"] = $form;
|
||||
|
||||
//print_r($data["Feeback"]);exit;
|
||||
|
||||
if(!$this->save($dbData,false,$fileds)){
|
||||
$result["22"] = __("LBL_EXPENSE_NOT_SAVED");
|
||||
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
0
app/Model/Datasource/empty
Normal file
0
app/Model/Datasource/empty
Normal file
122
app/Model/DemoExpense.php
Normal file
122
app/Model/DemoExpense.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
class DemoExpense extends AppModel
|
||||
{
|
||||
var $name = 'DemoExpense';
|
||||
|
||||
|
||||
|
||||
public function setORMForDemoGroupExpense(){
|
||||
$this->bindModel(
|
||||
|
||||
array('hasMany' => array(
|
||||
'DemoParticipant' => array(
|
||||
'className' => 'DemoParticipant',
|
||||
'conditions' => array('DemoParticipant.expense_id' => 'DemoExpense.id'),
|
||||
'order' => 'DemoParticipant.create_date ASC',
|
||||
'foreignKey' => 'expense_id'
|
||||
),
|
||||
'DemoGroupExpense' => array(
|
||||
'className' =>'DemoGroupExpense',
|
||||
'conditions' => array('DemoGroupExpense.expense_id' => 'DemoExpense.id'),
|
||||
'order' => 'DemoGroupExpense.create_date ASC',
|
||||
'foreignKey' => 'expense_id'
|
||||
)
|
||||
|
||||
)));
|
||||
|
||||
}
|
||||
|
||||
public function setORMForDemoFamilyExpense(){
|
||||
$this->bindModel(array('hasMany' => array(
|
||||
|
||||
'DemoFamilyExpense' => array(
|
||||
'className' =>'DemoFamilyExpense',
|
||||
'conditions' => array('DemoFamilyExpense.expense_id' => 'DemoExpense.id'),
|
||||
'order' => 'DemoFamilyExpense.create_date ASC',
|
||||
'foreignKey' => 'expense_id'
|
||||
)
|
||||
|
||||
)));
|
||||
}
|
||||
|
||||
public function setORMForDemoMess(){
|
||||
|
||||
$this->bindModel(array('hasMany' => array(
|
||||
'DemoParticipant' => array(
|
||||
'className' => 'DemoParticipant',
|
||||
'conditions' => array('DemoParticipant.expense_id' => 'DemoExpense.id'),
|
||||
'order' => 'DemoParticipant.create_date ASC',
|
||||
'foreignKey' => 'expense_id'
|
||||
),
|
||||
'DemoGroupExpense' => array(
|
||||
'className' =>'DemoGroupExpense',
|
||||
'conditions' => array('DemoGroupExpense.expense_id' => 'DemoExpense.id'),
|
||||
'order' => 'DemoGroupExpense.create_date ASC',
|
||||
'foreignKey' => 'expense_id'
|
||||
) ,
|
||||
'DemoMeal' => array(
|
||||
'className' =>'DemoMeal',
|
||||
'conditions' => array('DemoMeal.expense_id' => 'DemoExpense.id'),
|
||||
'order' => 'DemoMeal.date ASC',
|
||||
'foreignKey' => 'expense_id'
|
||||
|
||||
)
|
||||
|
||||
)));
|
||||
|
||||
}
|
||||
|
||||
public function getDemoGroupExpenseInfoByURL($unique_url){
|
||||
|
||||
$expenseType = substr($unique_url, 0, 1);
|
||||
if($expenseType == "2" || $expenseType == "7"){
|
||||
$this->setORMForDemoMess();
|
||||
} else {
|
||||
$this->setORMForDemoGroupExpense();
|
||||
}
|
||||
|
||||
|
||||
return $this->find('first', array('conditions' => array('DemoExpense.unique_url' =>$unique_url)));
|
||||
}
|
||||
|
||||
public function getDemoFamilyExpenseInfoByURL($unique_url){
|
||||
|
||||
$this->setORMForDemoFamilyExpense();
|
||||
|
||||
return $this->find('first', array('conditions' => array('DemoExpense.unique_url' =>$unique_url)));
|
||||
}
|
||||
|
||||
function findExpenseInfoByIds($expenseIdList){
|
||||
|
||||
$data = NULL;
|
||||
if(!empty($expenseIdList) && count($expenseIdList) > 0){
|
||||
$str = implode(",",$expenseIdList);
|
||||
|
||||
$this->hasMany = array();
|
||||
|
||||
$result = $this->find('all', array('conditions' => array(
|
||||
'DemoExpense.id in ('.$str.')'
|
||||
),
|
||||
'order' => 'DemoExpense.create_date DESC'));
|
||||
|
||||
if(!empty($result)){
|
||||
$data["expenseList"] = $result;
|
||||
App::import('model','DemoParticipant');
|
||||
$participant = new DemoParticipant();
|
||||
$participantInfo = $participant->find('all', array('conditions' => array(
|
||||
'DemoParticipant.expense_id in ('.$str.') ' ,'is_creator'=>'1'
|
||||
)));
|
||||
|
||||
$data["participantList"]= $participantInfo;
|
||||
}
|
||||
}
|
||||
|
||||
// $log = $this->getDataSource()->getLog(false, false);
|
||||
// debug($log);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
9
app/Model/DemoFamilyExpense.php
Normal file
9
app/Model/DemoFamilyExpense.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
class DemoFamilyExpense extends AppModel
|
||||
{
|
||||
var $name='DemoFamilyExpense';
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
6
app/Model/DemoGroupExpense.php
Normal file
6
app/Model/DemoGroupExpense.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
class DemoGroupExpense extends AppModel
|
||||
{
|
||||
var $name='DemoGroupExpense';
|
||||
|
||||
}
|
||||
7
app/Model/DemoMeal.php
Normal file
7
app/Model/DemoMeal.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
class DemoMeal extends AppModel
|
||||
{
|
||||
var $name='DemoMeal';
|
||||
|
||||
|
||||
}
|
||||
7
app/Model/DemoParticipant.php
Normal file
7
app/Model/DemoParticipant.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
class DemoParticipant extends AppModel
|
||||
{
|
||||
var $name='DemoParticipant';
|
||||
|
||||
}
|
||||
?>
|
||||
18
app/Model/Deposit.php
Normal file
18
app/Model/Deposit.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
class Deposit extends AppModel
|
||||
{
|
||||
var $name='Deposit';
|
||||
|
||||
|
||||
|
||||
function list($conditions = array() )
|
||||
{
|
||||
return $this->find('all', array('conditions' => $conditions));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
38
app/Model/EmailHistory.php
Normal file
38
app/Model/EmailHistory.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
class EmailHistory extends AppModel
|
||||
{
|
||||
var $name = 'EmailHistory';
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function insertEmailHistory($form){
|
||||
|
||||
$result = null;
|
||||
//1 = Input data format is not correct
|
||||
//4 = participant already exist in database
|
||||
//22 = Data not saved successfully in Database
|
||||
|
||||
|
||||
$fileds = array('unique_url','sent_to','ip','create_date');
|
||||
|
||||
|
||||
$dbData["EmailHistory"] = $form;
|
||||
|
||||
//insert into the table group_expenses
|
||||
if(!$this->save($dbData,false,$fileds)){
|
||||
$result["22"] = __("LBL_EMAIL_HISTORY_SAVED");
|
||||
}
|
||||
|
||||
//$log = $this->getDataSource()->getLog(false, false);
|
||||
// debug($log);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
674
app/Model/Expense.php
Normal file
674
app/Model/Expense.php
Normal file
@@ -0,0 +1,674 @@
|
||||
<?php
|
||||
class Expense extends AppModel
|
||||
{
|
||||
var $name = 'Expense';
|
||||
public $hasOne = 'GroupSettings';
|
||||
|
||||
function setGroupExpenseValidation()
|
||||
{
|
||||
|
||||
$this->validate = array(
|
||||
'title' => array(
|
||||
|
||||
'notBlank' => array(
|
||||
'rule' => 'notBlank',
|
||||
'message' => __('TITLE_NOT_EMPTY_MAX_CHAR')
|
||||
),
|
||||
'between' => array(
|
||||
'rule' => array('maxLength', '50'),
|
||||
'message' => __('TITLE_NOT_EMPTY_MAX_CHAR')
|
||||
)
|
||||
),
|
||||
'YourName' => array(
|
||||
|
||||
'notBlank' => array(
|
||||
'rule' => 'notBlank',
|
||||
'message' => __('YOUR_NAME_NOT_EMPTY_MAX_CHAR')
|
||||
),
|
||||
'between' => array(
|
||||
'rule' => array('maxLength', PARTICIPENT_NAME_LENGTH),
|
||||
'message' => __('YOUR_NAME_NOT_EMPTY_MAX_CHAR')
|
||||
),
|
||||
'noForbiddenChars' => array(
|
||||
'rule' => ['custom', '/^[^,|]*$/'],
|
||||
'message' => __('LBL_PARTICIPENT_NAME_ERROR')
|
||||
)
|
||||
),
|
||||
'participants' => array(
|
||||
|
||||
'notBlank' => array(
|
||||
'rule' => array('participantLengthCheck', PARTICIPENT_NAME_LENGTH),
|
||||
'message' => __('PARTICIPANT_NOT_EMPTY_MAX_CHAR')
|
||||
),
|
||||
'duplicacy' => array(
|
||||
'rule' => array('participantDuplicacyCheck', 'YourName'),
|
||||
'message' => __('PARTICIPANT_DUPCICATE')
|
||||
)
|
||||
|
||||
),
|
||||
'emails' => array(
|
||||
|
||||
'notBlank' => array(
|
||||
'rule' => array('validEmailCheck'),
|
||||
'message' => __('EMAIL_IS_NOT_VALIE')
|
||||
)
|
||||
|
||||
),
|
||||
'currency' => array(
|
||||
|
||||
'notBlank' => array(
|
||||
'rule' => 'notBlank',
|
||||
'message' => __('CURRENCY_NOT_EMPTY_MAX_CHAR')
|
||||
),
|
||||
'between' => array(
|
||||
'rule' => array('maxLength', '3'),
|
||||
'message' => __('CURRENCY_NOT_EMPTY_MAX_CHAR')
|
||||
)
|
||||
),
|
||||
'captcha' => array(
|
||||
|
||||
'notBlank' => array(
|
||||
'rule' => 'notBlank',
|
||||
'message' => __('CAPTCHA_NOT_EMPTY_MAX_CHAR')
|
||||
),
|
||||
'between' => array(
|
||||
'rule' => array('maxLength', '5'),
|
||||
'message' => __('CAPTCHA_NOT_EMPTY_MAX_CHAR')
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function setFamilyExpenseValidation()
|
||||
{
|
||||
|
||||
$this->validate = array(
|
||||
'title' => array(
|
||||
|
||||
'notBlank' => array(
|
||||
'rule' => 'notBlank',
|
||||
'message' => __('TITLE_NOT_EMPTY_MAX_CHAR')
|
||||
),
|
||||
'between' => array(
|
||||
'rule' => array('maxLength', '50'),
|
||||
'message' => __('TITLE_NOT_EMPTY_MAX_CHAR')
|
||||
)
|
||||
),
|
||||
|
||||
'currency' => array(
|
||||
|
||||
'notBlank' => array(
|
||||
'rule' => 'notBlank',
|
||||
'message' => __('CURRENCY_NOT_EMPTY_MAX_CHAR')
|
||||
),
|
||||
'between' => array(
|
||||
'rule' => array('maxLength', '3'),
|
||||
'message' => __('CURRENCY_NOT_EMPTY_MAX_CHAR')
|
||||
)
|
||||
),
|
||||
'emails' => array(
|
||||
|
||||
'notBlank' => array(
|
||||
'rule' => array('validEmailCheck'),
|
||||
'message' => __('EMAIL_IS_NOT_VALIE')
|
||||
)
|
||||
|
||||
),
|
||||
'captcha' => array(
|
||||
|
||||
'notBlank' => array(
|
||||
'rule' => 'notBlank',
|
||||
'message' => __('CAPTCHA_NOT_EMPTY_MAX_CHAR')
|
||||
),
|
||||
'between' => array(
|
||||
'rule' => array('maxLength', '5'),
|
||||
'message' => __('CAPTCHA_NOT_EMPTY_MAX_CHAR')
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function setGroupExpenseModifyValidation()
|
||||
{
|
||||
|
||||
$this->validate = array(
|
||||
'title' => array(
|
||||
|
||||
'notBlank' => array(
|
||||
'rule' => 'notBlank',
|
||||
'message' => __('TITLE_NOT_EMPTY_MAX_CHAR')
|
||||
),
|
||||
'between' => array(
|
||||
'rule' => array('maxLength', '50'),
|
||||
'message' => __('TITLE_NOT_EMPTY_MAX_CHAR')
|
||||
),
|
||||
'noForbiddenChars' => array(
|
||||
'rule' => ['custom', '/^[^,|]*$/'],
|
||||
'message' => __('LBL_PARTICIPENT_NAME_ERROR')
|
||||
)
|
||||
),
|
||||
'currency' => array(
|
||||
|
||||
'notBlank' => array(
|
||||
'rule' => 'notBlank',
|
||||
'message' => __('CURRENCY_NOT_EMPTY_MAX_CHAR')
|
||||
),
|
||||
'between' => array(
|
||||
'rule' => array('maxLength', '3'),
|
||||
'message' => __('CURRENCY_NOT_EMPTY_MAX_CHAR')
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/*public $hasMany = array(
|
||||
'Participant' => array(
|
||||
'className' => 'Participant',
|
||||
'conditions' => array('Participant.expense_id' => 'Expense.id'),
|
||||
'order' => 'Participant.create_date ASC'
|
||||
),
|
||||
'GroupExpense' => array(
|
||||
'className' =>'GroupExpense',
|
||||
'conditions' => array('GroupExpense.expense_id' => 'Expense.id'),
|
||||
'order' => 'GroupExpense.create_date ASC') ,
|
||||
'Meal' => array(
|
||||
'className' =>'Meal',
|
||||
'conditions' => array('Meal.expense_id' => 'Expense.id'),
|
||||
'order' => 'Meal.date ASC')
|
||||
|
||||
);*/
|
||||
|
||||
public function setORMForGroupExpense()
|
||||
{
|
||||
$this->bindModel(array('hasMany' => array(
|
||||
'Participant' => array(
|
||||
'className' => 'Participant',
|
||||
'conditions' => array('Participant.expense_id' => 'Expense.id'),
|
||||
'order' => 'Participant.create_date ASC'
|
||||
),
|
||||
'GroupExpense' => array(
|
||||
'className' => 'GroupExpense',
|
||||
'conditions' => array('GroupExpense.expense_id' => 'Expense.id'),
|
||||
'order' => 'GroupExpense.create_date ASC'
|
||||
)
|
||||
|
||||
)));
|
||||
}
|
||||
|
||||
public function setORMForFamilyExpense()
|
||||
{
|
||||
$this->bindModel(array('hasMany' => array(
|
||||
|
||||
'FamilyExpense' => array(
|
||||
'className' => 'FamilyExpense',
|
||||
'conditions' => array('FamilyExpense.expense_id' => 'Expense.id'),
|
||||
'order' => 'FamilyExpense.create_date ASC'
|
||||
)
|
||||
|
||||
)));
|
||||
}
|
||||
|
||||
public function setORMForMess()
|
||||
{
|
||||
|
||||
$this->bindModel(array('hasMany' => array(
|
||||
'Participant' => array(
|
||||
'className' => 'Participant',
|
||||
'conditions' => array('Participant.expense_id' => 'Expense.id'),
|
||||
'order' => 'Participant.create_date ASC'
|
||||
),
|
||||
'GroupExpense' => array(
|
||||
'className' => 'GroupExpense',
|
||||
'conditions' => array('GroupExpense.expense_id' => 'Expense.id'),
|
||||
'order' => 'GroupExpense.create_date ASC'
|
||||
),
|
||||
'Meal' => array(
|
||||
'className' => 'Meal',
|
||||
'conditions' => array('Meal.expense_id' => 'Expense.id'),
|
||||
'order' => 'Meal.date ASC'
|
||||
)
|
||||
|
||||
)));
|
||||
}
|
||||
|
||||
public function getGroupExpenseInfoByURL($unique_url)
|
||||
{
|
||||
|
||||
$expenseType = substr($unique_url, 0, 1);
|
||||
if ($expenseType == "2" || $expenseType == "7") {
|
||||
$this->setORMForMess();
|
||||
} else {
|
||||
$this->setORMForGroupExpense();
|
||||
}
|
||||
$this->unbindModel(
|
||||
array(
|
||||
'hasOne' => array('GroupSettings')
|
||||
)
|
||||
);
|
||||
return $this->find('first', array('conditions' => array('BINARY(Expense.unique_url)' => $unique_url)));
|
||||
}
|
||||
|
||||
public function getFamilyExpenseInfoByURL($unique_url)
|
||||
{
|
||||
|
||||
$this->setORMForFamilyExpense();
|
||||
$this->unbindModel(
|
||||
array(
|
||||
'hasOne' => array('GroupSettings')
|
||||
)
|
||||
);
|
||||
return $this->find('first', array('conditions' => array('BINARY(Expense.unique_url)' => $unique_url)));
|
||||
}
|
||||
|
||||
public function participantLengthCheck($check, $limit)
|
||||
{
|
||||
|
||||
$result = true;
|
||||
|
||||
$value = trim($check["participants"]);
|
||||
if ($value != "") {
|
||||
$valueArray = explode(",", $value);
|
||||
|
||||
foreach ($valueArray as $key => $value) {
|
||||
if (mb_strlen($value, 'UTF-8') > $limit) {
|
||||
$result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
public function validEmailCheck($check)
|
||||
{
|
||||
|
||||
$result = true;
|
||||
|
||||
$value = trim($check["emails"]);
|
||||
if ($value != "") {
|
||||
if (filter_var($value, FILTER_VALIDATE_EMAIL) === false) {
|
||||
$result = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
public function participantDuplicacyCheck($check, $yourName)
|
||||
{
|
||||
$result = true;
|
||||
|
||||
|
||||
$value = trim($check["participants"]);
|
||||
if ($value != "") {
|
||||
$valueArray = explode(",", $value);
|
||||
foreach ($valueArray as $key => $value) {
|
||||
$valueArray[$key] = trim(strtolower($value));
|
||||
}
|
||||
|
||||
$length = count($valueArray);
|
||||
$unique_array = array_unique($valueArray);
|
||||
if (count($unique_array) != $length) {
|
||||
$result = false;
|
||||
} else {
|
||||
foreach ($valueArray as $key => $value) {
|
||||
if (trim(strtolower($value)) == trim(strtolower($this->data["Expense"][$yourName]))) {
|
||||
$result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function modifyExpense($expenseFormArray)
|
||||
{
|
||||
|
||||
$result = null;
|
||||
|
||||
$form["id"] = trim($expenseFormArray["id"]);
|
||||
$form["title"] = trim($expenseFormArray["title"]);
|
||||
$form["currency"] = trim($expenseFormArray["currency"]);
|
||||
$form["description"] = trim($expenseFormArray["description"]);
|
||||
$form["version"] = trim($expenseFormArray["version"]);
|
||||
if (isset($expenseFormArray["default_meal"])) {
|
||||
$form["default_meal"] = trim($expenseFormArray["default_meal"]);
|
||||
$fileds = array('id', 'title', 'currency', 'description', 'update_date', 'update_user', 'default_meal', 'version');
|
||||
} else {
|
||||
$fileds = array('id', 'title', 'currency', 'description', 'update_date', 'update_user', 'version');
|
||||
}
|
||||
$form["update_date"] = time();
|
||||
$form["update_user"] = "system";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$data["Expense"] = $form;
|
||||
if (!$this->save($data, false, $fileds)) {
|
||||
$result["22"] = "expense not has been saved successfully";
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function createExpense($expenseFormArray, $isRemote, $archieved = false)
|
||||
{
|
||||
|
||||
$result = "";
|
||||
|
||||
$form["unique_url"] = "NEW";
|
||||
$form["title"] = trim($expenseFormArray["title"]);
|
||||
$form["currency"] = trim($expenseFormArray["currency"]);
|
||||
$form["description"] = trim($expenseFormArray["description"]);
|
||||
$form["language"] = $expenseFormArray["language"];
|
||||
$form["expense_type"] = $expenseFormArray["expense_type"]; // 1 = Group expense
|
||||
$form["source"] = $expenseFormArray["source"]; //1=web,2=mobile,3=facebook
|
||||
|
||||
$form["create_date"] = $expenseFormArray["create_date"]; //
|
||||
|
||||
if (!empty($expenseFormArray["create_user"])) {
|
||||
$form["create_user"] = $expenseFormArray["create_user"];
|
||||
} else {
|
||||
$form["create_user"] = "system";
|
||||
}
|
||||
|
||||
$form["update_date"] = time();
|
||||
$form["update_user"] = "system";
|
||||
|
||||
$form["ip"] = $expenseFormArray["ip"];;
|
||||
$form["user_agent"] = $expenseFormArray["user_agent"];;
|
||||
//$form["email"] = trim($expenseFormArray["email"]);
|
||||
$form["version"] = "0";
|
||||
$form["status"] = "1";
|
||||
|
||||
if ($form["expense_type"] == "2") {
|
||||
$form["default_meal"] = "0.5|1.0|1.0";
|
||||
} else {
|
||||
$form["default_meal"] = "";
|
||||
}
|
||||
|
||||
if (!empty($expenseFormArray["user_id"])) {
|
||||
$form["user_id"] = $expenseFormArray["user_id"];
|
||||
}
|
||||
|
||||
//insert into the table group_expenses
|
||||
if ($form["expense_type"] == "1" || $form["expense_type"] == "2") {
|
||||
|
||||
$fileds = array(
|
||||
'unique_url',
|
||||
'title',
|
||||
'currency',
|
||||
'description',
|
||||
'language',
|
||||
'expense_type',
|
||||
'source',
|
||||
'create_user',
|
||||
'create_date',
|
||||
'update_date',
|
||||
'update_user',
|
||||
'status',
|
||||
'default_meal',
|
||||
'ip',
|
||||
'user_agent',
|
||||
'version',
|
||||
'user_id'
|
||||
);
|
||||
if ($archieved) {
|
||||
$fileds[] = 'id';
|
||||
$form['unique_url'] = $expenseFormArray["unique_url"];
|
||||
$form['id'] = $expenseFormArray["id"];
|
||||
}
|
||||
|
||||
$data["Expense"] = $form;
|
||||
|
||||
if ($this->save($data, false, $fileds)) {
|
||||
$id = $this->id;
|
||||
if ($id != "") {
|
||||
$this->id = $id;
|
||||
if ($archieved) {
|
||||
$this->insertParticipantsByRemote($id, $expenseFormArray["participants"]);
|
||||
$result = $id . "," . $expenseFormArray["unique_url"];
|
||||
} else {
|
||||
$unique_url_id = $expenseFormArray["expense_type"] . $this->getUniqueURLById(time()) . $this->getUniqueURLById($id) . trim($expenseFormArray["secret_key"]);
|
||||
//update group_expenses
|
||||
if ($this->saveField("unique_url", $unique_url_id)) {
|
||||
//insert into participant table
|
||||
if ($isRemote == false) {
|
||||
$this->insertParticipants($id, $expenseFormArray["your_name"], $expenseFormArray["participants"]);
|
||||
} else {
|
||||
$this->insertParticipantsByRemote($id, $expenseFormArray["participants"]);
|
||||
}
|
||||
$result = $id . "," . $unique_url_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ($form["expense_type"] == "3") {
|
||||
$fileds = array(
|
||||
'unique_url',
|
||||
'title',
|
||||
'currency',
|
||||
'description',
|
||||
'language',
|
||||
'expense_type',
|
||||
'source',
|
||||
'create_user',
|
||||
'create_date',
|
||||
'update_date',
|
||||
'update_user',
|
||||
'status',
|
||||
'default_meal',
|
||||
'ip',
|
||||
'user_agent',
|
||||
'version',
|
||||
'user_id'
|
||||
);
|
||||
|
||||
if ($archieved) {
|
||||
$fileds[] = 'id';
|
||||
$form['unique_url'] = $expenseFormArray["unique_url"];
|
||||
$form['id'] = $expenseFormArray["id"];
|
||||
}
|
||||
$data["Expense"] = $form;
|
||||
|
||||
if ($this->save($data, false, $fileds)) {
|
||||
|
||||
$id = $this->id;
|
||||
|
||||
if ($id != "") {
|
||||
$this->id = $id;
|
||||
if ($archieved) {
|
||||
$result = $id . "," . $expenseFormArray["unique_url"];
|
||||
} else {
|
||||
$unique_url_id = $expenseFormArray["expense_type"] . $this->getUniqueURLById(time()) . $this->getUniqueURLById($id) . trim($expenseFormArray["secret_key"]);
|
||||
//update group_expenses
|
||||
if ($this->saveField("unique_url", $unique_url_id)) {
|
||||
//insert into participant table
|
||||
//if($isRemote == false){
|
||||
//$this->insertParticipants($id, $expenseFormArray["your_name"],$expenseFormArray["participants"]);
|
||||
$result = $id . "," . $unique_url_id;
|
||||
//} else {
|
||||
//$this->insertParticipantsByRemote($id,$expenseFormArray["participants"]);
|
||||
//$result = $id.",".$unique_url_id;
|
||||
//}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* function updateExpense($expenseFormArray){
|
||||
|
||||
$result = "";
|
||||
|
||||
$form["id"] =$expenseFormArray["id"];
|
||||
$form["title"] = $expenseFormArray["title"];
|
||||
$form["currency"] = $expenseFormArray["currency"];
|
||||
$form["description"] = $expenseFormArray["description"];
|
||||
$form["language"] = $expenseFormArray["language"];
|
||||
$form["is_secret"] = $expenseFormArray["is_secret"];
|
||||
$form["secret_key"] = $expenseFormArray["secret_key"];
|
||||
$form["update_date"] = time();
|
||||
$form["update_user"] = "system";
|
||||
$form["version"] = $expenseFormArray["version"];
|
||||
|
||||
$fileds = array('title','currency','description',
|
||||
'language','is_secret','secret_key','update_date','update_user');
|
||||
|
||||
|
||||
$data["Expense"] = $form;
|
||||
|
||||
//update few fields of group_expenses table
|
||||
if($this->save($data,false,$fileds)){
|
||||
$result = 1;
|
||||
}
|
||||
|
||||
return $result;
|
||||
} */
|
||||
|
||||
|
||||
|
||||
function insertParticipants($id, $creator_name, $participants)
|
||||
{
|
||||
|
||||
$data = array();
|
||||
|
||||
$form["Participant"][0]["participant_id"] = "1" . "_" . "0";
|
||||
$form["Participant"][0]["expense_id"] = $id;
|
||||
$form["Participant"][0]["name"] = $creator_name;
|
||||
$form["Participant"][0]["is_creator"] = 1;
|
||||
|
||||
$i = 1;
|
||||
if ($participants != "") {
|
||||
|
||||
$participant_array = explode(",", $participants);
|
||||
|
||||
foreach ($participant_array as $single_participant) {
|
||||
if ($single_participant != "") {
|
||||
|
||||
$form["Participant"][$i]["participant_id"] = "1" . "_" . $i;
|
||||
$form["Participant"][$i]["expense_id"] = $id;
|
||||
$form["Participant"][$i]["name"] = $single_participant;
|
||||
$form["Participant"][$i]["is_creator"] = 0;
|
||||
$i = $i + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
App::import('model', 'Participant');
|
||||
$participant = new Participant();
|
||||
$participant->saveMany($form["Participant"]);
|
||||
}
|
||||
|
||||
function insertParticipantsByRemote($id, $participantList)
|
||||
{
|
||||
|
||||
$i = 0;
|
||||
|
||||
foreach ($participantList as $key => $value) {
|
||||
$form["Participant"][$i]["participant_id"] = $value["participant_id"];
|
||||
$form["Participant"][$i]["expense_id"] = $id;
|
||||
$form["Participant"][$i]["name"] = $value["name"];
|
||||
$form["Participant"][$i]["is_creator"] = $value["is_creator"];
|
||||
$i = $i + 1;
|
||||
}
|
||||
|
||||
App::import('model', 'Participant');
|
||||
$participant = new Participant();
|
||||
$participant->saveMany($form["Participant"]);
|
||||
}
|
||||
|
||||
function findExpenseInfoByIds($expenseIdList)
|
||||
{
|
||||
|
||||
$data = NULL;
|
||||
if (!empty($expenseIdList) && count($expenseIdList) > 0) {
|
||||
$str = implode(",", $expenseIdList);
|
||||
|
||||
$this->hasMany = array();
|
||||
|
||||
$result = $this->find('all', array(
|
||||
'conditions' => array(
|
||||
'Expense.id in (' . $str . ')'
|
||||
),
|
||||
'order' => 'Expense.create_date DESC'
|
||||
));
|
||||
|
||||
if (!empty($result)) {
|
||||
$data["expenseList"] = $result;
|
||||
App::import('model', 'Participant');
|
||||
$participant = new Participant();
|
||||
$participantInfo = $participant->find('all', array('conditions' => array(
|
||||
'Participant.expense_id in (' . $str . ') ',
|
||||
'is_creator' => '1'
|
||||
)));
|
||||
|
||||
$data["participantList"] = $participantInfo;
|
||||
}
|
||||
}
|
||||
|
||||
// $log = $this->getDataSource()->getLog(false, false);
|
||||
// debug($log);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
function getUniqueURLById($in, $to_num = false, $pad_up = false)
|
||||
{
|
||||
|
||||
$index = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
$base = strlen($index);
|
||||
|
||||
if ($to_num) {
|
||||
// Digital number <<-- alphabet letter code
|
||||
$in = strrev($in);
|
||||
$out = 0;
|
||||
$len = strlen($in) - 1;
|
||||
for ($t = 0; $t <= $len; $t++) {
|
||||
$bcpow = bcpow($base, $len - $t);
|
||||
$out = $out + strpos($index, substr($in, $t, 1)) * $bcpow;
|
||||
}
|
||||
|
||||
if (is_numeric($pad_up)) {
|
||||
$pad_up--;
|
||||
if ($pad_up > 0) {
|
||||
$out -= pow($base, $pad_up);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Digital number -->> alphabet letter code
|
||||
if (is_numeric($pad_up)) {
|
||||
$pad_up--;
|
||||
if ($pad_up > 0) {
|
||||
$in += pow($base, $pad_up);
|
||||
}
|
||||
}
|
||||
|
||||
$out = "";
|
||||
for ($t = floor(log10($in) / log10($base)); $t >= 0; $t--) {
|
||||
$a = floor($in / bcpow($base, $t));
|
||||
$out = $out . substr($index, $a, 1);
|
||||
$in = $in - ($a * bcpow($base, $t));
|
||||
}
|
||||
$out = strrev($out); // reverse
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
0
app/Model/ExpenseDemo.php
Normal file
0
app/Model/ExpenseDemo.php
Normal file
32
app/Model/ExpenseEmail.php
Normal file
32
app/Model/ExpenseEmail.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
class ExpenseEmail extends AppModel
|
||||
{
|
||||
var $name='ExpenseEmail';
|
||||
|
||||
function insertExpenseEmail($inputData){
|
||||
|
||||
$result = NULL;
|
||||
if(isset( $inputData["id"])) {
|
||||
$form["id"] = $inputData["id"];
|
||||
}
|
||||
$form["unique_url"] = $inputData["unique_url"];
|
||||
$form["email"] = $inputData["email"];
|
||||
$form["title"] = $inputData["title"];
|
||||
$form["count_email_attempt"] = $inputData["count_email_attempt"];
|
||||
|
||||
if(isset( $inputData["id"])) {
|
||||
$fileds = array('id', 'unique_url', 'email', 'title', 'count_email_attempt');
|
||||
} else {
|
||||
$fileds = array( 'unique_url', 'email', 'title', 'count_email_attempt');
|
||||
}
|
||||
|
||||
|
||||
$dbData["ExpenseEmail"] = $form;
|
||||
|
||||
if(!$this->save($dbData,false,$fileds)){
|
||||
$result["22"] = __("LBL_EXPENSE_EMAIL_SAVED_SUCCESSFULLY");
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
16
app/Model/ExpiredRecord.php
Normal file
16
app/Model/ExpiredRecord.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
class ExpiredRecord extends AppModel
|
||||
{
|
||||
var $name='ExpiredRecord';
|
||||
|
||||
|
||||
public function saveAllExpiredRecords($data){
|
||||
|
||||
$error = "";
|
||||
if(!$this->saveMany($data["ExpiredRecord"])){
|
||||
$error = 22;
|
||||
}
|
||||
|
||||
return $error;
|
||||
}
|
||||
}
|
||||
9
app/Model/ExportReceipt.php
Normal file
9
app/Model/ExportReceipt.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
|
||||
class ExportReceipt extends AppModel
|
||||
{
|
||||
var $name='ExportReceipt';
|
||||
|
||||
|
||||
}
|
||||
350
app/Model/FamilyExpense.php
Normal file
350
app/Model/FamilyExpense.php
Normal file
@@ -0,0 +1,350 @@
|
||||
<?php
|
||||
class FamilyExpense extends AppModel
|
||||
{
|
||||
var $name='FamilyExpense';
|
||||
//1 = Input data format is not correct
|
||||
//2 = participant in this expense is deleted by other user or not available
|
||||
|
||||
|
||||
|
||||
private function validateAddExpense($data,$source){
|
||||
|
||||
$errorCode = "";
|
||||
|
||||
$checkParticipantList = array();
|
||||
|
||||
$form = $this->getFormDataByData($data);
|
||||
|
||||
//check expense ID
|
||||
$expenseIdArray = explode("-",$form["id"]);
|
||||
if(count($expenseIdArray) != 3 ){
|
||||
$errorCode = "1";
|
||||
}
|
||||
|
||||
if($errorCode == "" && $source == "1"){
|
||||
//check expense id already exist in db or not
|
||||
$data = $this->find('first', array('conditions' => array('FamilyExpense.id' =>$form["id"]), 'fields'=>array('id')));
|
||||
|
||||
if(!empty($data)){
|
||||
$errorCode = "34";
|
||||
}
|
||||
}
|
||||
return $errorCode;
|
||||
}
|
||||
|
||||
|
||||
private function validateEditExpense($data){
|
||||
$errorCode= $this->validateAddExpense($data,2);
|
||||
|
||||
if(empty($errorCode)){
|
||||
//check the expense is in DB or not
|
||||
|
||||
}
|
||||
|
||||
return $errorCode;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function addFamilyExpense($data){
|
||||
|
||||
|
||||
$result = null;
|
||||
//check the any of the involves participant(s) has been deleted or not
|
||||
//check account is closed already or not
|
||||
//update participant's balance
|
||||
//22 = Data not saved successfully in Database
|
||||
|
||||
$errorCode = $this->validateAddExpense($data,1);
|
||||
|
||||
|
||||
if(empty($errorCode)){
|
||||
|
||||
$form = $this->getFormDataByData($data);
|
||||
|
||||
|
||||
|
||||
$fileds = array('id','expense_type','expense_id','record_type','what','category','expense_date','expense_date_new','create_date'.'update_date','amount','is_reimbursement','type','version','images');
|
||||
$data["FamilyExpense"] = $form;
|
||||
|
||||
|
||||
if(!$this->save($data,false,$fileds)){
|
||||
$result["22"] = __("LBL_FAMILY_EXPENSE_NOT_SAVED");
|
||||
}
|
||||
} else {
|
||||
$result[$errorCode] = __("LBL_ADD_FAMILY_EXPENSE_FAIL");
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
public function addMultipleFamilyExpense($FinalFamilyExpenseArray,$expense_id){
|
||||
|
||||
$error = "";
|
||||
//check the any of the involves participant(s) has been deleted or not
|
||||
//check account is closed already or not
|
||||
//update participant's balance
|
||||
//22 = Data not saved successfully in Database
|
||||
|
||||
$i = 0;
|
||||
if(!empty($FinalFamilyExpenseArray)){
|
||||
foreach( $FinalFamilyExpenseArray as $key=>$value){
|
||||
$value["source"] = "2"; //2=mobile
|
||||
$value["expense_id"] = $expense_id;
|
||||
$form["FamilyExpense"][$i] = $this->getFormDataByData($value);
|
||||
|
||||
$i = $i + 1;
|
||||
}
|
||||
|
||||
if(!$this->saveMany($form["FamilyExpense"])){
|
||||
$error = "22";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $error;
|
||||
}
|
||||
|
||||
private function getFormDataByData($data){
|
||||
$form = array();
|
||||
$form["id"] = $data["id"];
|
||||
|
||||
$form["expense_id"] = $data["expense_id"];
|
||||
$form["record_type"] = $data["record_type"]; // 1= expense,2=income
|
||||
$form["what"] = $data["what"];
|
||||
$form["category"] = $data["category"];
|
||||
|
||||
if(isset($data["expense_date_old"])){
|
||||
$form["expense_date"] = $data["expense_date_old"];
|
||||
}
|
||||
|
||||
$form["expense_date_new"] = $data["expense_date"];
|
||||
$form["amount"] = $data["amount"];
|
||||
$form["category"] = $data["category"];
|
||||
$form["type"] = "1"; // 1=normal expense,2=balance expense
|
||||
|
||||
$form["version"] = 0;
|
||||
|
||||
if(isset($data["is_reimbursement"])){
|
||||
$form["is_reimbursement"] = $data["is_reimbursement"];
|
||||
}
|
||||
|
||||
if(isset($data["syn_add_unique_id"])){
|
||||
$form["syn_add_unique_id"] = $data["syn_add_unique_id"];
|
||||
}
|
||||
|
||||
|
||||
if(isset($data["create_date"]) && $this->isValidTimeStamp($data["create_date"]) ){
|
||||
|
||||
$form["create_date"] = $data["create_date"];
|
||||
$form["create_date"] = date('Y-m-d H:i:s', $form["create_date"]);
|
||||
|
||||
} else if(isset($data["create_date"]) && !empty($data["create_date"])){
|
||||
$form["create_date"] = $data["create_date"];
|
||||
|
||||
} else {
|
||||
$form["create_date"] = $this->getSystemCurrentIntTime();
|
||||
}
|
||||
|
||||
$form["update_date"] = $this->getSystemCurrentIntTime();
|
||||
|
||||
// ## New features
|
||||
if(isset($data["category_id"]) && !empty($data["category_id"])) {
|
||||
$form["category_id"] = $data["category_id"];
|
||||
}
|
||||
|
||||
if(isset($data["custom_categories"]) && !empty($data["custom_categories"])) {
|
||||
$form["custom_categories"] = $data["custom_categories"];
|
||||
}
|
||||
|
||||
if(isset($data["receipts"]) && !empty($data["receipts"])) {
|
||||
$form["receipts"] = $data["receipts"];
|
||||
}
|
||||
|
||||
if(isset($data["changed_by"]) && !empty($data["changed_by"])) {
|
||||
$form["changed_by"] = $data["changed_by"];
|
||||
} else {
|
||||
$form["changed_by"] = null;
|
||||
}
|
||||
|
||||
$form['images'] = empty($data['images']) ? null : $data['images'];
|
||||
|
||||
// ##
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
||||
public function modifyMultipleFamilyExpense($expenseList,$expenseId){
|
||||
|
||||
$error = "";
|
||||
//check the any of the involves participant(s) has been deleted or not
|
||||
//check account is closed already or not
|
||||
//update participant's balance
|
||||
//22 = Data not saved successfully in Database
|
||||
|
||||
$i = 0;
|
||||
|
||||
if(!empty($expenseList)){
|
||||
foreach( $expenseList as $key=>$value){
|
||||
$value["expense_id"] = $expenseId;
|
||||
$version = $value["version"];
|
||||
$form["FamilyExpense"][$i] = $this->getFormDataByData($value);
|
||||
$form["FamilyExpense"][$i]['version'] = ($version)+1;
|
||||
$i++;
|
||||
}
|
||||
|
||||
if(!$this->saveMany($form["FamilyExpense"])){
|
||||
//data modify fails
|
||||
$error = "22";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $error;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function modifyFamilyExpense($data){
|
||||
|
||||
//check the any of the involves participant(s) has been deleted or not
|
||||
//check account is closed already or not
|
||||
//update participant's balance
|
||||
//3 = group expense not available in database;
|
||||
//22 = Data not saved successfully in Database
|
||||
//23 = Log insertion fail
|
||||
|
||||
$result = null;
|
||||
$form = $this->getFormDataByData($data);
|
||||
|
||||
//retrieve the existing expense from DB
|
||||
$dbExpense = $this->find('first', array('conditions' => array('FamilyExpense.id' =>$form["id"]), 'fields'=>array('version')));
|
||||
|
||||
/*$dbExpense = $this->find('all',
|
||||
array('conditions' =>
|
||||
array('FamilyExpense.id =' => $form["id"]))); */
|
||||
|
||||
|
||||
|
||||
if(empty($dbExpense)){
|
||||
//if expense not available in DB
|
||||
$result["3"] = __("LBL_FAMILY_EXPENSE_NOT_AVAILABLE");
|
||||
} else {
|
||||
|
||||
//increase number of version
|
||||
$form['version'] = ($dbExpense["FamilyExpense"]["version"])+1;
|
||||
|
||||
//check similar like Add expense
|
||||
$errorCode = $this->validateEditExpense($data);
|
||||
|
||||
if(empty($errorCode)){
|
||||
|
||||
$fileds = array('id','expense_id','what','expense_date','expense_date_new','update_date','amount','category','is_reimbursement','version','images');
|
||||
$data["FamilyExpense"] = $form;
|
||||
|
||||
if(!$this->save($data,false,$fileds)){
|
||||
//data modify fails
|
||||
$result["22"] = __("LBL_DATA_SAVED_SUCCESSFULLY_DATABASE");
|
||||
}
|
||||
} else {
|
||||
//Found error
|
||||
$result[$errorCode] = __("LBL_EDIT_FAMILY_EXPENSE_FAIL");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function deleteMultipleFamilyExpense($expenseList,$expenseId){
|
||||
|
||||
$error = "";
|
||||
//check the any of the involves participant(s) has been deleted or not
|
||||
//check account is closed already or not
|
||||
//update participant's balance
|
||||
//22 = Data not saved successfully in Database
|
||||
|
||||
$i = 0;
|
||||
|
||||
if(!empty($expenseList)){
|
||||
foreach( $expenseList as $key=>$value){
|
||||
$groupExpenseIdList[] = $value["id"];
|
||||
$i++;
|
||||
}
|
||||
|
||||
if(!$this->deleteAll(array('FamilyExpense.id' => $groupExpenseIdList))){
|
||||
//data modify fails
|
||||
$error = "22";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $error;
|
||||
|
||||
}
|
||||
|
||||
public function deleteFamilyExpense($data){
|
||||
|
||||
$result = null;
|
||||
$form = $this->getFormDataByData($data);
|
||||
|
||||
//retrieve the existing expense from DB
|
||||
|
||||
/*$dbExpense = $this->find('all',
|
||||
array('conditions' =>
|
||||
array('FamilyExpense.id =' => $form["id"])));*/
|
||||
$dbExpense = $this->find('first', array('conditions' => array('FamilyExpense.id' =>$form["id"]), 'fields'=>array('id')));
|
||||
|
||||
|
||||
|
||||
if(empty($dbExpense)){
|
||||
//if expense not available in DB
|
||||
$result["3"] = __("LBL_FAMILY_EXPENSE_NOT_AVAILABLE");
|
||||
} else {
|
||||
|
||||
if(!$this->delete(array('id'=>$form["id"]))){
|
||||
|
||||
//data modify fails
|
||||
$result["22"] = __("LBL_FAMILY_EXPENSE_NOT_DELETED");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
private function isValidTimeStamp($timestamp)
|
||||
|
||||
{
|
||||
|
||||
return ((string) (int) $timestamp === $timestamp)
|
||||
|
||||
&& ($timestamp <= PHP_INT_MAX)
|
||||
|
||||
&& ($timestamp >= ~PHP_INT_MAX);
|
||||
|
||||
}
|
||||
|
||||
public function getImagesById($id){
|
||||
return $this->find('first',array(
|
||||
'fields' => array('FamilyExpense.id', 'FamilyExpense.images'),
|
||||
'conditions' => array('FamilyExpense.id =' => $id)));
|
||||
}
|
||||
|
||||
private function getSystemCurrentIntTime(){
|
||||
date_default_timezone_set("UTC");
|
||||
return time();
|
||||
}
|
||||
|
||||
}
|
||||
566
app/Model/GroupExpense.php
Normal file
566
app/Model/GroupExpense.php
Normal file
@@ -0,0 +1,566 @@
|
||||
<?php
|
||||
class GroupExpense extends AppModel
|
||||
{
|
||||
var $name='GroupExpense';
|
||||
//1 = Input data format is not correct
|
||||
//2 = participant in this expense is deleted by other user or not available
|
||||
|
||||
|
||||
|
||||
private function validateAddExpense($data){
|
||||
|
||||
$errorCode = "";
|
||||
|
||||
$checkParticipantList = array();
|
||||
|
||||
$form = $this->getFormDataByData($data);
|
||||
|
||||
//check expense ID
|
||||
$expenseIdArray = explode("-",$form["id"]);
|
||||
if(count($expenseIdArray) != 3 || $expenseIdArray[0] == ""){
|
||||
$errorCode = "1";
|
||||
} else {
|
||||
array_push($checkParticipantList,$expenseIdArray[0]);
|
||||
}
|
||||
|
||||
|
||||
//check the participant involes in the expense are available or not
|
||||
if($errorCode == "" ){
|
||||
array_push($checkParticipantList,$form["paid_by_participant_id"]);
|
||||
|
||||
if(!empty($form["participant_amount"])){
|
||||
$participantAmtStrArray = explode(",",$form["participant_amount"]);
|
||||
foreach($participantAmtStrArray as $key=>$value){
|
||||
$parts = explode("|",$value);
|
||||
array_push($checkParticipantList,$parts[0]);
|
||||
}
|
||||
}
|
||||
|
||||
//make array unique
|
||||
$checkParticipantList = array_unique($checkParticipantList);
|
||||
|
||||
//retrieve participant from DB
|
||||
$dbParticipantList = $this->getParticipantIdListByExpId($form['expense_id']);
|
||||
|
||||
//retrieve participants from DB
|
||||
//print_r($checkParticipantList);exit;
|
||||
|
||||
/* $Str = "";
|
||||
foreach($checkParticipantList as $key=>$value){
|
||||
$Str .= "{". $key."=>".$value."}";
|
||||
}
|
||||
|
||||
$fp = fopen("rajib.txt","w+");
|
||||
fwrite($fp, $Str);
|
||||
fclose($fp); */
|
||||
|
||||
foreach($checkParticipantList as $index=>$item){
|
||||
if (!in_array($item, $dbParticipantList)) {
|
||||
|
||||
$errorCode = "2";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $errorCode;
|
||||
}
|
||||
|
||||
|
||||
private function validateEditExpense($data){
|
||||
$errorCode= $this->validateAddExpense($data);
|
||||
|
||||
if(empty($errorCode)){
|
||||
//check the expense is in DB or not
|
||||
|
||||
}
|
||||
|
||||
return $errorCode;
|
||||
|
||||
}
|
||||
|
||||
public function getGroupExpenseLog($data){
|
||||
|
||||
$expense_id = $data["expense_id"];
|
||||
$frommDate = $data["fromDate"]." 00:00:00";
|
||||
/* $date = new DateTime($frommDate);
|
||||
$frommDate = $date->format('Y-m-d'); */
|
||||
|
||||
$toDate = date("Y-m-d", strtotime("+1 day", strtotime($data["toDate"])));
|
||||
/* $date = new DateTime($toDate);
|
||||
$toDate = $date->format('Y-m-d'); */
|
||||
|
||||
App::import('model','Log');
|
||||
$log = new Log();
|
||||
$result = $log->find('all', array('conditions' => array(
|
||||
'Log.expense_id' =>$expense_id,
|
||||
'Log.create_date >= ' => $frommDate,
|
||||
'Log.create_date <= ' => $toDate
|
||||
),
|
||||
'order' => 'Log.create_date DESC'));
|
||||
// $log = $this->getDataSource()->getLog(false, false);
|
||||
// $fp = fopen("testResult.txt","a+");
|
||||
// fwrite($fp,$frommDate."=".$toDate);
|
||||
// debug($log);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function getParticipantIdListByExpId($expense_id){
|
||||
App::import('model','Participant');
|
||||
$participant = new Participant();
|
||||
$dbParticipantIdList = array();
|
||||
$data = $participant->find('all',
|
||||
array('conditions' =>
|
||||
array('Participant.expense_id =' => $expense_id)));
|
||||
foreach($data as $index=>$object){
|
||||
array_push($dbParticipantIdList,$object["Participant"]["participant_id"]);
|
||||
}
|
||||
|
||||
return $dbParticipantIdList;
|
||||
}
|
||||
|
||||
public function addGroupExpense($data){
|
||||
|
||||
$result = null;
|
||||
//check the any of the involves participant(s) has been deleted or not
|
||||
//check account is closed already or not
|
||||
//update participant's balance
|
||||
//22 = Data not saved successfully in Database
|
||||
|
||||
$errorCode = $this->validateAddExpense($data);
|
||||
|
||||
if(empty($errorCode)){
|
||||
|
||||
$form = $this->getFormDataByData($data);
|
||||
|
||||
if($form["expense_type"] != "1"){
|
||||
$form["participant_amount"] = "";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$fileds = array('id','expense_type','expense_id','what','expense_date','expense_date_new','create_date','update_date','amount','paid_by_participant_id','is_reimbursement','participant_amount','isDetails','type','version', 'extras','images');
|
||||
$data["GroupExpense"] = $form;
|
||||
if(!$this->save($data,false,$fileds)){
|
||||
$result["22"] = __("LBL_GROUP_EXPENSE_NOT_SAVED");
|
||||
}
|
||||
} else {
|
||||
$result[$errorCode] = __("LBL_ADD_EXPENSE_FAILS");
|
||||
}
|
||||
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
public function addMultipleGroupExpense($expenseList,$expense_id){
|
||||
|
||||
$error = "";
|
||||
//check the any of the involves participant(s) has been deleted or not
|
||||
//check account is closed already or not
|
||||
//update participant's balance
|
||||
//22 = Data not saved successfully in Database
|
||||
|
||||
$i = 0;
|
||||
|
||||
if(!empty($expenseList)){
|
||||
|
||||
foreach( $expenseList as $key=>$value){
|
||||
$value["source"] = "2"; //2=mobile
|
||||
$value["expense_id"] = $expense_id;
|
||||
|
||||
if($value["expense_type"] != "1"){
|
||||
$value["participant_amount"] = "";
|
||||
}
|
||||
|
||||
$form["GroupExpense"][$i] = $this->getFormDataByData($value);
|
||||
|
||||
$i = $i + 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(!$this->saveMany($form["GroupExpense"])){
|
||||
$error = "22";
|
||||
}
|
||||
|
||||
}
|
||||
return $error;
|
||||
}
|
||||
|
||||
private function getFormDataByData($data){
|
||||
|
||||
$form = array();
|
||||
$form["id"] = $data["id"];
|
||||
if(isset($data["expense_type"])){
|
||||
$form["expense_type"] = $data["expense_type"];
|
||||
} else {
|
||||
$form["expense_type"] = "1"; //1=group expense,2 = mess expense
|
||||
}
|
||||
$form["expense_id"] = $data["expense_id"];
|
||||
$form["what"] = $data["what"];
|
||||
if(isset($data["expense_date_old"])){
|
||||
$form["expense_date"] = $data["expense_date_old"];
|
||||
}
|
||||
$form["expense_date_new"] = $data["expense_date"];
|
||||
$form["amount"] = $data["amount"];
|
||||
$form["paid_by_participant_id"] = $data["paid_by_participant_id"];
|
||||
$form["isDetails"] = $data["isDetails"];
|
||||
|
||||
$form["type"] = $data["type"]; // 1=normal expense,2=balance expense
|
||||
|
||||
if(isset($data["is_reimbursement"])){
|
||||
$form["is_reimbursement"] = $data["is_reimbursement"];
|
||||
}
|
||||
|
||||
if(isset($data["create_date"]) && $this->isValidTimeStamp($data["create_date"]) ){
|
||||
|
||||
$form["create_date"] = $data["create_date"];
|
||||
$form["create_date"] = date('Y-m-d H:i:s', $form["create_date"]);
|
||||
|
||||
} else if(isset($data["create_date"]) && !empty($data["create_date"]) ){
|
||||
$form["create_date"] = $data["create_date"];
|
||||
|
||||
} else {
|
||||
|
||||
$form["create_date"] = date('Y-m-d H:i:s');
|
||||
|
||||
}
|
||||
|
||||
$form["participant_amount"] = $data["participant_amount"];
|
||||
if(isset($data["previous_desc"])){
|
||||
$form["previous_desc"] = $data["previous_desc"];
|
||||
}
|
||||
if(isset($data["new_desc"])){
|
||||
$form["new_desc"] = $data["new_desc"];
|
||||
}
|
||||
|
||||
if(isset($data["previous_paid_by"])){
|
||||
$form["previous_paid_by"] = $data["previous_paid_by"];
|
||||
}
|
||||
|
||||
if(isset($data["syn_add_unique_id"])){
|
||||
$form["syn_add_unique_id"] = $data["syn_add_unique_id"];
|
||||
}
|
||||
|
||||
|
||||
$form["version"] = 0;
|
||||
|
||||
$form["update_date"] = $this->getSystemCurrentIntTime();
|
||||
|
||||
//Make extras more accurately
|
||||
$result = $this->checkExtraGroupExpense($data['extras'], $data['what']);
|
||||
if($result != 99) {
|
||||
$data["extras"] = substr_replace($data["extras"], $result, 0, 1);
|
||||
}
|
||||
|
||||
// assign data to form
|
||||
$form["extras"] = $data['extras'];
|
||||
|
||||
|
||||
// ## New features
|
||||
if(isset($data["category_id"]) && !empty($data["category_id"])) {
|
||||
$form["category_id"] = $data["category_id"];
|
||||
}
|
||||
|
||||
if(isset($data["custom_categories"]) && !empty($data["custom_categories"])) {
|
||||
$form["custom_categories"] = $data["custom_categories"];
|
||||
}
|
||||
|
||||
if(isset($data["receipts"]) && !empty($data["receipts"])) {
|
||||
$form["receipts"] = $data["receipts"];
|
||||
}
|
||||
|
||||
if(isset($data["changed_by"]) && !empty($data["changed_by"])) {
|
||||
$form["changed_by"] = $data["changed_by"];
|
||||
} else {
|
||||
$form["changed_by"] = null;
|
||||
}
|
||||
|
||||
$form['images'] = empty($data['images']) ? null : $data['images'];
|
||||
|
||||
|
||||
// ##
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
||||
public function modifyMultipleGroupExpense($expenseList,$expenseId){
|
||||
|
||||
$error = "";
|
||||
//check the any of the involves participant(s) has been deleted or not
|
||||
//check account is closed already or not
|
||||
//update participant's balance
|
||||
//22 = Data not saved successfully in Database
|
||||
|
||||
$i = 0;
|
||||
|
||||
foreach( $expenseList as $key=>$value){
|
||||
$value["expense_id"] = $expenseId;
|
||||
$version = $value["version"];
|
||||
|
||||
if($value["expense_type"] != "1"){
|
||||
$value["participant_amount"] = "";
|
||||
}
|
||||
|
||||
$form["GroupExpense"][$i] = $this->getFormDataByData($value);
|
||||
$form["GroupExpense"][$i]['version'] = ($version)+1;
|
||||
|
||||
//set log List
|
||||
$logList["Log"][$i]['expense_id'] = $form["GroupExpense"][$i]["expense_id"];
|
||||
$logList["Log"][$i]['previous_desc'] = $form["GroupExpense"][$i]["previous_desc"];
|
||||
$logList["Log"][$i]['new_desc'] = $form["GroupExpense"][$i]["new_desc"];
|
||||
$logList["Log"][$i]['previous_paid_by'] = $form["GroupExpense"][$i]["previous_paid_by"];
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
|
||||
App::import('model','Log');
|
||||
$log = new Log();
|
||||
|
||||
|
||||
//check the any of the involves participant(s) has been deleted or not
|
||||
//check account is closed already or not
|
||||
//update participant's balance
|
||||
//3 = group expense not available in database;
|
||||
//22 = Data not saved successfully in Database
|
||||
//23 = Log insertion fail
|
||||
|
||||
//increase number of version
|
||||
|
||||
|
||||
//check similar like Add expense
|
||||
//$errorCode = $this->validateEditExpense($data);
|
||||
|
||||
|
||||
if(!$this->saveMany($form["GroupExpense"])){
|
||||
//data modify fails
|
||||
$error = "22";
|
||||
} else {
|
||||
//data modify successfull.hence insert logs
|
||||
|
||||
if(!$log->saveMany($logList["Log"])){
|
||||
//data modify fails
|
||||
$error = "23";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $error;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function modifyGroupExpense($data){
|
||||
//check the any of the involves participant(s) has been deleted or not
|
||||
//check account is closed already or not
|
||||
//update participant's balance
|
||||
//3 = group expense not available in database;
|
||||
//22 = Data not saved successfully in Database
|
||||
//23 = Log insertion fail
|
||||
|
||||
$result = null;
|
||||
$form = $this->getFormDataByData($data);
|
||||
|
||||
//retrieve the existing expense from DB
|
||||
|
||||
$dbExpense = $this->find('all',
|
||||
array('conditions' =>
|
||||
array('GroupExpense.id =' => $form["id"])));
|
||||
|
||||
|
||||
|
||||
if(empty($dbExpense)){
|
||||
//if expense not available in DB
|
||||
$result["3"] = __("LBL_GROUP_EXPENSE_NOT_AVAILABLE");
|
||||
} else {
|
||||
|
||||
//increase number of version
|
||||
$form['version'] = ($dbExpense["0"]["GroupExpense"]["version"])+1;
|
||||
|
||||
//check similar like Add expense
|
||||
//$data["expense_date"] = $this->data["date"];
|
||||
|
||||
$errorCode = $this->validateEditExpense($data);
|
||||
|
||||
if(empty($errorCode)){
|
||||
|
||||
if($form["expense_type"] != "1"){
|
||||
$form["participant_amount"] = "";
|
||||
}
|
||||
|
||||
$fileds = array('id','expense_type','expense_id','what','expense_date','expense_date_new','create_date','update_date','amount','paid_by_participant_id','is_reimbursement','participant_amount','isDetails','version', 'extras','images');
|
||||
$data["GroupExpense"] = $form;
|
||||
|
||||
if(!$this->save($data,false,$fileds)){
|
||||
//data modify fails
|
||||
$result["22"] = __("LBL_DATA_SAVED_SUCCESSFULLY_DATABASE");
|
||||
} else {
|
||||
//data modify successfull.hence insert logs
|
||||
App::import('model','Log');
|
||||
$log = new Log();
|
||||
|
||||
$fileds = array('expense_id','previous_paid_by','changed_by','previous_desc','new_desc');
|
||||
$logData['Log'] = $this->getEditLogData($form);
|
||||
if(!$log->save($logData,false,$fileds)){
|
||||
//data modify fails
|
||||
$result["23"] = __("LBL_LOG_INSERTATION_FAIL");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//Found error
|
||||
$result[$errorCode] = __("LBL_EDIT_EXPENSE_FAILS");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
private function getEditLogData($form){
|
||||
$result = array();
|
||||
|
||||
$result['expense_id'] = $form['expense_id'];
|
||||
$result['previous_desc'] = $form['previous_desc'];
|
||||
$result['new_desc'] = $form['new_desc'];
|
||||
$result['previous_paid_by'] = $form['previous_paid_by'];
|
||||
$result['changed_by'] = $form['changed_by'];
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
public function deleteMultipleGroupExpense($expenseList,$expenseId){
|
||||
|
||||
$error = "";
|
||||
//check the any of the involves participant(s) has been deleted or not
|
||||
//check account is closed already or not
|
||||
//update participant's balance
|
||||
//22 = Data not saved successfully in Database
|
||||
|
||||
$i = 0;
|
||||
|
||||
foreach( $expenseList as $key=>$value){
|
||||
$groupExpenseIdList[] = $value["id"];
|
||||
//set log List
|
||||
$logList["Log"][$i]['expense_id'] = $expenseId;
|
||||
$logList["Log"][$i]['previous_desc'] = $value["previous_desc"];
|
||||
$logList["Log"][$i]['new_desc'] = $value["new_desc"];
|
||||
$logList["Log"][$i]['previous_paid_by'] = $value["previous_paid_by"];
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
|
||||
App::import('model','Log');
|
||||
$log = new Log();
|
||||
|
||||
|
||||
//check the any of the involves participant(s) has been deleted or not
|
||||
//check account is closed already or not
|
||||
//update participant's balance
|
||||
//3 = group expense not available in database;
|
||||
//22 = Data not saved successfully in Database
|
||||
//23 = Log insertion fail
|
||||
|
||||
//increase number of version
|
||||
|
||||
|
||||
//check similar like Add expense
|
||||
//$errorCode = $this->validateEditExpense($data);
|
||||
|
||||
|
||||
if(!$this->deleteAll(array('GroupExpense.id' => $groupExpenseIdList))){
|
||||
//data modify fails
|
||||
$error = "22";
|
||||
} else {
|
||||
//data modify successfull.hence insert logs
|
||||
|
||||
if(!$log->saveMany($logList["Log"])){
|
||||
//data modify fails
|
||||
$error = "23";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $error;
|
||||
|
||||
}
|
||||
|
||||
public function deleteGroupExpense($data){
|
||||
|
||||
$result = null;
|
||||
$form = $this->getFormDataByData($data);
|
||||
|
||||
//retrieve the existing expense from DB
|
||||
|
||||
$dbExpense = $this->find('all',
|
||||
array('conditions' =>
|
||||
array('GroupExpense.id =' => $form["id"])));
|
||||
|
||||
|
||||
|
||||
if(empty($dbExpense)){
|
||||
//if expense not available in DB
|
||||
$result["3"] = __("LBL_GROUP_EXPENSE_NOT_AVAILABLE");
|
||||
} else {
|
||||
|
||||
if(!$this->delete(array('id'=>$form["id"]))){
|
||||
|
||||
//data modify fails
|
||||
$result["22"] = __("LBL_GROUP_EXPENSE_NOT_DELETED_SUCCESSFULLY");
|
||||
} else {
|
||||
|
||||
//data modify successfull.hence insert logs
|
||||
App::import('model','Log');
|
||||
$log = new Log();
|
||||
|
||||
$fileds = array('expense_id','previous_paid_by','changed_by','previous_desc','new_desc');
|
||||
$logData['Log'] = $this->getEditLogData($form);
|
||||
if(!$log->save($logData,false,$fileds)){
|
||||
//data modify fails
|
||||
$result["23"] = __("LBL_LOG_INSERTATION_FAIL");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getImagesById($id){
|
||||
return $this->find('first',array(
|
||||
'fields' => array('GroupExpense.id', 'GroupExpense.images'),
|
||||
'conditions' => array('GroupExpense.id =' => $id)));
|
||||
}
|
||||
|
||||
|
||||
private function isValidTimeStamp($timestamp)
|
||||
|
||||
{
|
||||
|
||||
return ((string) (int) $timestamp === $timestamp)
|
||||
|
||||
&& ($timestamp <= PHP_INT_MAX)
|
||||
|
||||
&& ($timestamp >= ~PHP_INT_MAX);
|
||||
|
||||
}
|
||||
|
||||
private function getSystemCurrentIntTime(){
|
||||
date_default_timezone_set("UTC");
|
||||
return time();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
78
app/Model/GroupSetting.php
Normal file
78
app/Model/GroupSetting.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
class GroupSetting extends AppModel
|
||||
{
|
||||
var $name='GroupSetting';
|
||||
private $restricted_modes = ['ON' => 1, 'OFF' => 0];
|
||||
|
||||
public function getGroupSettingByURL($unique_url,$custom_select = false){
|
||||
|
||||
$options = array(
|
||||
'conditions' => array('GroupSetting.unique_url' => $unique_url)
|
||||
);
|
||||
|
||||
if ($custom_select) {
|
||||
$options['fields'] = array(
|
||||
'GroupSetting.categories',
|
||||
'GroupSetting.version',
|
||||
'GroupSetting.is_restricted_mode'
|
||||
);
|
||||
}
|
||||
|
||||
$groupSettingData = $this->find('first', $options);
|
||||
|
||||
if (empty($groupSettingData) && empty($groupSettingData['GroupSetting'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$groupSettingData['GroupSetting']['categories'] = json_decode($groupSettingData['GroupSetting']['categories'], true);
|
||||
return $groupSettingData['GroupSetting'];
|
||||
|
||||
}
|
||||
public function saveGroupSetting($groupSettingData)
|
||||
{
|
||||
$request = $this->_prepareFields($groupSettingData);
|
||||
return $this->save($request);
|
||||
|
||||
}
|
||||
|
||||
public function PermissionEnabled($unique_url){
|
||||
$group_setting = $this->getGroupSettingByURL($unique_url);
|
||||
if (empty($group_setting)) {
|
||||
return PUBLIC_PERMIT;
|
||||
}
|
||||
$isRestricted = isset($group_setting['is_restricted_mode']) &&
|
||||
$group_setting['is_restricted_mode'] == $this->restricted_modes['OFF'];
|
||||
if ($isRestricted) {
|
||||
return NO_PERMIT;
|
||||
}
|
||||
return $group_setting;
|
||||
}
|
||||
protected function _prepareFields($data)
|
||||
{
|
||||
$returnData = array();
|
||||
if (isset($data['is_restricted_mode'])) {
|
||||
$returnData['is_restricted_mode'] = $data['is_restricted_mode'];
|
||||
}
|
||||
if (isset($data['expense_id'])) {
|
||||
$returnData['expense_id'] = $data['expense_id'];
|
||||
}
|
||||
if (isset($data['unique_url'])) {
|
||||
$returnData['unique_url'] = $data['unique_url'];
|
||||
}
|
||||
$returnData['categories'] = (!empty($data['categories'])) ? $data['categories'] : '[]';
|
||||
|
||||
if (!empty($data['id'])) {
|
||||
$returnData['id'] = $data['id'];
|
||||
$returnData['version'] = $data['version'] + 1;
|
||||
}
|
||||
else{
|
||||
$returnData['version'] = 0;
|
||||
}
|
||||
|
||||
return $returnData;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
38
app/Model/LoadingHistory.php
Normal file
38
app/Model/LoadingHistory.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
class LoadingHistory extends AppModel
|
||||
{
|
||||
var $name = 'LoadingHistory';
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function insertLoadingHistory($form){
|
||||
|
||||
$result = null;
|
||||
//1 = Input data format is not correct
|
||||
//4 = participant already exist in database
|
||||
//22 = Data not saved successfully in Database
|
||||
|
||||
|
||||
$fileds = array('expense_id','unique_url','ip','user_agent','create_date');
|
||||
|
||||
|
||||
$dbData["LoadingHistory"] = $form;
|
||||
|
||||
//insert into the table group_expenses
|
||||
if(!$this->save($dbData,false,$fileds)){
|
||||
$result["22"] = __("LBL_LOGIN_HISTORY_NOT_SAVED");
|
||||
}
|
||||
|
||||
//$log = $this->getDataSource()->getLog(false, false);
|
||||
// debug($log);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
6
app/Model/Log.php
Normal file
6
app/Model/Log.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
class Log extends AppModel
|
||||
{
|
||||
var $name='Log';
|
||||
}
|
||||
?>
|
||||
50
app/Model/LogAppCrashes.php
Normal file
50
app/Model/LogAppCrashes.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
class LogAppCrashes extends AppModel
|
||||
{
|
||||
var $name='LogAppCrashes';
|
||||
|
||||
function insertLogAppCrashes($inputData){
|
||||
|
||||
$result = false;
|
||||
// $expense_type = substr($inputData["unique_url"], 0, 1);
|
||||
if(!isset($inputData["expense_type"])){
|
||||
$form["expense_type"] = 0;
|
||||
} else {
|
||||
$form["expense_type"] = trim($inputData["expense_type"]);
|
||||
}
|
||||
$input_request_data = $this->convertJson($inputData['request']);
|
||||
$input_response_data = $this->convertJson($inputData['response']);
|
||||
|
||||
$form["error_code"] = trim($inputData["error_code"]);
|
||||
$form["error_desc"] = trim($inputData["error_desc"]);
|
||||
$form["request"] = $input_request_data;
|
||||
$form["response"] = $input_response_data;
|
||||
$form["crash_date"] = trim($inputData["crash_date"]);
|
||||
$form["ip"] = trim($inputData["ip"]);
|
||||
$form["device_info"] = trim($inputData["device_info"]);
|
||||
|
||||
|
||||
$fileds = array('expense_type','error_code','error_desc','request','response','crash_date','ip','device_info');
|
||||
|
||||
|
||||
$dbData["LogAppCrashes"] = $form;
|
||||
|
||||
//print_r($data["Feeback"]);exit;
|
||||
|
||||
if(!$this->save($dbData,false,$fileds)){
|
||||
$result = true;
|
||||
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function convertJson($input_data)
|
||||
{
|
||||
$data = trim($input_data);
|
||||
$unserialized_data = unserialize($data);
|
||||
$json_data = json_encode($unserialized_data);
|
||||
return $json_data;
|
||||
}
|
||||
|
||||
}
|
||||
31
app/Model/LogAppVisitors.php
Normal file
31
app/Model/LogAppVisitors.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
class LogAppVisitors extends AppModel
|
||||
{
|
||||
var $name='LogAppVisitors';
|
||||
|
||||
function insertLogAppVisitors($inputData){
|
||||
|
||||
$result = false;
|
||||
$form["expense_type"] = trim($inputData["expense_type"]);
|
||||
$form["app_type"] = trim($inputData["app_type"]);
|
||||
$form["visiting_date"] = trim($inputData["visiting_date"]);
|
||||
$form["ip"] = trim($inputData["ip"]);
|
||||
$form["device_info"] = trim($inputData["device_info"]);
|
||||
|
||||
|
||||
$fileds = array('expense_type','app_type','visiting_date','ip','device_info');
|
||||
|
||||
|
||||
$dbData["LogAppVisitors"] = $form;
|
||||
|
||||
//print_r($data["Feeback"]);exit;
|
||||
|
||||
if(!$this->save($dbData,false,$fileds)){
|
||||
$result = true;
|
||||
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
450
app/Model/Meal.php
Normal file
450
app/Model/Meal.php
Normal file
@@ -0,0 +1,450 @@
|
||||
<?php
|
||||
class Meal extends AppModel
|
||||
{
|
||||
var $name='Meal';
|
||||
//1 = meal already has been added
|
||||
//2 = participant in this Meal is deleted by other user or not available
|
||||
|
||||
|
||||
|
||||
private function validateAddMeal($data){
|
||||
|
||||
$errorCode = "";
|
||||
|
||||
$checkParticipantList = array();
|
||||
|
||||
$form = $this->getFormDataByData($data);
|
||||
|
||||
|
||||
//check the participant involes in the meal are available or not
|
||||
if($errorCode == "" ){
|
||||
|
||||
|
||||
$participantAmtStrArray = explode(",",$form["meal_amount"]);
|
||||
foreach($participantAmtStrArray as $key=>$value){
|
||||
$parts = explode("|",$value);
|
||||
array_push($checkParticipantList,$parts[0]);
|
||||
}
|
||||
|
||||
//make array unique
|
||||
//$checkParticipantList = array_unique($checkParticipantList);
|
||||
|
||||
//retrieve participant from DB
|
||||
$dbParticipantList = $this->getParticipantIdListByExpId($form['expense_id']);
|
||||
|
||||
//retrieve participants from DB
|
||||
//print_r($checkParticipantList);exit;
|
||||
|
||||
foreach($checkParticipantList as $index=>$item){
|
||||
if (!in_array($item, $dbParticipantList)) {
|
||||
$errorCode = "2";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $errorCode;
|
||||
}
|
||||
|
||||
|
||||
private function validateEditMeal($data){
|
||||
$errorCode= $this->validateAddMeal($data);
|
||||
|
||||
//check the meal object exist or not in DB
|
||||
//check the new participant involves in meal exist in participant table or not
|
||||
|
||||
|
||||
if(empty($errorCode)){
|
||||
//check the expense is in DB or not
|
||||
|
||||
}
|
||||
|
||||
return $errorCode;
|
||||
}
|
||||
|
||||
public function getMealLog($data){
|
||||
|
||||
$expense_id = $data["expense_id"];
|
||||
$frommDate = $data["fromDate"]." 00:00:00";
|
||||
/* $date = new DateTime($frommDate);
|
||||
$frommDate = $date->format('Y-m-d'); */
|
||||
|
||||
$toDate = date("Y-m-d", strtotime("+1 day", strtotime($data["toDate"])));
|
||||
/* $date = new DateTime($toDate);
|
||||
$toDate = $date->format('Y-m-d'); */
|
||||
|
||||
App::import('model','Log');
|
||||
$log = new Log();
|
||||
$result = $log->find('all', array('conditions' => array(
|
||||
'Log.expense_id' =>$expense_id,
|
||||
'Log.create_date >= ' => $frommDate,
|
||||
'Log.create_date <= ' => $toDate
|
||||
),
|
||||
'order' => 'Log.create_date DESC'));
|
||||
// $log = $this->getDataSource()->getLog(false, false);
|
||||
// $fp = fopen("testResult.txt","a+");
|
||||
// fwrite($fp,$frommDate."=".$toDate);
|
||||
// debug($log);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function getParticipantIdListByExpId($expense_id){
|
||||
App::import('model','Participant');
|
||||
$participant = new Participant();
|
||||
$dbParticipantIdList = array();
|
||||
$data = $participant->find('all',
|
||||
array('conditions' =>
|
||||
array('Participant.expense_id =' => $expense_id)));
|
||||
foreach($data as $index=>$object){
|
||||
array_push($dbParticipantIdList,$object["Participant"]["participant_id"]);
|
||||
}
|
||||
|
||||
return $dbParticipantIdList;
|
||||
}
|
||||
|
||||
public function addMeal($data){
|
||||
|
||||
$result = null;
|
||||
//check the any of the involves participant(s) has been deleted or not
|
||||
//check account is closed already or not
|
||||
//update participant's balance
|
||||
//22 = Data not saved successfully in Database
|
||||
|
||||
$form = $this->getFormDataByData($data);
|
||||
|
||||
//check already record exist in DB for this date or not
|
||||
$dbMeal = $this->find('all',
|
||||
array('conditions' =>
|
||||
array('Meal.expense_id =' => $form["expense_id"],'Meal.date_new =' => $form["date_new"])));
|
||||
|
||||
if(!empty($dbMeal)){
|
||||
$errorCode = "1";
|
||||
} else {
|
||||
$errorCode = $this->validateAddMeal($data);
|
||||
}
|
||||
|
||||
|
||||
if(empty($errorCode)){
|
||||
|
||||
/*
|
||||
|
||||
$fp = fopen("result.txt",'a+');
|
||||
fwrite($fp,implode(" ",$form));*/
|
||||
|
||||
$fileds = array('expense_id','date','date_new','update_date','meal_amount','version');
|
||||
$dbData["Meal"] = $form;
|
||||
|
||||
if(!$this->save($dbData,false,$fileds)){
|
||||
$result["22"] = __("LBL_MEAL_NOT_SAVED");
|
||||
}
|
||||
} else {
|
||||
$result[$errorCode] = __("LBL_ADD_MEAL_FAILS");
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
public function addMultipleMeal($mealList,$expense_id){
|
||||
|
||||
$error = "";
|
||||
//check the any of the involves participant(s) has been deleted or not
|
||||
//check account is closed already or not
|
||||
//update participant's balance
|
||||
//22 = Data not saved successfully in Database
|
||||
|
||||
$i = 0;
|
||||
if(!empty($mealList)){
|
||||
foreach( $mealList as $key=>$value){
|
||||
$value["source"] = "2"; //2=mobile
|
||||
$value["expense_id"] = $expense_id;
|
||||
$form["Meal"][$i] = $this->getFormDataByData($value);
|
||||
|
||||
$i = $i + 1;
|
||||
}
|
||||
|
||||
if(!$this->saveMany($form["Meal"])){
|
||||
$error = "22";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $error;
|
||||
}
|
||||
|
||||
private function getFormDataByData($data){
|
||||
$form = array();
|
||||
//$form["id"] = $data["id"];
|
||||
$form["expense_id"] = $data["expense_id"];
|
||||
if(isset($data["date_old"])){
|
||||
$form["date"] = $data["date_old"];
|
||||
}
|
||||
|
||||
$form["date_new"] = $data["date"];
|
||||
$form["meal_amount"] = $data["meal_amount"];
|
||||
|
||||
$form["version"] = 0;
|
||||
|
||||
$form["update_date"] = $this->getSystemCurrentIntTime();
|
||||
|
||||
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
||||
public function modifyMultipleMeal($expenseList,$expenseId){
|
||||
|
||||
$error = "";
|
||||
//check the any of the involves participant(s) has been deleted or not
|
||||
//check account is closed already or not
|
||||
//update participant's balance
|
||||
//22 = Data not saved successfully in Database
|
||||
|
||||
$i = 0;
|
||||
|
||||
foreach( $expenseList as $key=>$value){
|
||||
$value["expense_id"] = $expenseId;
|
||||
$version = $value["version"];
|
||||
$form["Meal"][$i] = $this->getFormDataByData($value);
|
||||
$form["Meal"][$i]['version'] = ($version)+1;
|
||||
$form["Meal"][$i]['id'] = $value["id"];
|
||||
|
||||
/*//set log List
|
||||
$logList["Log"][$i]['expense_id'] = $form["GroupExpense"][$i]["expense_id"];
|
||||
$logList["Log"][$i]['previous_desc'] = $form["GroupExpense"][$i]["previous_desc"];
|
||||
$logList["Log"][$i]['new_desc'] = $form["GroupExpense"][$i]["new_desc"];
|
||||
$logList["Log"][$i]['previous_paid_by'] = $form["GroupExpense"][$i]["previous_paid_by"]; */
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
|
||||
/*App::import('model','Log');
|
||||
$log = new Log();*/
|
||||
|
||||
|
||||
//check the any of the involves participant(s) has been deleted or not
|
||||
//check account is closed already or not
|
||||
//update participant's balance
|
||||
//3 = group expense not available in database;
|
||||
//22 = Data not saved successfully in Database
|
||||
//23 = Log insertion fail
|
||||
|
||||
//increase number of version
|
||||
|
||||
|
||||
//check similar like Add expense
|
||||
//$errorCode = $this->validateEditExpense($data);
|
||||
|
||||
|
||||
if(!$this->saveMany($form["Meal"])){
|
||||
//data modify fails
|
||||
$error = "22";
|
||||
} else {
|
||||
//data modify successfull.hence insert logs
|
||||
|
||||
/*if(!$log->saveMany($logList["Log"])){
|
||||
//data modify fails
|
||||
$error = "23";
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
return $error;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function modifyMeal($data){
|
||||
|
||||
//check the any of the involves participant(s) has been deleted or not
|
||||
//check account is closed already or not
|
||||
//update participant's balance
|
||||
//3 = group expense not available in database;
|
||||
//22 = Data not saved successfully in Database
|
||||
//23 = Log insertion fail
|
||||
|
||||
$result = null;
|
||||
$form = $this->getFormDataByData($data);
|
||||
|
||||
//retrieve the existing expense from DB
|
||||
|
||||
$dbMeal = $this->find('all',
|
||||
array('conditions' =>
|
||||
array('Meal.expense_id =' => $form["expense_id"],'Meal.date_new =' => $data["old_date"])));
|
||||
|
||||
|
||||
if(empty($dbMeal)){
|
||||
//if expense not available in DB
|
||||
$result["3"] = __("LBL_MEAL_NOT_AVAILABLE");
|
||||
} else {
|
||||
|
||||
//increase number of version
|
||||
$form['version'] = ($dbMeal["0"]["Meal"]["version"])+1;
|
||||
$form["id"] = $dbMeal["0"]["Meal"]["id"];
|
||||
|
||||
//check similar like Add expense
|
||||
$errorCode = $this->validateEditMeal($data);
|
||||
|
||||
if(empty($errorCode)){
|
||||
|
||||
$fileds = array('id','expense_id','date','date_new','update_date','meal_amount','version');
|
||||
$data["Meal"] = $form;
|
||||
|
||||
if(!$this->save($data,false,$fileds)){
|
||||
//data modify fails
|
||||
$result["22"] = __("LBL_DATA_SAVED_SUCCESSFULLY_DATABASE");
|
||||
} else {
|
||||
//data modify successfull.hence insert logs
|
||||
/*App::import('model','Log');
|
||||
$log = new Log();
|
||||
|
||||
$fileds = array('expense_id','previous_paid_by','previous_desc','new_desc');
|
||||
$logData['Log'] = $this->getEditLogData($form);
|
||||
if(!$log->save($logData,false,$fileds)){
|
||||
//data modify fails
|
||||
$result["23"] = "Log insertion fail";
|
||||
}*/
|
||||
}
|
||||
} else {
|
||||
//Found error
|
||||
$result[$errorCode] = __("LBL_EDIT_MEAL_FAILS");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
private function getEditLogData($form){
|
||||
$result = array();
|
||||
|
||||
$result['expense_id'] = $form['expense_id'];
|
||||
$result['previous_desc'] = $form['previous_desc'];
|
||||
$result['new_desc'] = $form['new_desc'];
|
||||
$result['previous_paid_by'] = $form['previous_paid_by'];
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
public function deleteMultipleMeal($expenseList,$expenseId){
|
||||
|
||||
$error = "";
|
||||
//check the any of the involves participant(s) has been deleted or not
|
||||
//check account is closed already or not
|
||||
//update participant's balance
|
||||
//22 = Data not saved successfully in Database
|
||||
|
||||
$i = 0;
|
||||
|
||||
foreach( $expenseList as $key=>$value){
|
||||
$mealIdList[] = $value["id"];
|
||||
//set log List
|
||||
/*$logList["Log"][$i]['expense_id'] = $expenseId;
|
||||
$logList["Log"][$i]['previous_desc'] = $value["previous_desc"];
|
||||
$logList["Log"][$i]['new_desc'] = $value["new_desc"];
|
||||
$logList["Log"][$i]['previous_paid_by'] = $value["previous_paid_by"];
|
||||
|
||||
$i++;*/
|
||||
}
|
||||
|
||||
/*
|
||||
App::import('model','Log');
|
||||
$log = new Log();
|
||||
*/
|
||||
|
||||
//check the any of the involves participant(s) has been deleted or not
|
||||
//check account is closed already or not
|
||||
//update participant's balance
|
||||
//3 = group expense not available in database;
|
||||
//22 = Data not saved successfully in Database
|
||||
//23 = Log insertion fail
|
||||
|
||||
//increase number of version
|
||||
|
||||
|
||||
//check similar like Add expense
|
||||
//$errorCode = $this->validateEditExpense($data);
|
||||
|
||||
|
||||
if(!$this->deleteAll(array('Meal.id' => $mealIdList))){
|
||||
//data modify fails
|
||||
$error = "22";
|
||||
} else {
|
||||
//data modify successfull.hence insert logs
|
||||
|
||||
/*if(!$log->saveMany($logList["Log"])){
|
||||
//data modify fails
|
||||
$error = "23";
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
return $error;
|
||||
|
||||
}
|
||||
|
||||
public function deleteMeal($data){
|
||||
|
||||
$result = null;
|
||||
$form = $this->getFormDataByData($data);
|
||||
|
||||
// $fp = fopen("result.txt",'w+');
|
||||
// fwrite($fp,$form["expense_id"]."==".$form["date"]);exit;
|
||||
|
||||
//retrieve the existing expense from DB
|
||||
|
||||
$dbMeal = $this->find('all',
|
||||
array('conditions' =>
|
||||
array('Meal.expense_id =' => $form["expense_id"],'Meal.date_new =' => $form["date_new"])));
|
||||
|
||||
//$fp = fopen("result.txt",'w+');
|
||||
// fwrite($fp,implode(" ",$dbMeal));
|
||||
|
||||
|
||||
|
||||
if(empty($dbMeal)){
|
||||
//if expense not available in DB
|
||||
$result["3"] = __("LBL_MEAL_NOT_AVAILABLE");
|
||||
} else {
|
||||
$form["id"] = $dbMeal["0"]["Meal"]["id"];
|
||||
if(!$this->delete(array('id'=>$form["id"]))){
|
||||
|
||||
//data modify fails
|
||||
$result["22"] = __("LBL_MEAL_NOT_DELETED");
|
||||
} else {
|
||||
|
||||
//data modify successfull.hence insert logs
|
||||
/*App::import('model','Log');
|
||||
$log = new Log();
|
||||
|
||||
$fileds = array('expense_id','previous_paid_by','previous_desc','new_desc');
|
||||
$logData['Log'] = $this->getEditLogData($form);
|
||||
if(!$log->save($logData,false,$fileds)){
|
||||
//data modify fails
|
||||
$result["23"] = "Log insertion fail";
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function getSystemCurrentIntTime(){
|
||||
date_default_timezone_set("UTC");
|
||||
return time();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
37
app/Model/Order.php
Normal file
37
app/Model/Order.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
class Order extends AppModel
|
||||
{
|
||||
var $name='Order';
|
||||
|
||||
|
||||
|
||||
function list($conditions = array(), $order = 'id desc' )
|
||||
{
|
||||
return $this->find('all', array(
|
||||
'conditions' => $conditions,
|
||||
'order' => $order,
|
||||
));
|
||||
}
|
||||
|
||||
function add($inputData)
|
||||
{
|
||||
$result = false;
|
||||
|
||||
if(!empty($inputData))
|
||||
{
|
||||
$fileds = array();
|
||||
$dbData["Order"] = $inputData;
|
||||
if($this->save($dbData,false,$fileds)){
|
||||
$dbData["Order"]['id'] = $this->id;
|
||||
$result = true;
|
||||
}
|
||||
}
|
||||
return array($result,$dbData["Order"]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
32
app/Model/OrderBilling.php
Normal file
32
app/Model/OrderBilling.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
class OrderBilling extends AppModel
|
||||
{
|
||||
var $name='OrderBilling';
|
||||
|
||||
|
||||
|
||||
function list($conditions = array() )
|
||||
{
|
||||
return $this->find('all', array('conditions' => $conditions));
|
||||
}
|
||||
|
||||
function add($inputData)
|
||||
{
|
||||
$result = false;
|
||||
|
||||
if(!empty($inputData))
|
||||
{
|
||||
$fileds = array();
|
||||
$dbData["OrderBilling"] = $inputData;
|
||||
if($this->save($dbData,false,$fileds)){
|
||||
$dbData["OrderBilling"]['id'] = $this->id;
|
||||
$result = true;
|
||||
}
|
||||
}
|
||||
return array($result,$dbData["OrderBilling"]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
383
app/Model/Participant.php
Normal file
383
app/Model/Participant.php
Normal file
@@ -0,0 +1,383 @@
|
||||
<?php
|
||||
class Participant extends AppModel
|
||||
{
|
||||
var $name='Participant';
|
||||
|
||||
private function validateAddParticipant($dbData,$data,$isAdd){
|
||||
|
||||
$errorCode = "";
|
||||
//1 = Input data format is not correct
|
||||
//4 = participant already exist in database
|
||||
|
||||
if($data["name"] == ""){
|
||||
$errorCode = 1;
|
||||
} else if(mb_strlen($data["name"], 'UTF-8') > PARTICIPENT_NAME_LENGTH){
|
||||
$errorCode = 2;
|
||||
} if(mb_strlen($data["name"], 'UTF-8') > mb_strlen(str_replace(",","",$data["name"]), 'UTF-8')
|
||||
|| mb_strlen($data["name"], 'UTF-8') > mb_strlen(str_replace("|","",$data["name"]), 'UTF-8')){
|
||||
$errorCode = 3;
|
||||
}
|
||||
|
||||
if($errorCode == ""){
|
||||
|
||||
|
||||
|
||||
foreach($dbData as $key=>$value){
|
||||
|
||||
if($isAdd == false && trim($value["Participant"]["participant_id"]) == $data["participant_id"] ){
|
||||
continue;
|
||||
}
|
||||
|
||||
if(strtolower(trim($value["Participant"]["name"])) == strtolower($data["name"])){
|
||||
|
||||
$errorCode = 4;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* $fp = fopen("Test.txt","a+");
|
||||
fwrite($fp,"error".$errorCode);exit; */
|
||||
|
||||
return $errorCode;
|
||||
}
|
||||
|
||||
|
||||
private function getFormDataByData($data){
|
||||
$form = array();
|
||||
$form["participant_id"] = trim($data["id"]);
|
||||
$form["expense_id"] = trim($data["expense_id"]);
|
||||
$form["name"] = trim($data["name"]);
|
||||
$form["is_creator"] = 0;
|
||||
|
||||
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function addParticipant($data){
|
||||
|
||||
|
||||
// $fp = fopen("result.txt","w+");
|
||||
// fwrite($fp,"in add Participant");
|
||||
$result = null;
|
||||
//1 = Input data format is not correct
|
||||
//4 = participant already exist in database
|
||||
//22 = Data not saved successfully in Database
|
||||
|
||||
$form = $this->getFormDataByData($data);
|
||||
|
||||
$dbData = $this->find('all', array('conditions' => array('Participant.expense_id' =>$form["expense_id"])));
|
||||
|
||||
$errorCode = $this->validateAddParticipant($dbData,$form,true);
|
||||
|
||||
if(empty($errorCode)){
|
||||
|
||||
|
||||
$fileds = array('participant_id','expense_id','name','is_creator');
|
||||
|
||||
|
||||
$dbData["Participant"] = $form;
|
||||
|
||||
//insert into the table group_expenses
|
||||
if(trim($form["name"]) != "" && !$this->save($dbData,false,$fileds)){
|
||||
$result["22"] = "Participant has not been added successfully";
|
||||
}
|
||||
|
||||
} else {
|
||||
$result[$errorCode] = __("LBL_ADD_PARTICIPANT_FAILS");
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $result;
|
||||
|
||||
|
||||
}
|
||||
|
||||
function addMultipleParticipant($participantList,$expense_id){
|
||||
//$fp = fopen("result.txt","w+");
|
||||
//fwrite($fp,"in add Multiple Participant");
|
||||
$error = "";
|
||||
$i = 0;
|
||||
//1 = Input data format is not correct
|
||||
//4 = participant already exist in database
|
||||
//22 = Data not saved successfully in Database
|
||||
|
||||
if(!empty($participantList)){
|
||||
|
||||
foreach($participantList as $key=>$value){
|
||||
$value["id"] = $value["participant_id"]; //2=mobile
|
||||
$value["expense_id"] = $expense_id;
|
||||
|
||||
if(!empty($value)){
|
||||
$form["Participant"][$i] = $this->getFormDataByData($value);
|
||||
$form["Participant"][$i]["id"] = "";
|
||||
$i = $i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
//echo "<pre>";
|
||||
// print_r($form["Participant"]);exit;
|
||||
|
||||
if($i>0 && !$this->saveMany($form["Participant"])){
|
||||
$error = "22";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return $error;
|
||||
|
||||
|
||||
}
|
||||
|
||||
function modifyParticipant($data){
|
||||
|
||||
|
||||
//$fp = fopen("result.txt","w+");
|
||||
// fwrite($fp,"in Modify Participant");
|
||||
|
||||
$result = null;
|
||||
//1 = Input data format is not correct
|
||||
//4 = participant already exist in database
|
||||
//22 = Data not saved successfully in Database
|
||||
|
||||
$form = $this->getFormDataByData($data);
|
||||
$dbData = $this->find('all', array('conditions' => array('Participant.expense_id' =>$form["expense_id"])));
|
||||
|
||||
$errorCode = $this->validateAddParticipant($dbData,$form,false);
|
||||
|
||||
if(empty($errorCode)){
|
||||
|
||||
|
||||
$fileds = array('name','version');
|
||||
|
||||
//get participant ID
|
||||
$form['id'] = "";
|
||||
foreach($dbData as $key=>$value){
|
||||
if(trim($value["Participant"]["participant_id"]) == $form["participant_id"]){
|
||||
$form['id'] = trim($value["Participant"]["id"]);
|
||||
$form['version'] = trim($value["Participant"]["version"]) + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$saveData["Participant"] = $form;
|
||||
|
||||
//insert into the table group_expenses
|
||||
if(trim($form["name"]) != "" && !$this->save($saveData,false,$fileds)){
|
||||
$result["22"] = __("LBL_PARTICIPANT_NOT_UPDATED");
|
||||
}
|
||||
|
||||
} else {
|
||||
$result[$errorCode] = __("LBL_PARTICIPANT_FAILS");
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $result;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function modifyMultipleParticipant($participantList){
|
||||
|
||||
//$fp = fopen("result.txt","w+");
|
||||
// fwrite($fp,"in Modify Multiple Participant");
|
||||
|
||||
$error = "";
|
||||
$i = 0;
|
||||
//1 = Input data format is not correct
|
||||
//4 = participant already exist in database
|
||||
//22 = Data not saved successfully in Database
|
||||
|
||||
if(!empty($participantList)){
|
||||
|
||||
//echo "participant List<br/><pre>";
|
||||
//print_r($participantList);
|
||||
//exit;
|
||||
|
||||
foreach($participantList as $key=>$value){
|
||||
//$value["id"] = ""; //2=mobile
|
||||
//$value["expense_id"] = $expense_id;
|
||||
if(trim($value["name"]) != ""){
|
||||
$form["Participant"][$i]["id"] = $value["id"];
|
||||
$form["Participant"][$i]["name"] = $value["name"];
|
||||
$form["Participant"][$i]["version"] = $value["version"]+1;
|
||||
|
||||
$i = $i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if($i > 0 && !$this->saveMany($form["Participant"])){
|
||||
$error = "22";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return $error;
|
||||
}
|
||||
|
||||
function deleteMultipleParticipant($participantList){
|
||||
|
||||
$error = "";
|
||||
$i = 0;
|
||||
//1 = Input data format is not correct
|
||||
//4 = participant already exist in database
|
||||
//22 = Data not saved successfully in Database
|
||||
|
||||
if(!empty($participantList)){
|
||||
$participantIdList = array();
|
||||
foreach($participantList as $key=>$value){
|
||||
//$value["id"] = ""; //2=mobile
|
||||
//$value["expense_id"] = $expense_id;
|
||||
$participantIdList[] = $value["id"];
|
||||
}
|
||||
|
||||
if(!$this->deleteAll(array('Participant.id' => $participantIdList))){
|
||||
$error = "22";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return $error;
|
||||
}
|
||||
|
||||
|
||||
function deleteParticpant($data){
|
||||
|
||||
|
||||
|
||||
$result = null;
|
||||
$form = $this->getFormDataByData($data);
|
||||
|
||||
//retrieve the existing expense from DB
|
||||
App::import('model','GroupExpense');
|
||||
$GroupExpense = new GroupExpense();
|
||||
$dbExpense = $GroupExpense->find('all',
|
||||
array('conditions' =>
|
||||
array('GroupExpense.expense_id =' => $form["expense_id"])));
|
||||
|
||||
|
||||
|
||||
//if(empty($dbExpense)){
|
||||
//if expense not available in DB
|
||||
// $result["3"] = "Group Expense not available in database";
|
||||
//} else {
|
||||
|
||||
//validate if any of the paid by/amount str has the participant id
|
||||
$validation_result = true;
|
||||
|
||||
//check participant has any expense or not
|
||||
if(!empty($dbExpense)){
|
||||
|
||||
foreach($dbExpense as $key=>$value){
|
||||
//check paid by
|
||||
if(trim($value['GroupExpense']['paid_by_participant_id']) == $form['participant_id']) {
|
||||
$validation_result = false;
|
||||
break;
|
||||
}
|
||||
|
||||
//check amount String
|
||||
$amountStr = trim($value['GroupExpense']['participant_amount']);
|
||||
|
||||
$amountStrArray = explode(',',$amountStr);
|
||||
foreach($amountStrArray as $seq=>$item){
|
||||
$participantIdStrArray = explode("|",$item);
|
||||
|
||||
if(trim($participantIdStrArray[0]) == $form['participant_id']) {
|
||||
$validation_result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if($validation_result == false)
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//check participant has any meal or not
|
||||
if($validation_result == true){
|
||||
|
||||
App::import('model','Meal');
|
||||
$Meal = new Meal();
|
||||
$dbMeal = $Meal->find('all',
|
||||
array('conditions' => array('Meal.expense_id =' => $form["expense_id"])));
|
||||
|
||||
if(!empty($dbMeal)){
|
||||
|
||||
foreach($dbMeal as $key=>$value){
|
||||
|
||||
//check amount String
|
||||
$mealStr = trim($value['Meal']['meal_amount']);
|
||||
|
||||
$mealStrArray = explode(',',$mealStr);
|
||||
foreach($mealStrArray as $seq=>$item){
|
||||
$participantIdStrArray = explode("|",$item);
|
||||
|
||||
if(trim($participantIdStrArray[0]) == $form['participant_id']) {
|
||||
$validation_result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if($validation_result == false)
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if($validation_result == true){
|
||||
if(!$this->deleteAll(array('Participant.expense_id' => $form["expense_id"],'Participant.participant_id' => $form["participant_id"]), false)){
|
||||
|
||||
//data modify fails
|
||||
$result["22"] = __("LBL_PARTICIPANT_NOT_DELETED");
|
||||
}
|
||||
} else {
|
||||
$result["24"] = __("LBL_PARTICIPANT_NOT_DELETED");
|
||||
}
|
||||
|
||||
//}
|
||||
|
||||
//$log = $this->getDataSource()->getLog(false, false);
|
||||
//debug($log);
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
function getExpenseIdListByFacebookId($facebook_id){
|
||||
$expenseIdList = NULL;
|
||||
|
||||
|
||||
if(!empty($facebook_id)){
|
||||
|
||||
$result = $this->find('all', array('conditions' => array(
|
||||
'Participant.facebook_id' =>$facebook_id
|
||||
) ));
|
||||
|
||||
|
||||
if(!empty($result) && count($result) > 0){
|
||||
foreach($result as $key=>$value){
|
||||
$expenseIdList[] = $value["Participant"]["expense_id"];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $expenseIdList;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
18
app/Model/PaymentType.php
Normal file
18
app/Model/PaymentType.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
class PaymentType extends AppModel
|
||||
{
|
||||
var $name='PaymentType';
|
||||
|
||||
|
||||
|
||||
function list($conditions = array() )
|
||||
{
|
||||
return $this->find('all', array('conditions' => $conditions));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
115
app/Model/PermissionTable.php
Normal file
115
app/Model/PermissionTable.php
Normal file
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
class PermissionTable extends AppModel
|
||||
{
|
||||
var $name = 'PermissionTable';
|
||||
var $useTable = 'permissions';
|
||||
|
||||
public function getPermissionByUrlAndUserId($unique_url,$user_id) {
|
||||
$user_permission = $this->find('first', array(
|
||||
'conditions' => array('PermissionTable.unique_url' => $unique_url, 'PermissionTable.user_id' => $user_id)
|
||||
));
|
||||
if(empty($user_permission)) {
|
||||
return false;
|
||||
}
|
||||
return $user_permission;
|
||||
|
||||
}
|
||||
/* public function getPermissionByUrl($unique_url,$custom_select = false,$isOwner = false) {
|
||||
|
||||
$options = array(
|
||||
'conditions' => array('PermissionTable.unique_url' => $unique_url)
|
||||
);
|
||||
|
||||
if ($custom_select) {
|
||||
$options['fields'] = array('PermissionTable.profile_id', 'PermissionTable.role');
|
||||
}
|
||||
if($isOwner) {
|
||||
$options['conditions']['PermissionTable.role !='] = OWNER;
|
||||
}
|
||||
|
||||
$permissions = $this->find('all', $options);
|
||||
|
||||
if ($custom_select) {
|
||||
return array_map(function ($item) {
|
||||
return [
|
||||
'profile_id' => $item['PermissionTable']['profile_id'],
|
||||
'role' => $item['PermissionTable']['role']
|
||||
];
|
||||
}, $permissions);
|
||||
}
|
||||
return array_map(function ($item) {
|
||||
return [
|
||||
'user_id' => $item['PermissionTable']['user_id'],
|
||||
'profile_id' => $item['PermissionTable']['profile_id'],
|
||||
'role' => $item['PermissionTable']['role']
|
||||
];
|
||||
}, $permissions);
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
public function getPermissionByUrl($unique_url,$custom_select = false,$isOwner = false){
|
||||
$options = array(
|
||||
'conditions' => array(
|
||||
'PermissionTable.unique_url' => $unique_url
|
||||
),
|
||||
'joins' => array(
|
||||
array(
|
||||
'table' => 'users',
|
||||
'alias' => 'User',
|
||||
'type' => 'INNER',
|
||||
'conditions' => array(
|
||||
'User.id = PermissionTable.user_id'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
if ($isOwner) {
|
||||
$options['conditions']['PermissionTable.role !='] = OWNER;
|
||||
}
|
||||
|
||||
|
||||
$options['fields'] = array(
|
||||
'PermissionTable.user_id',
|
||||
'User.profile_id',
|
||||
'PermissionTable.role'
|
||||
);
|
||||
|
||||
$permissions = $this->find('all', $options);
|
||||
|
||||
if ($custom_select) {
|
||||
return array_map(function ($item) {
|
||||
return [
|
||||
'profile_id' => $item['User']['profile_id'],
|
||||
'role' => $item['PermissionTable']['role']
|
||||
];
|
||||
}, $permissions);
|
||||
}
|
||||
|
||||
return array_map(function ($item) {
|
||||
return [
|
||||
'user_id' => $item['PermissionTable']['user_id'],
|
||||
'profile_id' => $item['User']['profile_id'],
|
||||
'role' => $item['PermissionTable']['role']
|
||||
];
|
||||
}, $permissions);
|
||||
}
|
||||
|
||||
public function addPermission($request)
|
||||
{
|
||||
if (isset($request[0])) {
|
||||
return $this->saveMany($request);
|
||||
} else {
|
||||
return $this->save($request);
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteByCondition($deleteConditions)
|
||||
{
|
||||
return $this->deleteAll(
|
||||
array($deleteConditions)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
26
app/Model/Product.php
Normal file
26
app/Model/Product.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
class Product extends AppModel
|
||||
{
|
||||
var $name='Product';
|
||||
|
||||
|
||||
|
||||
function list($conditions = array() )
|
||||
{
|
||||
$returnData = array();
|
||||
$productObj = $this->find('all', array('conditions' => $conditions));
|
||||
|
||||
if(!empty($productObj)){
|
||||
foreach ($productObj as $product){
|
||||
$returnData[] = $product['Product'];
|
||||
}
|
||||
}
|
||||
return $returnData;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
64
app/Model/PushToken.php
Normal file
64
app/Model/PushToken.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
class PushToken extends AppModel
|
||||
{
|
||||
var $name='PushToken';
|
||||
|
||||
private $platforms = ['ios' => 1,'android' => 2, 'web' => 3];
|
||||
private $is_active = ['active' => 1, 'in_active' => 0];
|
||||
|
||||
|
||||
// Check if record exists for the user, device, platform
|
||||
public function checkActiveToken($userId, $deviceId, $platform) {
|
||||
return $this->find('first', array(
|
||||
'conditions' => array(
|
||||
'user_id' => $userId,
|
||||
'device_id' => $deviceId,
|
||||
'platform' => $platform
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
// get tokens
|
||||
public function getToken($params = array()) {
|
||||
|
||||
$conditions = array();
|
||||
|
||||
// Support single ID or multiple IDs
|
||||
if (!empty($params['user_id'])) {
|
||||
if (is_array($params['user_id'])) {
|
||||
$conditions['PushToken.user_id'] = $params['user_id'];
|
||||
} else {
|
||||
$conditions['PushToken.user_id'] = $params['user_id'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($params['device_id'])) {
|
||||
$conditions['PushToken.device_id'] = $params['device_id'];
|
||||
}
|
||||
|
||||
if (!empty($params['platform'])) {
|
||||
$conditions['PushToken.platform'] = $params['platform'];
|
||||
}
|
||||
|
||||
if (isset($params['status'])) {
|
||||
$conditions['PushToken.is_active'] = $params['status'];
|
||||
}
|
||||
if (isset($params['push_token'])) {
|
||||
$conditions['PushToken.push_token'] = $params['push_token'];
|
||||
}
|
||||
|
||||
return $this->find('all', array(
|
||||
'conditions' => $conditions
|
||||
));
|
||||
}
|
||||
|
||||
public function deleteByCondition($deleteConditions)
|
||||
{
|
||||
return $this->deleteAll(
|
||||
array($deleteConditions)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
32
app/Model/Recurring.php
Normal file
32
app/Model/Recurring.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
class Recurring extends AppModel
|
||||
{
|
||||
var $name='Recurring';
|
||||
|
||||
|
||||
|
||||
function list($conditions = array() )
|
||||
{
|
||||
return $this->find('all', array('conditions' => $conditions));
|
||||
}
|
||||
|
||||
function add($inputData)
|
||||
{
|
||||
$result = false;
|
||||
|
||||
if(!empty($inputData))
|
||||
{
|
||||
$fileds = array();
|
||||
$dbData["Recurring"] = $inputData;
|
||||
if($this->save($dbData,false,$fileds)){
|
||||
$dbData["Recurring"]['id'] = $this->id;
|
||||
$result = true;
|
||||
}
|
||||
}
|
||||
return array($result,$dbData["Recurring"]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
31
app/Model/TempExpenseEmail.php
Normal file
31
app/Model/TempExpenseEmail.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
class TempExpenseEmail extends AppModel
|
||||
{
|
||||
var $name='TempExpenseEmail';
|
||||
|
||||
function insertTempExpenseEmail($inputData){
|
||||
|
||||
$result = NULL;
|
||||
$form["id"] = trim($inputData["id"]);
|
||||
$form["unique_url"] = trim($inputData["unique_url"]);
|
||||
$form["email"] = trim($inputData["email"]);
|
||||
$form["title"] = trim($inputData["title"]);
|
||||
$form["create_date"] = trim($inputData["create_date"]);
|
||||
|
||||
|
||||
$fileds = array('id','unique_url','email','title','create_date');
|
||||
|
||||
|
||||
$dbData["TempExpenseEmail"] = $form;
|
||||
|
||||
//print_r($data["Feeback"]);exit;
|
||||
|
||||
if(!$this->save($dbData,false,$fileds)){
|
||||
$result["22"] = __("LBL_TEMP_EXPENSE_EMAIL_NOT_SAVED");
|
||||
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
32
app/Model/Transaction.php
Normal file
32
app/Model/Transaction.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
class Transaction extends AppModel
|
||||
{
|
||||
var $name='Transaction';
|
||||
|
||||
|
||||
|
||||
function list($conditions = array() )
|
||||
{
|
||||
return $this->find('all', array('conditions' => $conditions));
|
||||
}
|
||||
|
||||
function add($inputData)
|
||||
{
|
||||
$result = false;
|
||||
|
||||
if(!empty($inputData))
|
||||
{
|
||||
$fileds = array();
|
||||
$dbData["Transaction"] = $inputData;
|
||||
if($this->save($dbData,false,$fileds)){
|
||||
$dbData["Transaction"]['id'] = $this->id;
|
||||
$result = true;
|
||||
}
|
||||
}
|
||||
return array($result,$dbData["Transaction"]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
230
app/Model/User.php
Normal file
230
app/Model/User.php
Normal file
@@ -0,0 +1,230 @@
|
||||
<?php
|
||||
|
||||
class User extends AppModel
|
||||
{
|
||||
var $name='User';
|
||||
|
||||
|
||||
function isUserExist( $profile_id ){
|
||||
|
||||
/*
|
||||
$unique_number = "234234-34234-234234-234234-324234"."4537"; // device id + six digit random number
|
||||
$salt = 'Nop@ss%!*-+@s=_17';
|
||||
$generated_token = hash('sha256', $unique_number . $salt);
|
||||
|
||||
echo $generated_token;exit;
|
||||
*/
|
||||
$result = true;
|
||||
|
||||
// $profile_id = "'".$profile_id."'";
|
||||
|
||||
$userObj = $this->find('first', array('conditions' => array('profile_id' =>$profile_id)));
|
||||
//$log = $this->getDataSource()->getLog(false, false);
|
||||
|
||||
|
||||
if(empty($userObj)){
|
||||
$result = false;
|
||||
}
|
||||
|
||||
return array($result,$userObj);
|
||||
|
||||
}
|
||||
|
||||
function isUserIdExist( $user_id ){
|
||||
$result = true;
|
||||
|
||||
$userObj = $this->find('first', array('conditions' => array('id' =>$user_id)));
|
||||
if(empty($userObj)){
|
||||
$result = false;
|
||||
}
|
||||
return array($result,$userObj);
|
||||
}
|
||||
|
||||
function getUserByProfileId($profile_id) {
|
||||
$userObj = $this->find('first', array('fields' => array('id', 'first_name','last_name','password','profile_type', 'profile_id','is_verified','nick_name', 'preferences','version','create_date', 'update_date'),'conditions' => array('profile_id' =>$profile_id)));
|
||||
return $userObj;
|
||||
}
|
||||
|
||||
function getUserByUserId($user_id){
|
||||
//$userObj = $this->find('first', array('fields' => array('id', 'first_name','last_name','password','profile_type', 'profile_id','is_verified','nick_name', 'preferences','version','create_date', 'update_date'),'conditions' => array('id' =>$user_id)));
|
||||
$userObj = $this->find('first', array('fields' => array('id','profile_type', 'profile_id','first_name','last_name'),'conditions' => array('id' =>$user_id)));
|
||||
return $userObj;
|
||||
}
|
||||
|
||||
|
||||
function insertUser($inputData){
|
||||
|
||||
$result = false;
|
||||
|
||||
//$form["first_name"] = trim($inputData["first_name"]);
|
||||
//$form["last_name"] = trim($inputData["last_name"]);
|
||||
|
||||
//1=email, 2=gmail, 3=facebook, 4= twiitter; default = 1
|
||||
$form["profile_type"] = trim($inputData["profile_type"]);
|
||||
$form["profile_id"] = trim($inputData["profile_id"]);
|
||||
$form["password"] = trim($inputData["password"]);
|
||||
//$form["preferences"] = trim($inputData["preferences"]);
|
||||
|
||||
if (isset($inputData["is_verified"])) {
|
||||
$form["is_verified"] = trim($inputData["is_verified"]);
|
||||
}
|
||||
//$form["nick_name"] = trim($inputData["nick_name"]);
|
||||
|
||||
|
||||
|
||||
|
||||
//$form["ip"] = trim($inputData["ip"]);
|
||||
//$form["device_info"] = trim($inputData["device_info"]);
|
||||
|
||||
$form["create_date"] = trim($inputData["create_date"]);
|
||||
$form["update_date"] = trim($inputData["update_date"]);
|
||||
|
||||
|
||||
$fileds = array('first_name','last_name','profile_type','profile_id','password',
|
||||
'preferences','is_verified','nick_name', 'ip', 'device_info','create_date','update_date');
|
||||
|
||||
|
||||
|
||||
|
||||
$dbData["User"] = $form;
|
||||
|
||||
if($this->save($dbData,false,$fileds)){
|
||||
$result = true;
|
||||
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
function saveAllGroups($data){
|
||||
|
||||
}
|
||||
|
||||
function setPassTokenByProfileId( $profile_id, $resetPassToken, $resetPassTokenExpireDateTime )
|
||||
{
|
||||
return $this->updateAll(
|
||||
array(
|
||||
"resetpass_token" => '"'.$resetPassToken.'"',
|
||||
"resetpass_token_expire_date" => '"'.$resetPassTokenExpireDateTime.'"'
|
||||
),
|
||||
array("profile_id" => $profile_id)
|
||||
);
|
||||
}
|
||||
|
||||
function resetPassTokenByProfileId( $profile_id )
|
||||
{
|
||||
return $this->updateAll(
|
||||
array(
|
||||
"resetpass_token" => null,
|
||||
"resetpass_token_expire_date" => null
|
||||
),
|
||||
array("profile_id" => $profile_id)
|
||||
);
|
||||
}
|
||||
|
||||
function setVerificationTokenByProfileId( $profile_id, $verificationToken )
|
||||
{
|
||||
return $this->updateAll(
|
||||
array(
|
||||
"verification_token" => '"'.$verificationToken.'"'
|
||||
),
|
||||
array("profile_id" => $profile_id)
|
||||
);
|
||||
}
|
||||
|
||||
function resetVerificationTokenByProfileId( $profile_id )
|
||||
{
|
||||
return $this->updateAll(
|
||||
array(
|
||||
"verification_token" => null,
|
||||
"is_verified" => 1
|
||||
),
|
||||
array("profile_id" => $profile_id)
|
||||
);
|
||||
}
|
||||
|
||||
function setPasswordByProfileId( $profile_id, $password )
|
||||
{
|
||||
return $this->updateAll(
|
||||
array(
|
||||
"password" => '"'.$password.'"'
|
||||
),
|
||||
array("profile_id" => $profile_id)
|
||||
);
|
||||
}
|
||||
|
||||
function isUserExistByResetPassToken( $resetPassToken )
|
||||
{
|
||||
$result = true;
|
||||
if(!empty($resetPassToken)){
|
||||
$userObj = $this->find('first', array(
|
||||
'conditions' => array('resetpass_token' => $resetPassToken)
|
||||
));
|
||||
}
|
||||
|
||||
if(empty($userObj)){
|
||||
$result = false;
|
||||
}
|
||||
return array($result,$userObj);
|
||||
}
|
||||
|
||||
function isUserExistByVerificationToken( $profile_id, $verificationToken )
|
||||
{
|
||||
$result = true;
|
||||
$userObj = $this->find('first', array(
|
||||
'conditions' => array(
|
||||
'profile_id' => $profile_id,
|
||||
'verification_token' => $verificationToken
|
||||
)
|
||||
));
|
||||
|
||||
if(empty($userObj)){
|
||||
$result = false;
|
||||
}
|
||||
return array($result,$userObj);
|
||||
}
|
||||
|
||||
function updateFieldsById($id, $fields)
|
||||
{
|
||||
return $this->updateAll($fields,array("id" => $id));
|
||||
}
|
||||
|
||||
function isExistUserById($id){
|
||||
$result = true;
|
||||
|
||||
$userObj = $this->find('first', array('conditions' => array('id' =>$id)));
|
||||
|
||||
if(empty($userObj)){
|
||||
$result = false;
|
||||
} else {
|
||||
$userObj = $userObj['User'];
|
||||
}
|
||||
return array($result,$userObj);
|
||||
}
|
||||
|
||||
function isUserExistByProfile($profile_id, $profile_type) {
|
||||
$result = true;
|
||||
|
||||
$userObj = $this->find('first', array(
|
||||
'conditions' => array(
|
||||
'profile_id' => $profile_id,
|
||||
'profile_type' => $profile_type,
|
||||
)
|
||||
));
|
||||
|
||||
if(empty($userObj)){
|
||||
$result = false;
|
||||
} else {
|
||||
$userObj = $userObj['User'];
|
||||
}
|
||||
return array($result,$userObj);
|
||||
}
|
||||
|
||||
function findByProfileId( $profile_id ){
|
||||
|
||||
return $this->find('first', array('conditions' => array('profile_id' =>$profile_id)));
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
202
app/Model/UserGroup.php
Normal file
202
app/Model/UserGroup.php
Normal file
@@ -0,0 +1,202 @@
|
||||
<?php
|
||||
|
||||
|
||||
/**
|
||||
* @property Expense $Expense
|
||||
*/
|
||||
class UserGroup extends AppModel
|
||||
{
|
||||
var $name='UserGroup';
|
||||
|
||||
|
||||
function list($fields = array('*'),$conditions = array() )
|
||||
{
|
||||
$returnData = array();
|
||||
$userGroups = $this->find('all', array(
|
||||
'fields' => $fields,
|
||||
'conditions' => $conditions,
|
||||
));
|
||||
if(!empty($userGroups)){
|
||||
foreach ($userGroups as $userGroup){
|
||||
$returnData[] = $userGroup['UserGroup'];
|
||||
}
|
||||
}
|
||||
return $returnData;
|
||||
}
|
||||
|
||||
function listWithExpense($fields = array('*'),$conditions = array() )
|
||||
{
|
||||
$returnData = array();
|
||||
$userGroups = $this->find('all', array(
|
||||
'fields' => $fields,
|
||||
'conditions' => $conditions,
|
||||
'joins' => array(
|
||||
array(
|
||||
'table' => 'expenses',
|
||||
'alias' => 'Expense',
|
||||
'type' => 'INNER',
|
||||
'conditions' => array(
|
||||
'Expense.unique_url = UserGroup.unique_url'
|
||||
)
|
||||
)
|
||||
)
|
||||
));
|
||||
|
||||
// TODO why loop
|
||||
if(!empty($userGroups)){
|
||||
foreach ($userGroups as $userGroup){
|
||||
$temp = array_merge($userGroup['UserGroup'], $userGroup['Expense']);
|
||||
$returnData[] = $temp;
|
||||
}
|
||||
}
|
||||
return $returnData;
|
||||
}
|
||||
|
||||
public function groupListWithExpense($fields = array('*'), $conditions = array()) {
|
||||
$returnData = array();
|
||||
$startTime = microtime(true);
|
||||
|
||||
$expenseType = isset($conditions['expense_type']) ? $conditions['expense_type'] : null;
|
||||
unset($conditions['expense_type']); // unset becausse user_groups has no column expense_type
|
||||
|
||||
// Get all user groups first
|
||||
$userGroups = $this->find('all', array(
|
||||
'conditions' => $conditions
|
||||
));
|
||||
|
||||
if (empty($userGroups)) {
|
||||
return $returnData;
|
||||
}
|
||||
|
||||
// Collect all unique_url values
|
||||
$uniqueUrls = Hash::extract($userGroups, '{n}.UserGroup.unique_url');
|
||||
$uniqueUrls = array_values(array_unique(array_filter($uniqueUrls)));
|
||||
|
||||
if (empty($uniqueUrls)) {
|
||||
return $returnData;
|
||||
}
|
||||
|
||||
$this->Expense = ClassRegistry::init('Expense');
|
||||
|
||||
$expenseFields = array(
|
||||
'Expense.id',
|
||||
'Expense.unique_url',
|
||||
'Expense.title',
|
||||
'Expense.create_date'
|
||||
);
|
||||
|
||||
// 1. Query expenses table once
|
||||
$expenseConditions = array('Expense.unique_url' => $uniqueUrls);
|
||||
if ($expenseType !== null) {
|
||||
$expenseConditions['Expense.expense_type'] = $expenseType;
|
||||
}
|
||||
$expenses = $this->Expense->find('all', array(
|
||||
'fields' => $expenseFields,
|
||||
'conditions' => $expenseConditions,
|
||||
));
|
||||
|
||||
$mainExpenses = Hash::extract($expenses, '{n}.Expense');
|
||||
$returnData = array_merge($returnData, $mainExpenses);
|
||||
|
||||
// Find which unique_url values were not found
|
||||
$foundUrls = Hash::extract($expenses, '{n}.Expense.unique_url');
|
||||
$missingUrls = array_values(array_diff($uniqueUrls, $foundUrls));
|
||||
|
||||
if (empty($missingUrls)) {
|
||||
return $returnData;
|
||||
}
|
||||
|
||||
|
||||
// 2. Query backup_expenses once
|
||||
/** @var DboSource $db */
|
||||
$db = ConnectionManager::getDataSource('default');
|
||||
|
||||
$backupExpenses = $db->fetchAll(
|
||||
"SELECT id, unique_url, title, create_date
|
||||
FROM backup_expenses AS Expense
|
||||
WHERE unique_url IN (" . implode(',', array_fill(0, count($missingUrls), '?')) . ")",
|
||||
$missingUrls
|
||||
);
|
||||
|
||||
$backupData = Hash::extract($backupExpenses, '{n}.Expense');
|
||||
$returnData = array_merge($returnData, $backupData);
|
||||
|
||||
$foundBackupUrls = Hash::extract($backupExpenses, '{n}.Expense.unique_url');
|
||||
$missingUrls = array_values(array_diff($missingUrls, $foundBackupUrls));
|
||||
|
||||
if (empty($missingUrls)) {
|
||||
return $returnData;
|
||||
}
|
||||
|
||||
3. Query archive expenses once
|
||||
try {
|
||||
/** @var DboSource $archiveDb */
|
||||
$archiveDb = ConnectionManager::getDataSource('archieve'); // TODO
|
||||
|
||||
$archiveExpenses = $archiveDb->fetchAll(
|
||||
"SELECT id, unique_url, title, create_date
|
||||
FROM expenses AS Expense
|
||||
WHERE unique_url IN (" . implode(',', array_fill(0, count($missingUrls), '?')) . ")",
|
||||
$missingUrls
|
||||
);
|
||||
|
||||
$archiveData = Hash::extract($archiveExpenses, '{n}.Expense');
|
||||
$returnData = array_merge($returnData, $archiveData);
|
||||
} catch (MissingConnectionException $ex) {
|
||||
// Archive DB unavailable (e.g. local dev), skip silently
|
||||
}
|
||||
|
||||
return $returnData;
|
||||
}
|
||||
|
||||
function isExistUserGroup(int $user_id, string $unique_url)
|
||||
{
|
||||
$result = false;
|
||||
$userGroups = $this->find('first', array(
|
||||
'conditions' => array(
|
||||
'user_id' => $user_id,
|
||||
'unique_url' => $unique_url,
|
||||
),
|
||||
));
|
||||
if(!empty($userGroups)){
|
||||
$result = true;
|
||||
$userGroups = $userGroups['UserGroup'];
|
||||
}
|
||||
return array($result,$userGroups);
|
||||
}
|
||||
|
||||
function add($inputData)
|
||||
{
|
||||
$result = false;
|
||||
|
||||
if(!empty($inputData))
|
||||
{
|
||||
$fileds = array();
|
||||
$dbData["UserGroup"] = $inputData;
|
||||
if($this->save($dbData,false,$fileds)){
|
||||
$dbData["UserGroup"]['id'] = $this->id;
|
||||
$result = true;
|
||||
}
|
||||
}
|
||||
return array($result,$dbData["UserGroup"]);
|
||||
}
|
||||
|
||||
function deleteUG($deleteConditions)
|
||||
{
|
||||
return $this->deleteAll(
|
||||
array($deleteConditions)
|
||||
);
|
||||
}
|
||||
|
||||
function updateUG($updateFields,$updateConditions)
|
||||
{
|
||||
$result = false;
|
||||
if(!empty($updateFields) && !empty($updateConditions))
|
||||
{
|
||||
if($this->updateAll($updateFields, $updateConditions)){
|
||||
$result = true;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
32
app/Model/Wallet.php
Normal file
32
app/Model/Wallet.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
class Wallet extends AppModel
|
||||
{
|
||||
var $name='Wallet';
|
||||
|
||||
|
||||
|
||||
function list($conditions = array() )
|
||||
{
|
||||
return $this->find('all', array('conditions' => $conditions));
|
||||
}
|
||||
|
||||
function add($inputData)
|
||||
{
|
||||
$result = false;
|
||||
|
||||
if(!empty($inputData))
|
||||
{
|
||||
$fileds = array();
|
||||
$dbData["Wallet"] = $inputData;
|
||||
if($this->save($dbData,false,$fileds)){
|
||||
$dbData["Wallet"]['id'] = $this->id;
|
||||
$result = true;
|
||||
}
|
||||
}
|
||||
return array($result,$dbData["Wallet"]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user