Skip to content

Commit

Permalink
inventory is now saving
Browse files Browse the repository at this point in the history
  • Loading branch information
dvbondoy committed Dec 29, 2016
1 parent ee7cbc3 commit 58e5df3
Show file tree
Hide file tree
Showing 12 changed files with 305 additions and 103 deletions.
7 changes: 7 additions & 0 deletions www/blocks/shared/shared.module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(function() {
'use strict';

angular.module('blocks.shared', [

]);
})();
23 changes: 23 additions & 0 deletions www/blocks/shared/shared.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
(function() {
'use strict';

angular
.module('blocks.shared')
.service('SharedProperties', SharedProperties);

// SharedProperties.$inject = ['dependency1'];
function SharedProperties() {
var property = {
isInventory:false
};

return {
getProperty:function(){
return property;
},
setProperty:function(value){
property = value;
}
};
}
})();
3 changes: 3 additions & 0 deletions www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
<script src="blocks/router/router.module.js"></script>
<script src="blocks/router/router.helperProvider.js"></script>

<script src="blocks/shared/shared.module.js"></script>
<script src="blocks/shared/shared.service.js"></script>

<script src="core/core.module.js"></script>
<script src="core/core.config.js"></script>

Expand Down
134 changes: 126 additions & 8 deletions www/sales/sales.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
.controller('SalesController', SalesController)
.controller('SalesCtrl', SalesCtrl);

SalesCtrl.$inject = ['$scope', '$ionicActionSheet', '$ionicModal', '$ionicLoading','$q'];
function SalesCtrl($scope,$ionicActionSheet,$ionicModal,$ionicLoading,$q) {
SalesCtrl.$inject = ['$scope', '$ionicActionSheet', '$ionicModal', '$ionicLoading','$q','SharedProperties'];
function SalesCtrl($scope,$ionicActionSheet,$ionicModal,$ionicLoading,$q,SharedProperties) {
var vm = this;
// VIEW MODEL VARIABLES======================================================
vm.ITEMS = [];
Expand All @@ -21,6 +21,7 @@
vm.quantity = 1; //order quantity
vm.amount = 0; // payment amount
vm.customer = {name:'Walk-In'};
vm.isInventory = false; //flag for creating an inventory
vm.order = { //will store orders
items:[],
customer:{},
Expand All @@ -43,11 +44,12 @@
days:0
}
};


// LOCAL VARIABLES===========================================================
var activePCategory;

// console.log(SharedProperties.getProperty());

// MODAL VIEWS HERE =============================================
$ionicModal.fromTemplateUrl('sales/templates/items-modal.html',{
scope:$scope,
Expand All @@ -56,6 +58,13 @@
$scope.itemsModal = modal;
});

$ionicModal.fromTemplateUrl('sales/templates/customer-modal.html',{
scope:$scope,
animation:'slide-in-up'
}).then(function(modal){
$scope.customerModal = modal;
});

$ionicModal.fromTemplateUrl('sales/templates/payment-details-modal.html',{
scope:$scope,
animation:'slide-in-up'
Expand Down Expand Up @@ -114,6 +123,35 @@
getParentCategories();
}

$scope.chooseFilter = function() {
// console.log(SharedProperties.getProperty());
var menu = [
{
text: 'Categories'
},
{
text: 'All Items'
},
{
text: 'Discounts'
}
];

var hideSheet = $ionicActionSheet.show({
buttons: menu,
cancelText: 'Cancel',
cancel: function() {

},
buttonClicked: function(index) {
vm.filterText = menu[index].text;
// vm.items = getItems();
return true;
}
});
}


// ORDERS HERE =================================================
$scope.addItemOrder = function(item) {
var hasItem = false;
Expand Down Expand Up @@ -173,6 +211,7 @@
console.log(vm.order.total);
}

// PROCESS PAYMENTS ==============================================================
$scope.addPayment = function() {
var menu = [
{text:'Cash'},{text:'Terms'},{text:'Check'}
Expand Down Expand Up @@ -202,11 +241,6 @@
return true;
}
});

}

$scope.checkOut = function() {

}

$scope.keyPressed = function(keyCode) {
Expand Down Expand Up @@ -246,6 +280,90 @@
// console.log(vm.amount);
}

// FINISH SALE AND SAVE TO DATABSE =================================================
$scope.checkOut = function() {
var now = moment();
var payment = totalPayment();
var sale = vm.order;
var id; //sales representative id

// get our current user
$q.when(_db.get('_local/userId').then(function(data){
console.log(data);
id = data.userId;
}).catch(function(error){
console.log(error);
}));

sale._id = "sales_"+now;
sale.date = now;
sale.userId = id;
sale.doc_type = 'sales';

if(payment < vm.order.total) {
alert('Insufficient Payment');
} else {
$q.when(_db.put(sale).then(function(result){
console.log(result);
}).catch(function(error){
console.log(error);
}));
//reset some Vars
vm.order.items = [];
vm.order.total = 0;
vm.payment = {cash:{},terms:{},check:[]};
vm.customer.company = 'Walk-In';
vm.amount = 0;
}

if(payment > vm.order.total) {
var change = payment - vm.order.subtotal;
alert("CHANGE: Php " + change);
}
}

function totalPayment() {
var amount = 0;
// get cash
amount += vm.payment.cash.amount;
// get terms
amount += vm.payment.terms.amount;
// get check
for(var i = 0; i < vm.payment.check.length; i++) {
amount += vm.payment.check[i].amount;
}

return amount;
}

// INVENTORY
$scope.newInventory = function(){
$q.when(_db.query('inventory_ddoc/active',{key:'active'},function(error,result){
if(result.rows.length > 0) {
alert('You have an active inventory. Close it first.');
} else {
vm.isInventory = true;
}
}));
}

$scope.saveInventory = function() {
var inventory = vm.order;
var now = moment();

inventory._id = 'inventory_'+now;
inventory.doc_type = 'inventory';
inventory.status = 'active';
inventory.date = now;

$q.when(_db.put(inventory).catch(function(error){
console.log(error);
}).then(function(result){
console.log(result);
}));

}

}

SalesController.$inject = ['$scope', 'Category', '$ionicActionSheet', 'Items', '$ionicModal', 'Customer', 'Sales', 'Discounts', 'moment'];
Expand Down
2 changes: 1 addition & 1 deletion www/sales/sales.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
'use strict';

angular.module('app.sales', [

'blocks.shared'
]);
})();
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ <h1 class="title">Select Customer</h1>

<div class="padding">
<ion-list>
<ion-item ng-repeat="customer in vm.customers | filter : search" ng-click="vm.customer = customer;customerModal.hide()">
<ion-item ng-click="newInventory();customerModal.hide()">
<span class="bold">INVENTORY</span>
</ion-item>
<ion-item ng-repeat="customer in vm.customers | filter : search" ng-click="vm.customer = customer;customerModal.hide();vm.isInventory=false">
<div>
<h1 class="gray">{{customer.company}}</h1>
<span>{{customer.contact_name}}</span>
Expand Down
7 changes: 4 additions & 3 deletions www/sales/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
<!-- View order button-->
<ion-nav-buttons side="right">
<button class="button button-icon button-clear ion-person-add" ng-click="customerModal.show()"></button>
<button class="button button-icon button-clear ion-android-done-all" ng-click="saveSale()" ng-disabled="vm.order.items.length == 0"></button>
<button class="button button-icon button-clear ion-android-done-all ng-hide" ng-hide="vm.isInventory" ng-click="checkOut()" ng-disabled="vm.order.items.length == 0"></button>
<button class="button button-icon button-clear ion-android-archive" ng-if="vm.isInventory == true" ng-click="saveInventory()"></button>
</ion-nav-buttons>

</ion-nav-bar>
Expand Down Expand Up @@ -87,7 +88,7 @@
</div>

<ion-list>
<ion-item class="item-icon-left pos-item" ng-repeat="category in vm.CATEGORIES" ng-if="vm.filterText == 'Categories'" ng-click="getCategories(category)">
<ion-item class="item-icon-left pos-item" ng-repeat="category in vm.CATEGORIES" ng-show="vm.filterText == 'Categories'" ng-click="getCategories(category)">
<div class="icon">
<img src="{{ item.image }}" alt="{{ item.name }}" ng-if="item.image"/>
<div class="no-image center-align" ng-if="!item.image">
Expand Down Expand Up @@ -134,7 +135,7 @@
</div>
</ion-item>

<ion-item class="item-icon-left" ng-repeat="discount in vm.discounts" ng-click="addDiscount(discount)" ng-show"vm.filterText == 'Discounts'">
<ion-item class="item-icon-left" ng-repeat="discount in vm.discounts" ng-click="addDiscount(discount)" ng-show="vm.filterText == 'Discounts'">
<i class="icon ion-pricetag"></i>
<div class="padding-left">
{{ discount.title }}
Expand Down
Loading

0 comments on commit 58e5df3

Please sign in to comment.