1 angular.module('pdm') 2 .controller('Ctrl_DailyKeeper', 3 ['$scope', '$ionicModal', '$db', '$cordovaToast', '$ionicPopup', '$alertPopup' 4 , function ($scope, $ionicModal, $db, $cordovaToast, $ionicPopup, $alertPopup) { $scope.getKA = function (callback, cndt) { 8 var sql = "SELECT * FROM Finacial_KeepAccount WHERE 1=1 "; 9 if (cndt != undefined && cndt != '')sql += (' AND ' + cndt); 10 sql += ' ORDER BY RecordDate desc'; 11 $db._exec(sql, [], function (rst) { 12 if (rst.rows.length == 0) { 13 if(!g_debug) 14 $cordovaToast.showShortCenter('load ka success but no data'); } 17 var data = []; 18 for (var i = 0; i < rst.rows.length; i++) data.push(rst.rows.item(i)); 19 callback(data); 20 }); 21 }; 22 $scope.addKA = function (SuitType, ItemText, MoneyFlowDirect, Cash, AccountType, RecordDate, Remark) { 23 $db.add('Finacial_KeepAccount' 24 , 'SuitType,ItemText,MoneyFlowDirect,Cash,AccountType,RecordDate,Remark, account' 25 , [SuitType, ItemText, MoneyFlowDirect, Cash, AccountType, RecordDate, Remark, g_user]); 26 }; 27 $scope.updateKA = function (id, SuitType, ItemText, MoneyFlowDirect, Cash, AccountType, RecordDate, Remark) { 28 $db.update('Finacial_KeepAccount' 29 , 'SuitType,ItemText,MoneyFlowDirect,Cash,AccountType,RecordDate,Remark' 30 , [SuitType, ItemText, MoneyFlowDirect, Cash, AccountType, RecordDate, Remark] 31 , 'id=' + id.toString()); 32 }; 33 $scope.deleteKA = function (id) { 34 $db.delete('Finacial_KeepAccount', 'id=' + id.toString()); 35 }; $scope.Finacial_SuitClass = [ 39 {MainClass: '基本生活', SuitType: '餐饮饮食'} 40 , {MainClass: '基本生活', SuitType: '柴米油盐'} 41 , {MainClass: '美容化妆', SuitType: '服饰装扮'} 42 , {MainClass: '收入', SuitType: '福利津贴'} 43 , {MainClass: '收入', SuitType: '工资'} 44 , {MainClass: '美容化妆', SuitType: '化妆品美容'} 45 , {MainClass: '交通通讯', SuitType: '话费网费'} 46 , {MainClass: '交通通讯', SuitType: '交通费'} 47 , {MainClass: '人情往来', SuitType: '借出'} 48 , {MainClass: '投资', SuitType: '理财投资'} 49 , {MainClass: '文化娱乐', SuitType: '旅游娱乐'} 50 , {MainClass: '收入', SuitType: '其他收入'} 51 , {MainClass: '其他支出', SuitType: '其他支出'} 52 , {MainClass: '人情往来', SuitType: '人际往来'} 53 , {MainClass: '基本生活', SuitType: '日常用品'} 54 , {MainClass: '文化娱乐', SuitType: '书报音像'} 55 , {MainClass: '文化娱乐', SuitType: '数码产品'} 56 , {MainClass: '基本生活', SuitType: '水果零食'} 57 , {MainClass: '基本生活', SuitType: '物业水电'} 58 , {MainClass: '人情往来', SuitType: '孝敬长辈'} 59 , {MainClass: '基本生活', SuitType: '医药保健'} 60 , {MainClass: '文化娱乐', SuitType: '运动健身'} 61 ]; 62 $scope.currDA = { 63 title: '新增' 64 , id: 0 65 , RecordDate: new Date() 66 , SuitType: '' 67 , ItemText: '' 68 , Cash: 0 69 , Income: false 70 , Remark: '' 71 } 72 73 $scope.arrageData = function () { 74 var _data = $scope.dailyAccount; (_data.length > 0) { 77 _data[0].ext_displayDivider = ''; (_data.length > 1) { 80 var lastDA = _data[0]; 81 for (var i = 1; i < _data.length; i++) { 82 _data[i].ext_displayDivider = 'none'; 83 if (new Date(_data[i].RecordDate) < new Date(lastDA.RecordDate)) { 84 _data[i].ext_displayDivider = ''; 85 lastDA = _data[i]; 86 } 87 } 88 } 89 } 90 }; 91 92 $scope.remove = function (da) { 93 $ionicPopup.confirm({ 94 title: 'Confrim', 95 template: 'Do you really want to delete?', 96 scope: $scope, 97 buttons: [ 98 { 99 text: '<b>Yes</b>', 100 type: 'button-positive', 101 onTap: function (e) { $scope.deleteKA(da.id); 104 $scope.loadDate(); 105 } 106 }, 107 { 108 type: 'button-canceldark', 109 text: '<b>Cancel</b>', 110 onTap: function (e) { 111 console.log('cancel delete'); 112 } 113 } 114 ] 115 }); 116 }; 117 118 $scope.showDetail = function (da) { 119 if (da == undefined) { $scope.currDA.title = '新增'; 122 123 $scope.currDA.id = 0; 124 $scope.currDA.RecordDate = new Date(); 125 $scope.currDA.SuitType = ''; 126 $scope.currDA.ItemText = ''; 127 $scope.currDA.Cash = 0; 128 $scope.currDA.Income = false; 129 $scope.currDA.Remark = ''; 130 } else { $scope.currDA.title = '编辑'; 133 134 $scope.getKA(function (data) { 135 if (data.length > 0) { 136 var item = data[0]; 137 138 $scope.currDA.id = item.id; 139 $scope.currDA.RecordDate = new Date(item.RecordDate); 140 $scope.currDA.SuitType = item.SuitType; 141 $scope.currDA.ItemText = item.ItemText; 142 $scope.currDA.Cash = item.Cash; 143 $scope.currDA.Income = (item.MoneyFlowDirect == '入账'); 144 $scope.currDA.Remark = item.Remark; 145 } 146 } 147 , ' id = ' + da.id); 148 } 149 150 $scope.openModal(); 151 } 152 153 $scope.save = function () { ($scope.currDA.SuitType == '' 157 || $scope.currDA.SuitType.indexOf('账目类型') >= 0) { 158 $alertPopup('账目类型没有选定哦'); 159 return; 160 } _moneyFlowDirection = '出账'; 163 if ($scope.currDA.Income) _moneyFlowDirection = '入账'; ($scope.currDA.id == 0) { $scope.addKA( 168 $scope.currDA.SuitType 169 , $scope.currDA.ItemText 170 , _moneyFlowDirection 171 , $scope.currDA.Cash 172 , '我的钱包' 173 , dateFormat($scope.currDA.RecordDate, 'ymd') 174 , $scope.currDA.Remark 175 ); 176 $scope.closeDetail(); 177 $scope.loadDate(); 178 } 179 else { $ionicPopup.confirm({ 182 title: 'Confrim', 183 template: 'Do you really want to update?', 184 scope: $scope, 185 buttons: [ 186 { 187 text: '<b>Yes</b>', 188 type: 'button-positive', 189 onTap: function (e) { 190 $scope.updateKA( 191 $scope.currDA.id 192 , $scope.currDA.SuitType 193 , $scope.currDA.ItemText 194 , _moneyFlowDirection 195 , $scope.currDA.Cash 196 , '我的钱包' 197 , dateFormat($scope.currDA.RecordDate, 'ymd') 198 , $scope.currDA.Remark 199 ); 200 $scope.closeDetail(); 201 $scope.loadDate(); 202 } 203 }, 204 { 205 type: 'button-canceldark', 206 text: '<b>Cancel</b>', 207 onTap: function (e) { 208 console.log('cancel update'); 209 } 210 } 211 ] 212 }); 213 } 214 } $ionicModal.fromTemplateUrl('detail.html', { 218 scope: $scope, 219 animation: 'slide-in-up' 220 }).then(function (modal) { 221 $scope.modal = modal; 222 }); 223 $scope.openModal = function () { 224 $scope.modal.show(); 225 }; 226 $scope.closeDetail = function () { 227 $scope.modal.hide(); 228 } 229 $scope.$on('$destroy', function () { 230 $scope.modal.remove(); 231 }); 232 233 $scope.loadDate = function () { 234 $scope.getKA(function (data) { 235 for (var i = 0; i < data.length; i++) { 236 var _d = data[i]; 237 _d['ext_displayDivider'] = 'none'; 238 _d['ext_TextColor'] = 'black'; 239 if (_d.MoneyFlowDirect == '入账')_d['ext_TextColor'] = 'blue'; 240 } 241 $scope.dailyAccount = data; 242 $scope.arrageData(); 243 }); 244 } $scope.loadDate(); 248 249 }]) 250 ;
View Code