there is a userinterface for entering products with name, quantity. if the product name already exists in database, subtract the product quantity we are entering from database value and update in which has same field of product quantity. else insert it.

if(this.storeservice.checkoutgoing(name))
      {

      this.storeservice.checkoutgoing(name).valueChanges().subscribe((arg: any) =>
       {


        arg.forEach(elem => {
          const id = elem.id;
          const prd = elem.productqty;
         // const fieldprd =  element.incomingpieces;

           const total: number  = Number.parseFloat(prd.toString()) -  Number.parseFloat(outgoingpieces.toString());

          this.storeservice.updateoutgoingo(total,id);
     });

      });

    }
    else
    {

    }







checkoutgoing(name) : AngularFirestoreCollection<any> {
    return this.db.collection(`productmetirials`, ref => ref.where('productname','==',name).orderBy("date", "desc"));
  }



  updateoutgoingo(productqty,id):  Promise<void> {

    const date: string  = new Date().toISOString();
    const method = 'outgoing';

    return this.db.doc(`productmeterials/${id}`).update({
      productqty,
        date,

      });[enter image description here][1]

    }

0 Answers