Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <ion-item *ngFor="let stock of stocks | async" class="item item-trns text-center"
- (click)="showOptions(stock, stock.$key)">
- <strong><h2>{{ stock.name }}</h2></strong>
- <p>Date added: {{stock.date}}</p>
- <p>Quantity in stock: {{stock.actualq-stock.sold}}</p>
- <p>Sold: {{stock.sold}}</p>
- showOptions(stock, stock.$key)
- Quantity in stock: {{stock.actualq-stock.sold}}
- addSale(id,saledate,salequantity,buyingprice,sellingprice,sale,profit,saletotal) {
- if(id) {
- this.stocks.update(id, {
- saledate: saledate,
- salequantity: salequantity,
- buyingprice: buyingprice,
- sellingprice: sellingprice,
- sale: true,
- profit: (sellingprice-buyingprice)*salequantity,
- saletotal: (salequantity*sellingprice),
- }).then( newSale => {
- this.toast.show('Data updated', '5000', 'center').subscribe(
- toast => {
- this.navCtrl.pop();
- }
- );
- })
- .catch(e => {
- console.log(e);
- this.toast.show(e, '5000', 'center').subscribe(
- toast => {
- console.log(toast);
- }
- );
- });
- addSale(id,saledate,salequantity,buyingprice,sellingprice,sale,profit,saletotal) {
- if(id) {
- this.db.object('stocks/'+id).snapshotChanges().subscribe(action => {
- console.log(action.payload.val());
- let stockInHand = action.payload.val().actualq-action.payload.val().sold;
- //check if salequantity is lessthan or equal to stockInHand
- if(salequantity <= stockInHand){
- //perform update
- }else{
- //toast no stock available
- }
- });
- }
- }
Add Comment
Please, Sign In to add comment