Guest User

Untitled

a guest
Feb 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. <ion-item *ngFor="let stock of stocks | async" class="item item-trns text-center"
  2. (click)="showOptions(stock, stock.$key)">
  3. <strong><h2>{{ stock.name }}</h2></strong>
  4. <p>Date added: {{stock.date}}</p>
  5. <p>Quantity in stock: {{stock.actualq-stock.sold}}</p>
  6. <p>Sold: {{stock.sold}}</p>
  7.  
  8. showOptions(stock, stock.$key)
  9.  
  10. Quantity in stock: {{stock.actualq-stock.sold}}
  11.  
  12. addSale(id,saledate,salequantity,buyingprice,sellingprice,sale,profit,saletotal) {
  13. if(id) {
  14. this.stocks.update(id, {
  15. saledate: saledate,
  16. salequantity: salequantity,
  17. buyingprice: buyingprice,
  18. sellingprice: sellingprice,
  19. sale: true,
  20. profit: (sellingprice-buyingprice)*salequantity,
  21. saletotal: (salequantity*sellingprice),
  22.  
  23. }).then( newSale => {
  24. this.toast.show('Data updated', '5000', 'center').subscribe(
  25. toast => {
  26. this.navCtrl.pop();
  27. }
  28. );
  29. })
  30. .catch(e => {
  31. console.log(e);
  32. this.toast.show(e, '5000', 'center').subscribe(
  33. toast => {
  34. console.log(toast);
  35. }
  36. );
  37. });
  38.  
  39. addSale(id,saledate,salequantity,buyingprice,sellingprice,sale,profit,saletotal) {
  40. if(id) {
  41. this.db.object('stocks/'+id).snapshotChanges().subscribe(action => {
  42. console.log(action.payload.val());
  43. let stockInHand = action.payload.val().actualq-action.payload.val().sold;
  44. //check if salequantity is lessthan or equal to stockInHand
  45. if(salequantity <= stockInHand){
  46. //perform update
  47. }else{
  48. //toast no stock available
  49. }
  50. });
  51. }
  52. }
Add Comment
Please, Sign In to add comment