.
501 Sales Diary Apps
Building On Codepen Platform
Continue from the previous tutorial, http://basic-steps.blogspot.my/2017/01/403-create-ionic-inventory-category-apps.html
HTML
<html>
<head>
<meta charset="utf-8">
<title>Diary</title>
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<!-- Internal Library
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<script src="lib/ionic/js/ionic.bundle.js"></script>
-->
<!-- Cloud Library -->
<link href="//code.ionicframework.com/nightly/css/ionic.css" rel="stylesheet">
<script src="//code.ionicframework.com/nightly/js/ionic.bundle.js"></script>
<!-- Needed for Cordova/PhoneGap (will be a 404 during development) -->
<script src="cordova.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/datejs/1.0/date.min.js"></script>
</head>
<body ng-app="app">
<div>
<div>
<ion-nav-bar class="bar-stable">
<ion-nav-back-button></ion-nav-back-button>
</ion-nav-bar>
<ion-nav-view></ion-nav-view>
</div>
</div>
<script id="home.html" type="text/ng-template">
<ion-view title="My Sales Diary" id="page1" style="font-weight:bold">
<ion-nav-buttons side="right" class="has-header">
<button class="button button-icon" ui-sref="menu.details({param2:'1'})">
<i class="icon ion-compose"></i>
</button>
</ion-nav-buttons>
<ion-content padding="true" class="has-header">
<center>
<i class="icon icon ion-cash" style="font-size:150px;color:lightgreen;"></i>
</center>
<div class="mytodaybar" ui-sref="menu.details">
Sales Today
</div>
<br/> Cost Today
<div class="mycostbar" ui-sref="menu.details">
<div class="row">
<div class="col">Target Cost Per Day</div>
<div class="col">Total Cost</div>
<div class="col">Cost Variance</div>
</div>
<div class="row">
<div class="col">
<h1>0000</h1>
</div>
<div class="col">
<h1>0000</h1>
</div>
<div class="col">
<h1>0000</h1>
</div>
</div>
</div>
<br/> Sales Today
<div class="mybillbar" ui-sref="menu.details">
<div class="row">
<div class="col"><b>Target Sales Per Day</b></div>
<div class="col"><b>Total Sales</b></div>
<div class="col"><b>Sales Variance</b></div>
</div>
<div class="row">
<div class="col">
<h1>0000</h1>
</div>
<div class="col">
<h1>0000</h1>
</div>
<div class="col">
<h1>0000</h1>
</div>
</div>
</div>
</ion-content>
</ion-view>
</script>
<script id="menu.html" type="text/ng-template">
<ion-side-menus enable-menu-with-back-views="false">
<ion-side-menu-content>
<ion-nav-bar class="bar-balanced">
<ion-nav-back-button></ion-nav-back-button>
<ion-nav-buttons side="left">
<button class="button button-icon button-clear ion-navicon" menu-toggle="left"></button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-nav-view name="side-menu21"></ion-nav-view>
</ion-side-menu-content>
<ion-side-menu side="left" id="side-menu21">
<ion-header-bar class="bar-balanced">
<div class="title">Menu</div>
</ion-header-bar>
<ion-content padding="false" class="side-menu-left has-header ">
<ion-list id="menu-list1">
<div class="item item-avatar">
<img src="https://gravatar.com/avatar/aa72bcbdc4d283758c2f9553e9fafdba?s=80&d=https://codepen.io/assets/avatars/user-avatar-80x80-bdcd44a3bfb9a5fd01eb8b86f9e033fa1a9897c3a15b33adfc2649a002dab1b6.png">
<h2>My Sales Diary</h2>
<p>keep moving!</p>
</div>
<ion-item class="item-icon-left item" id="menu-list-item1" ui-sref="menu.home" menu-close="">
<i class="icon ion-home"></i>Home
</ion-item>
<ion-item class="item-icon-left item" id="menu-list-item2" ui-sref="menu.monthly" menu-close="">
<i class="icon ion-stats-bars"></i>Diary
</ion-item>
<ion-item class="item-icon-left item" id="menu-list-item3" ui-sref="menu.settings" menu-close="">
<i class="icon ion-wrench"></i>Settings
</ion-item>
</ion-content>
</ion-side-menu>
</ion-side-menus>
</script>
<script id="monthly.html" type="text/ng-template">
<ion-view title="Monthly" id="page2">
<ion-content padding="true" class="has-header">
<h2>MONTHLY SUMMARY</h2>
<div class="row">
<div class="col"><b>Year-Month</b></div>
<div class="col"><b>Costs</b></div>
<div class="col"><b>Sales</b></div>
<div class="col-10"></div>
</div>
<div class="row" ng-class-odd="'odd'" ng-class-even="'even'" ng-repeat="item in listSummaryRecords|orderBy:'-yearmonth'" ui-sref="menu.daily({
param1:{{listSummaryIndex}},
param2:{{item.yearmonth|json}}})">
<div class="col">{{item.yearmonth}}</div>
<div class="col">{{item.cost}}</div>
<div class="col">{{item.sale}}</div>
<div class="col-10" style="padding:5px;">
<i class="icon ion-chevron-right"></i>
</div>
</div>
</ion-content>
</ion-view>
</script>
<script id="daily.html" type="text/ng-template">
<ion-view title="Daily" id="page3">
<ion-content padding="true" class="has-header">
<label class="item item-input item-select">
<div class = "input-label">
Year-Month
</div>
<select ng-model="entry.yearmonth"
ng-options="yearmonth for yearmonth in yearmonths"
ng-init="entry.yearmonth=selectedyearmonth"
ng-change="refreshView()">
</select>
</label>
<h2>DAILY SUMMARY</h2>
<div class="row">
<div class="col"><b>Date</b></div>
<div class="col"><b>Costs</b></div>
<div class="col"><b>Sales</b></div>
<div class="col-10"></div>
</div>
<div class="row" ng-class-odd="'odd'" ng-class-even="'even'" ng-repeat="item in listSummaryRecords|orderBy:'-date'" ui-sref="menu.details({param1:{{item.date}}})">
<div class="col">{{item.date| date:'dd'}}</div>
<div class="col">{{item.cost}}</div>
<div class="col">{{item.sale}}</div>
<div class="col-10" style="padding:5px;">
<i class="icon ion-chevron-right"></i>
</div>
</div>
</ion-content>
</ion-view>
</script>
<script id="details.html" type="text/ng-template">
<ion-view title="Details" id="page4">
<ion-nav-buttons side="right" class="has-header">
<button class="button button-icon" ng-click="selectCategory()">
<i class="icon ion-compose"></i>
</button>
</ion-nav-buttons>
<ion-content padding="true" class="has-header">
<label class="item item-input">
<span class="input-label">Date</span>
<input type="date"
ng-model="entry.searchDate"
ng-change="refreshView()">
</label>
<h2>DETAILS</h2>
<div class="row">
<div class="col"><b>Date</b></div>
<div class="col"><b>Desc</b></div>
<div class="col"><b>Costs</b></div>
<div class="col"><b>Sales</b></div>
<div class="col-10"></div>
</div>
<div class="row" ng-class-odd="'odd'" ng-class-even="'even'" ng-repeat="detail in details |orderBy:'-date'">
<div class="col">{{detail.date| date:'dd'}}</div>
<div class="col">{{detail.desc}}</div>
<div class="col">{{detail.cost}}</div>
<div class="col">{{detail.sale}}</div>
<div class="col-10" style="padding:5px;">
<i class="icon ion-chevron-right"></i>
</div>
</div>
</ion-content>
</ion-view>
</script>
<script id="insertRecord.html" type="text/ng-template">
<div class="modal">
<!-- Modal header bar -->
<ion-header-bar class="bar-secondary">
<h1 class="title">Insert Record</h1>
<button class="button button-clear button-positive" ng-click="closeInsertRecord()">Cancel</button>
</ion-header-bar>
<!-- Modal content area -->
<ion-content>
<form ng-submit="submitInsertRecord(entry)">
<div class="list">
<label class="item item-input">
<input type="date" placeholder="Transaction Date" ng-model="entry.date">
</label>
<label class="item item-input">
<input type="text" placeholder="Transaction Desc" ng-model="entry.desc">
</label>
<label class="item item-input">
<input type="text" placeholder="Transaction Cost" ng-model="entry.cost">
</label>
<label class="item item-input">
<input type="text" placeholder="Transaction Sale" ng-model="entry.sale">
</label>
</div>
<div class="padding">
<button type="submit" class="button button-block button-positive">Insert Record</button>
</div>
</form>
</ion-content>
</div>
</script>
<script id="selectCategory.html" type="text/ng-template">
<div class="modal">
<!-- Modal header bar -->
<ion-header-bar class="bar-secondary">
<h1 class="title">Select Category</h1>
<button class="button button-clear button-positive" ng-click="closeSelectCategory()">Cancel</button>
</ion-header-bar>
<!-- Modal content area -->
<ion-content>
<form ng-submit="submitCategory(entry)">
<div class="button-bar">
<a class="button button-positive" ng-click="getCategoryItems(1)">Cat 1</a>
<a class="button button-assertive" ng-click="getCategoryItems(2)">Cat 2</a>
<a class="button button-energized" ng-click="getCategoryItems(3)">Cat 3</a>
<a class="button" ng-click="getCategoryItems(4)">Cat 4</a>
</div>
<ion-list>
<ion-item ng-repeat="item in CategoryItems" ng-click="submitCategory(item)">
{{item.desc}}::{{item.cost}}::{{item.sale}}
</ion-item>
</ion-list>
<div class="padding">
</div>
</form>
</ion-content>
</div>
</script>
<script id="settings.html" type="text/ng-template">
<ion-view title="Settings" id="page5">
<ion-content padding="true" class="has-header">
<h2>SETTINGS</h2>
</ion-content>
</ion-view>
</script>
</body>
</html>
|
JS
angular.module('app', ['ionic'])
.factory('DataTree', function() {
return {
all: function(trunkName) {
var trunkString = window.localStorage[trunkName];
if (trunkString) {
return angular.fromJson(trunkString);
}
return [];
},
save: function(trunkName, trunkString) {
//console.log(trunkString);
window.localStorage[trunkName] = angular.toJson(trunkString);
}
}
})
.controller('homeCtrl', ['$scope', '$stateParams', '$ionicModal', 'DataTree',
function($scope, $stateParams, $ionicModal, DataTree) {}
])
.controller('menuCtrl', ['$scope', '$stateParams',
function($scope, $stateParams) {}
])
.controller('monthlyCtrl', ['$scope', '$stateParams', 'DataTree',
function($scope, $stateParams, DataTree) {
var titleSource = "inventoryRecordBookDetails";
var listRecords = [];
var listSummaryIndex = [];
var listSummaryRecords = [];
function summarizeMonthly() {
listRecords = DataTree.all(titleSource);
// init lists
listSummaryIndex = [];
listSummaryRecords = [];
// process listDetailRecords
listRecords.forEach(function(d) {
//console.log(d);
d.date = new Date(d.date);
yearmonthvalue = d.date.toISOString().substring(0, 7);
var obj = {
yearmonth: yearmonthvalue,
desc: d.desc,
cost: d.cost,
sale: d.sale
};
//assign arrayData item to lists
var i = listSummaryIndex.indexOf(yearmonthvalue);
if (i < 0) {
listSummaryIndex.push(yearmonthvalue);
listSummaryRecords.push(obj);
} else {
listSummaryRecords[i].cost =
parseFloat(listSummaryRecords[i].cost) +
parseFloat(obj.cost);
listSummaryRecords[i].sale =
parseFloat(listSummaryRecords[i].sale) +
parseFloat(obj.sale);
}
//console.log(listSummaryIndex);
//console.log(listSummaryRecords);
});
//console.log(listSummaryRecords);
}
function refreshView() {
summarizeMonthly();
$scope.listSummaryIndex = listSummaryIndex;
$scope.listSummaryRecords = listSummaryRecords;
}
$scope.$on('$ionicView.enter', function() {
refreshView();
});
}
])
.controller('dailyCtrl', ['$scope', '$stateParams', '$ionicModal', 'DataTree',
function($scope, $stateParams, $ionicModal, DataTree) {
$scope.entry = {};
$scope.yearmonths = $stateParams.param1;
$scope.selectedyearmonth = $stateParams.param2;
var titleSource = "inventoryRecordBookDetails";
var listRecords = [];
var listSummaryIndex = [];
var listSummaryRecords = [];
function summarizeDaily() {
listRecords = DataTree.all(titleSource);
// init lists
listSummaryIndex = [];
listSummaryRecords = [];
// process listRecords
listRecords.forEach(function(d) {
//console.log(d);
d.date = new Date(d.date);
e = d.date;
e = e.getTime();
yearmonthvalue = d.date.toISOString().substring(0, 7);
var obj = {
yearmonth: yearmonthvalue,
date: e,
cost: d.cost,
sale: d.sale
};
//assign arrayData item to lists
if (yearmonthvalue == $scope.entry.yearmonth) {
//console.log(obj.date);
//console.log(listSummaryIndex);
var i = listSummaryIndex.indexOf(obj.date);
//console.log(i);
if (i < 0) {
listSummaryIndex.push(obj.date);
listSummaryRecords.push(obj);
} else {
listSummaryRecords[i].cost =
parseFloat(listSummaryRecords[i].cost) +
parseFloat(obj.cost);
listSummaryRecords[i].sale =
parseFloat(listSummaryRecords[i].sale) +
parseFloat(obj.sale);
}
}
//console.log(listSummaryIndex);
//console.log(listSummaryRecords);
});
//console.log(listSummaryRecords);
}
$scope.refreshView = function() {
summarizeDaily();
$scope.listSummaryRecords = listSummaryRecords;
}
$scope.$on('$ionicView.enter', function() {
$scope.refreshView();
});
}
])
.controller('detailsCtrl', ['$scope', '$stateParams', '$ionicModal', '$ionicPopup', 'DataTree',
function($scope, $stateParams, $ionicModal, $ionicPopup, DataTree) {
$scope.entry = {};
var titleDetails = "inventoryRecordBookDetails";
var sourceDetails = DataTree.all(titleDetails);
// Create and load the Modal
$ionicModal.fromTemplateUrl('insertRecord.html', function(modal) {
$scope.insertRecordModal = modal;
}, {
scope: $scope,
animation: 'slide-in-up'
});
// Called when the form is submitted
$scope.submitInsertRecord = function(entry) {
//convert the date into UTC Date
//to avoid time zone differences
var d = new Date(entry.date);
var utcDate = new Date(Date.UTC(
d.getFullYear(),
d.getMonth(),
d.getDate(), 0, 0, 0));
// add new item to data source
sourceDetails.push({
date: utcDate,
desc: entry.desc,
cost: entry.cost,
sale: entry.sale
});
//sort data source by date in ascending order
sourceDetails.sort(function(a, b) {
return new Date(a.date).getTime() -
new Date(b.date).getTime()
});
//save data source into storage
DataTree.save(titleDetails, sourceDetails);
$scope.Details = sourceDetails;
//if search date entry exists
//perform searchDate()
$scope.entry.searchDate = $scope.entry.date;
$scope.refreshView();
//reset entry value
$scope.entry.desc = null;
$scope.entry.cost = null;
$scope.entry.sale = null;
$scope.insertRecordModal.hide();
};
// Open our new task modal
$scope.insertRecord = function(item) {
//if searchDate is not null get its value
//else, get current date value
if ($scope.entry.searchDate == null) {
$scope.entry.date = new Date();
} else {
$scope.entry.date = $scope.entry.searchDate;
}
$scope.entry.desc = item.desc;
$scope.entry.cost = item.cost;
$scope.entry.sale = item.sale;
$scope.insertRecordModal.show();
};
// Close the new task modal
$scope.closeInsertRecord = function() {
$scope.insertRecordModal.hide();
};
// Create and load the Modal
$ionicModal.fromTemplateUrl('selectCategory.html', function(modal) {
$scope.selectCategoryModal = modal;
}, {
scope: $scope,
animation: 'slide-in-up'
});
// Called when the form is submitted
$scope.submitCategory = function(entry) {
$scope.CategoryItems = [];
$scope.selectCategoryModal.hide();
$scope.insertRecord(entry);
}
// Open our new Category Selection modal
$scope.selectCategory = function() {
$scope.selectCategoryModal.show();
};
// Close the new task modal
$scope.closeSelectCategory = function() {
$scope.CategoryItems = [];
$scope.selectCategoryModal.hide();
};
$scope.getCategoryItems = function(category) {
$scope.CategoryItems = [{
desc: 'Cat ' + category + ' Item 1',
cost: 10 * category,
sale: 20 * category
},
{
desc: 'Cat ' + category + ' Item 2',
cost: 10 * category,
sale: 20 * category
},
{
desc: 'Cat ' + category + ' Item 3',
cost: 10 * category,
sale: 20 * category
}
]
}
$scope.refreshView = function() {
//if input is null
if ($scope.entry.searchDate == null) {
$scope.details = [];
return;
} else { //if input is not null
var d = new Date($scope.entry.searchDate);
var testDate = new Date(Date.UTC(
d.getFullYear(),
d.getMonth(),
d.getDate(), 0, 0, 0));
var obj = sourceDetails.filter(function(obj) {
var sourceDate = new Date(obj.date);
//console.log(sourceDate.getTime()+"="+utcDate.getTime());
return (sourceDate.getTime() === testDate.getTime());
//return obj.date === $scope.detailsPage.inputDate;
});
//console.log(obj);
$scope.details = obj;
}
}
$scope.$on('$ionicView.enter', function() {
$scope.entry.searchDate = (
$stateParams.param1 == null ?
new Date() : new Date($stateParams.param1));
if ($stateParams.param2 == '1') {
$scope.selectCategory();
}
$scope.refreshView();
});
}
])
.controller('settingsCtrl', ['$scope', '$stateParams',
function($scope, $stateParams) {}
])
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('menu.home', {
url: '/page1',
views: {
'side-menu21': {
templateUrl: 'home.html',
controller: 'homeCtrl'
}
}
})
.state('menu', {
url: '/side-menu21',
templateUrl: 'menu.html',
controller: 'menuCtrl'
})
.state('menu.monthly', {
url: '/page2',
views: {
'side-menu21': {
templateUrl: 'monthly.html',
controller: 'monthlyCtrl'
}
}
})
.state('menu.daily', {
url: '/page3',
params: {
param1: null,
param2: null
},
views: {
'side-menu21': {
templateUrl: 'daily.html',
controller: 'dailyCtrl'
}
}
})
.state('menu.details', {
url: '/page4',
params: {
param1: null,
param2: null
},
views: {
'side-menu21': {
templateUrl: 'details.html',
controller: 'detailsCtrl'
}
}
})
.state('menu.settings', {
url: '/page5',
views: {
'side-menu21': {
templateUrl: 'settings.html',
controller: 'settingsCtrl'
}
}
})
$urlRouterProvider.otherwise('/side-menu21/page1')
});
|
No comments:
Post a Comment