Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function() {
- 'use strict';
- angular.module("purchaseOrderModule")
- .controller("LookupProductPurchaseOrderController", LookupProductPurchaseOrderController);
- LookupProductPurchaseOrderController.$inject = ['$uibModalInstance', 'items','$scope' ,'RestService', 'PurchasingApiConstant', '$filter', 'LeafCommonConstant'];
- function LookupProductPurchaseOrderController($uibModalInstance, items, $scope, RestService, PurchasingApiConstant, $filter, LeafCommonConstant) {
- var ctrl = $scope;
- ctrl.checkAll = checkAll;
- ctrl.doSearch = doSearch;
- ctrl.pageChanged = pageChanged;
- ctrl.doAddProduct = doAddProduct;
- ctrl.close = close;
- ctrl.errors = [];
- ctrl.productList = [];
- ctrl.totalItems = 0;
- ctrl.currentPage = 1;
- ctrl.limit = 5;
- ctrl.input = {
- "keyword": "",
- "ctgrProductId": null,
- "subCtgrProductId": null,
- "brand": "",
- "limit": ctrl.limit,
- "currentPage": ctrl.currentPage,
- "checked": false,
- "productSelected": []
- };
- doSearch();
- function pageChanged(){
- ctrl.input.offset = (ctrl.input.currentPage-1)*ctrl.input.limit;
- doSearch();
- }
- function doSearch() {
- var input = angular.copy(ctrl.input);
- input.ctgrProductId = (input.ctgrProductId != null)? input.ctgrProductId : -99;
- input.subCtgrProductId = (input.subCtgrProductId != null)? input.subCtgrProductId : -99;
- RestService.call(PurchasingApiConstant.COUNT_GET_PRODUCT_LIST_FOR_PURCHASE_ORDER, input)
- .then(function (result) {
- input.offset = (ctrl.input.currentPage-1)*input.limit;
- ctrl.totalItems = result.result.count;
- ctrl.totalPages = Math.ceil(ctrl.totalItems / input.limit);
- getProductListForPurchaseOrder(input);
- })
- }
- function getProductListForPurchaseOrder(input) {
- RestService.call(PurchasingApiConstant.GET_PRODUCT_LIST_FOR_PURCHASE_ORDER, input)
- .then(function (response) {
- var result = response.result;
- if(result.status == "OK") {
- ctrl.productList = result.productList;
- } else {
- onTop();
- ctrl.errors = result;
- }
- })
- }
- function checkAll() {
- var condition = !ctrl.input.checked;
- if(condition){
- if(ctrl.input.productSelected.length == 0) {
- ctrl.input.productSelected = angular.copy(ctrl.productList);
- } else {
- if(ctrl.input.productSelected.length >= 0 && condition) {
- ctrl.input.productSelected = angular.copy(ctrl.productList);
- } else {
- ctrl.input.productSelected = [];
- }
- }
- } else {
- ctrl.input.productSelected = [];
- }
- }
- function doAddProduct() {
- try {
- if(items.id == -99) {
- var arrayData = [];
- _.forEach(ctrl.input.productSelected, function(value, key) {
- value.qty = 1;
- value.unitPrice = value.lastPrice;
- value.itemAmountGross = value.lastPrice*value.qty;
- arrayData.push(value)
- });
- $uibModalInstance.close(arrayData);
- }
- } catch (e) {
- }
- }
- function close() {
- $uibModalInstance.dismiss();
- }
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement