Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class AddProductModalComponent implements OnInit {
}

addProductToStockOrder(productModel: any) {
if (!productModel.quantity) {
if (!productModel.quantity || productModel.quantity <= 0) {
this.toastr.error('Quantity should be greater than zero');
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,15 @@
<th>Order Quantity</th>
<th>Suggested Order Quantity</th>
<th>Store Inventory</th>
<th *ngIf="userProfile.integrationType === 'vend'">Sync</th>
<th *ngIf="editable">Approve</th>
</tr>
</thead>
<tbody>
<ng-container *ngFor="let lineItem of notApprovedLineItems; let i = index">
<tr class="bg-light text-primary"
*ngIf="lineItem.categoryModelName !== notApprovedLineItems[i-1]?.categoryModelName">
<td colspan="7"><strong>{{lineItem.categoryModelName || 'No Category'}}</strong></td>
<td colspan="8"><strong>{{lineItem.categoryModelName || 'No Category'}}</strong></td>
</tr>
<tr>
<ng-container *ngIf="lineItem.productModel">
Expand All @@ -194,7 +195,7 @@
<div class="form-group">
<div class="input-group quantity-input">
<div class="input-group-prepend pointer"
(click)="lineItem.orderQuantity = lineItem.orderQuantity - (lineItem.caseQuantity || 1)">
(click)="decrementQuantity(lineItem)">
<span class="input-group-text">
<i class="fa fa-minus-circle quantity-icon text-danger"></i>
</span>
Expand Down Expand Up @@ -262,6 +263,13 @@
</button>
</td>
<td>{{lineItem.storeInventory}}</td>
<td *ngIf="userProfile.integrationType === 'vend'">
<i *ngIf="lineItem.asyncPushSuccess === true" class="fa fa-check-circle" style="color: green;"></i>
<i *ngIf="lineItem.asyncPushSuccess === false" class="fa fa-ban" style="color: red;"></i>
<div *ngIf="lineItem.asyncPushSuccess === null" class="spinner-border spinner-border-sm text-success" role="status">
<span class="sr-only">Loading...</span>
</div>
</td>
<td>
<button *ngIf="editable" class="btn btn-danger" type="submit"
(click)="approveItem(lineItem)">
Expand Down Expand Up @@ -370,14 +378,15 @@
<th>Order Quantity</th>
<th>Suggested Order Quantity</th>
<th>Store Inventory</th>
<th *ngIf="userProfile.integrationType === 'vend'">Sync</th>
<th *ngIf="editable">Remove</th>
</tr>
</thead>
<tbody>
<ng-container *ngFor="let lineItem of approvedLineItems; let i = index">
<tr class="bg-light text-primary"
*ngIf="lineItem.categoryModelName !== approvedLineItems[i-1]?.categoryModelName">
<td colspan="7"><strong>{{lineItem.categoryModelName || 'No Category'}}</strong></td>
<td colspan="8"><strong>{{lineItem.categoryModelName || 'No Category'}}</strong></td>
</tr>
<tr>
<ng-container *ngIf="lineItem.productModel">
Expand Down Expand Up @@ -450,6 +459,13 @@
</button>
</td>
<td>{{lineItem.storeInventory}}</td>
<td *ngIf="userProfile.integrationType === 'vend'">
<i *ngIf="lineItem.asyncPushSuccess === true" class="fa fa-check-circle" style="color: green;"></i>
<i *ngIf="lineItem.asyncPushSuccess === false" class="fa fa-ban" style="color: red;"></i>
<div *ngIf="lineItem.asyncPushSuccess === null" class="spinner-border spinner-border-sm text-success" role="status">
<span class="sr-only">Loading...</span>
</div>
</td>
<td>
<button *ngIf="editable" class="btn btn-danger" type="submit"
(click)="removeItem(lineItem)">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component, OnDestroy, OnInit, ViewChild} from '@angular/core';
import {ChangeDetectorRef, Component, OnDestroy, OnInit, ViewChild} from '@angular/core';
import {OrgModelApi} from "../../../../shared/lb-sdk/services/custom/OrgModel";
import {ActivatedRoute, Router} from '@angular/router';
import {combineLatest, Subscription} from 'rxjs';
Expand All @@ -14,6 +14,7 @@ import Utils from '../../../../shared/constants/utils';
import {BsModalRef, BsModalService} from "ngx-bootstrap/modal";
import {DeleteOrderComponent} from "../../shared-components/delete-order/delete-order.component";
import {SharedDataService} from '../../../../shared/services/shared-data.service';
import {delay} from 'rxjs/operators';

@Component({
selector: 'app-generated',
Expand Down Expand Up @@ -94,6 +95,7 @@ export class GeneratedComponent implements OnInit, OnDestroy {
private toastr: ToastrService,
private _userProfileService: UserProfileService,
private _eventSourceService: EventSourceService,
private changeDetector: ChangeDetectorRef,
private auth: LoopBackAuth,
private modalService: BsModalService,
private sharedDataService: SharedDataService) {
Expand All @@ -106,6 +108,9 @@ export class GeneratedComponent implements OnInit, OnDestroy {
this.emailModalData.to = this.order.supplierModel ? ( this.order.supplierModel.email ? this.order.supplierModel.email : '') : '';
this.getNotApprovedStockOrderLineItems();
this.getApprovedStockOrderLineItems();
if(this.userProfile.integrationType === 'vend') {
this.listenItemSyncChanges();
}
},
error => {
console.log('error', error)
Expand Down Expand Up @@ -696,4 +701,30 @@ export class GeneratedComponent implements OnInit, OnDestroy {
console.log(e);
}

decrementQuantity(lineItem: any) {
let newOrderQty = lineItem.orderQuantity - (lineItem.caseQuantity || 1);
if (newOrderQty < 0) {
newOrderQty = 0;
}
lineItem.orderQuantity = newOrderQty
}

listenItemSyncChanges() {
const EventSourceUrl = `/notification/${this.order.id}-line-items/waitForResponseAPI`;
const eventApi = this._eventSourceService.connectToStream(EventSourceUrl)
.subscribe(([event, es]) => {
console.log(event);
const { data } = event;
const searchArray = data.approved ? this.approvedLineItems: this.notApprovedLineItems;
for (let i = 0; i < searchArray.length; i++){
if (searchArray[i].id === data.stockOrderLineItemId) {
searchArray[i].asyncPushSuccess = data.success;
this.changeDetector.detectChanges();
break;
}
}

});
this.subscriptions.push(eventApi);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,15 @@
<th>Delivered Quantity</th>
<th>Received Quantity</th>
<th>Store Inventory</th>
<th *ngIf="userProfile.integrationType === 'vend'">Sync</th>
<th *ngIf="editable">Receive</th>
</tr>
</thead>
<tbody>
<ng-container *ngFor="let lineItem of notReceivedLineItems; let i = index;">
<tr class="bg-light text-primary"
*ngIf="lineItem.categoryModelName !== notReceivedLineItems[i-1]?.categoryModelName">
<td colspan="8"><strong>{{lineItem.categoryModelName || 'No Category'}}</strong></td>
<td colspan="9"><strong>{{lineItem.categoryModelName || 'No Category'}}</strong></td>
</tr>
<tr>
<ng-container *ngIf="lineItem.productModel">
Expand Down Expand Up @@ -218,6 +219,13 @@
</div>
</td>
<td>{{lineItem.storeInventory}}</td>
<td *ngIf="userProfile.integrationType === 'vend'">
<i *ngIf="lineItem.asyncPushSuccess === true" class="fa fa-check-circle" style="color: green;"></i>
<i *ngIf="lineItem.asyncPushSuccess === false" class="fa fa-ban" style="color: red;"></i>
<div *ngIf="lineItem.asyncPushSuccess === null" class="spinner-border spinner-border-sm text-success" role="status">
<span class="sr-only">Loading...</span>
</div>
</td>
<td *ngIf="editable">
<button *ngIf="!enableBarcode" class="btn btn-danger" type="submit"
(click)="receiveItem(lineItem)">
Expand Down Expand Up @@ -276,14 +284,15 @@
<th>Ordered Quantity</th>
<th>Delivered Quantity</th>
<th>Received Quantity</th>
<th *ngIf="userProfile.integrationType === 'vend'">Sync</th>
<th *ngIf="editable">Remove</th>
</tr>
</thead>
<tbody>
<ng-container *ngFor="let lineItem of receivedLineItems; let i = index;">
<tr class="bg-light text-primary"
*ngIf="lineItem.categoryModelName !== receivedLineItems[i-1]?.categoryModelName">
<td colspan="8"><strong>{{lineItem.categoryModelName || 'No Category'}}</strong></td>
<td colspan="9"><strong>{{lineItem.categoryModelName || 'No Category'}}</strong></td>
</tr>
<tr>
<ng-container *ngIf="lineItem.productModel">
Expand All @@ -308,6 +317,13 @@
</td>
<td>{{lineItem.fulfilledQuantity}}</td>
<td>{{lineItem.receivedQuantity}}</td>
<td *ngIf="userProfile.integrationType === 'vend'">
<i *ngIf="lineItem.asyncPushSuccess === true" class="fa fa-check-circle" style="color: green;"></i>
<i *ngIf="lineItem.asyncPushSuccess === false" class="fa fa-ban" style="color: red;"></i>
<div *ngIf="lineItem.asyncPushSuccess === null" class="spinner-border spinner-border-sm text-success" role="status">
<span class="sr-only">Loading...</span>
</div>
</td>
<td *ngIf="editable">
<button *ngIf="!enableBarcode" class="btn btn-danger" type="submit"
(click)="removeItem(lineItem)">
Expand Down Expand Up @@ -340,7 +356,7 @@
[maxSize]="maxPageDisplay"
[rotate]="false"
[boundaryLinks]="true"
(pageChanged)="getReceivedLineItems(lineItemsLimitPerPage, ($event.page - 1) * lineItemsLimitPerPage)"
(pageChanged)="getReceivedStockOrderLineItems(lineItemsLimitPerPage, ($event.page - 1) * lineItemsLimitPerPage)"
[itemsPerPage]="lineItemsLimitPerPage">
</pagination>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component, ElementRef, OnDestroy, OnInit, ViewChild} from '@angular/core';
import {ChangeDetectorRef, Component, ElementRef, OnDestroy, OnInit, ViewChild} from '@angular/core';
import {OrgModelApi} from "../../../../shared/lb-sdk/services/custom/OrgModel";
import {ActivatedRoute, Router} from '@angular/router';
import {Observable, combineLatest, Subscription} from 'rxjs';
Expand Down Expand Up @@ -59,6 +59,7 @@ export class ReceiveComponent implements OnInit, OnDestroy {
private _eventSourceService: EventSourceService,
private auth: LoopBackAuth,
private modalService: BsModalService,
private changeDetector: ChangeDetectorRef,
private sharedDataService: SharedDataService) {
}

Expand All @@ -68,6 +69,9 @@ export class ReceiveComponent implements OnInit, OnDestroy {
this.order = data.stockOrderDetails[0];
this.getNotReceivedStockOrderLineItems();
this.getReceivedStockOrderLineItems();
if(this.userProfile.integrationType === 'vend') {
this.listenItemSyncChanges();
}
},
error => {
console.log('error', error)
Expand Down Expand Up @@ -357,14 +361,13 @@ export class ReceiveComponent implements OnInit, OnDestroy {
} else {
this.loading = true;
this.creatingPurchaseOrderVend = true;
this.waitForRecieveWorker(this.userProfile.userId);
this.orgModelApi.receiveConsignment(
this.userProfile.orgModelId,
this.order.id
).subscribe(recieveRequest => {
this.toastr.info('Receiving consignment...');
this._router.navigate(['/orders/stock-orders']);
this.loading = false;
this.waitForRecieveWorker(recieveRequest.callId);
}, error => {
this.loading = false;
this.toastr.error('Error in receiving order');
Expand All @@ -373,19 +376,20 @@ export class ReceiveComponent implements OnInit, OnDestroy {
}

waitForRecieveWorker(callId) {
const self = this;
const EventSourceUrl = `/notification/${callId}/waitForResponse`;
this.subscriptions.push(
this._eventSourceService.connectToStream(EventSourceUrl)
.subscribe(([event, es]) => {
console.log(event);
es.close();
if (event.data.success === true) {
es.close();
this.creatingPurchaseOrderVend = false;
this._router.navigate(['/orders/stock-orders']);
this.toastr.success('Order received successfully');
self.creatingPurchaseOrderVend = false;
self._router.navigate(['/orders/stock-orders']);
self.toastr.success('Order received successfully');
} else {
this.creatingPurchaseOrderVend = false;
this.toastr.error('Error in receiving order');
self.creatingPurchaseOrderVend = false;
self.toastr.error('Error in receiving order');
}
})
);
Expand Down Expand Up @@ -459,6 +463,29 @@ export class ReceiveComponent implements OnInit, OnDestroy {
this.searchProductBySku(searchSKUText)
}
}

listenItemSyncChanges() {
const EventSourceUrl = `/notification/${this.order.id}-line-items/waitForResponseAPI`;
const eventApi = this._eventSourceService.connectToStream(EventSourceUrl)
.subscribe(([event, es]) => {
console.log(event);
const { data } = event;
for (let i = 0; i < this.receivedLineItems.length; i++){
if (this.receivedLineItems[i].id === data.stockOrderLineItemId) {
this.receivedLineItems[i].asyncPushSuccess = data.success;
break;
}
}
for (let i = 0; i < this.notReceivedLineItems.length; i++){
if (this.notReceivedLineItems[i].id === data.stockOrderLineItemId) {
this.notReceivedLineItems[i].asyncPushSuccess = data.success;
break;
}
}
this.changeDetector.detectChanges();
});
this.subscriptions.push(eventApi);
}
}

class box {
Expand Down
Loading