Remove three rows from an array using Angular 7

I need assistance with a subtraction operation involving the first 3 rows of a table.

TVA Collectée -TVA Déductible - Tva déductible/immo

If the result is positive, I want to display it in the TVA à Payer box, and if it's negative, show it in the Crédit de TVA box.

Below is the HTML code snippet:



  <div class="table-responsive">
    <table class="styled-table" border="1" cellpadding="1" cellspacing="1">
      <thead>
        <tr height="50">
          <th align="center" width="150">&nbsp;</th>
          <td align="center" width="150" *ngFor="let item of listdate">{{item}}</td>
        </tr>
      </thead>

      <tbody>
        <tr>

          <th>TVA Collectée</th>
          <ng-container *ngFor="let item of date">
            <td>
              <ng-container *ngFor="let c of listTvaVente">
                <label *ngIf="item === c.date">{{c.tvaCollectee | number : '0.3-3'}}</label>
              </ng-container>
            </td>
          </ng-container>

        </tr>
        <tr>
          <th>TVA Déductible</th>
          <ng-container *ngFor="let item of date">
            <td>
              <ng-container *ngFor="let c  of listTvaAchat ">
                <label *ngIf="item === c.date ">{{c.tvaDeductible| number : '0.3-3'}}</label>
              </ng-container>
            </td>
          </ng-container>
        </tr>

        <tr>
          <th>TVA Déductible/immo</th>
          <ng-container *ngFor="let item of date">
            <td>
              <ng-container *ngFor="let c  of listTvaInv ">
                <label *ngIf="item=== c.date ">{{c.tvaDeductible| number : '0.3-3'}}</label>
              </ng-container>
            </td>
          </ng-container>
        </tr>
        <tr>
          <th>TVA à Reporter</th>
        </tr>
        <tr>
          <th>TVA à Payer</th>
        </tr>
        <tr>
          <th>Crédit de TVA</th>
        </tr>

      </tbody>

    </table>
  </div>

This my .ts code:

import { Component, VERSION } from '@angular/core';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  listdate = ['Janvier-2021', 'Février-2021', 'Mars-2021'];
  date = ['2020-01', '2020-02', '2020-03'];

  listTvaVente = [
    {
      date: '2020-01',
      year: 2020,
      month: 'JANUARY',
      chiffreAffaireHT: 0.0,
      tvaCollectee: 36000.0
    },
    {
      date: '2020-02',
      year: 2020,
      month: 'FEBRUARY',
      chiffreAffaireHT: 0.0,
      tvaCollectee: 35455.0
    },
    {
      date: '2020-03',
      year: 2020,
      month: 'MARCH',
      chiffreAffaireHT: 0.0,
      tvaCollectee: 45000.0
    }
  ];

  listTvaAchat = [
    {
      date: '2020-01',
      year: 2020,
      month: 'JANUARY',
      chiffreAffaireHT: 0.0,
      tvaDeductible: 26000.0
    },
    {
      date: '2020-02',
      year: 2020,
      month: 'FEBRUARY',
      chiffreAffaireHT: 0.0,
      tvaDeductible: 26000.0
...

here is an example I want to do

https://i.sstatic.net/osBvu.png

Thanks in advance.

Answer №1

If you want to achieve the desired outcome, simply follow these instructions:

JavaScript:

    dataList = [
    {
      date: '2021-01',
      year: 2021,
      month: 'JANUARY',
      value: 0
    },
    {
      date: '2021-02',
      year: 2021,
      month: 'FEBRUARY',
      value: 0
    },
    {
      date: '2021-03',
      year: 2021,
      month: 'MARCH',
      value: 0
    }
  ];

  creditValues = [
    {
      date: '2021-01',
      year: 2021,
      month: 'JANUARY',
      credit: 0
    },
    {
      date: '2021-02',
      year: 2021,
      month: 'FEBRUARY',
      credit: 0
    },
    {
      date: '2021-03',
      year: 2021,
      month: 'MARCH',
      credit: 0
    }
  ];

  constructor() {}

  ngOnInit() {
    const length = this.dataList.length;
    for (let i = 0; i < length; i++) {
      const subValue =
        this.listTvaVente[i].tvaCollectee -
        this.listTvaAchat[i].tvaDeductible -
        this.listTvaInv[i].tvaDeductible;

      if (subValue >= 0) {
        this.dataList[i].value = subValue;
      } else {
        this.creditValues[i].credit = subValue * -1;
      }
    }
  }

As for .HTML code:

     <tr>
    <th>Total Value Added Tax Payable</th>
    <ng-container *ngFor="let item of date">
      <td>
        <ng-container *ngFor="let d  of dataList ">
          <label *ngIf="item=== d.date ">{{d.value| number : '0.3-3'}}</label>
        </ng-container>
      </td>
    </ng-container>
  </tr>
  <tr>
    <th>VAT Credit</th>
    <ng-container *ngFor="let item of date">
      <td>
        <ng-container *ngFor="let c  of creditValues ">
          <label *ngIf="item=== c.date ">{{c.credit| number : '0.3-3'}}</label>
        </ng-container>
      </td>
    </ng-container>
  </tr>

Check out this live demo for more details: https://stackblitz.com/edit/angular7-playground-myfas7?file=src%2Fapp%2Fapp.component.html

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What could be causing the error message "why can't shows read property

Within my Ionic-Angular application, I have successfully loaded the content from the database and printed it on the console. However, I am facing an issue where I cannot bind this content to the view. The error message that appears is displayed in https:// ...

Deconstructing Angular 2 Custom Pipes

As I delve deeper into learning Angular 2, my recent endeavor involves creating a custom pipe to filter results in my gallery by category. Unfortunately, the resources I've been referring to lack detailed explanations on how custom pipes actually work ...

Error in React Native Typescript: The type 'string' cannot be assigned to the type '"solid" | "clear" | "outline"'. (Error code: ts(2322))

I have integrated TypeScript with React Native in my project. import React from 'react'; import { Button } from 'react-native-elements'; import { IThemedButton } from '../../../models/themedButton'; interface IThemedButtonPr ...

How can I simulate an Item in dynamoose with a custom updateAt timestamp?

Currently, I am integrating end-to-end testing for a micro service. One of the features I am working on involves verifying that an item was last updated over 2 hours ago. However, when I create a mock object with a date that is 6 hours older than the cur ...

Utilizing Angular for Select Options with Objects as Values

One issue I am encountering is with a form that contains select boxes using objects as values: <mat-option [value]="object"> While this works fine when creating new records, editing existing ones proves to be problematic because the object in the m ...

Personalizing the arrow positioning of the Angular8 date picker (both top and bottom arrow)

I am interested in enhancing the design of the Angular 8 date picker by adding top and bottom arrows instead of the default left and right arrows. Can someone guide me on how to customize it? Check out the Angular 8 date picker here ...

Utilizing Dialogflow's Conv.Data or Conv.User.Storage for a Basic Counter System

I am interested in developing a simple counter within a conversation using a Firebase function with Actions for Google. The documentation suggests the following: app.intent('Default Welcome Intent', conv => { conv.data.someProperty = &apo ...

Upcoming 13.4 Error: NEXT_REDIRECT detected in API routes

Here is the code snippet from my /app/api/auth/route.ts file: import { redirect } from 'next/navigation'; export async function GET(req: Request) { try { redirect('/dashboard'); } catch (error) { console.log(error); ...

TypeScript generic types allow you to create reusable components that

function genericIdentity<T>(arg: T): T { return arg; } let myGenericIdentity: <U>(arg: U) => U = genericIdentity; I see that the 'genericIdentity' function is accepting an argument of a generic type. However, I am unsure about ...

Learn how to securely download files from an Azure Storage Container using Reactjs

I'm currently working on applications using reactjs/typescript. My goal is to download files from azure storage v2, following a specific path. The path includes the container named 'enrichment' and several nested folders. My objective is to ...

Step-by-step guide on incorporating HTML into a popover within Angular4

After successfully implementing a hover popover in Angular using PopoverModule from ngx-popover, I now need to modify the content inside the popover. My search led me to this example: <ng-template #popContent>Hello, <b& ...

The table on the page shifts position when viewed on different devices, sometimes not remaining between the header and footer

Here is a link to see how my page looks with the header, table, and footer: https://i.sstatic.net/U6tdO.png If you want to see how it looks when responsive (with smaller width), check out this link: https://i.sstatic.net/zsGkc.png I have encountered 2 ma ...

I have been attempting to incorporate icons from fluent ui northstar into the fluent ui dropdown component, but unfortunately, there is a lack of adequate documentation

I attempted to use renderItem to include a divider and Icon in a Fluent UI dropdown menu, but the icons are not visible. Even the default value does not display the icons, and the dropdown menu does not appear after clicking. import * as React from " ...

Expandable rows within an Angular Material table (mat-table) feature a distinct gap, even when rows are collapsed

I recently integrated an Angular Material table into my website, following the examples provided on the official Angular page (link to the examples). I wanted the table rows to be expandable similar to the "Table with expandable rows" example on the Angula ...

Configure the server port for transmitting API requests from Angular to NodeJS during the development phase

I've encountered an issue with my MEAN Stack application. I'm using Angular 6 for the front-end and have set up the users routing and back-end login system successfully tested with Postman. However, whenever I try to use the form, I keep encounte ...

In TypeScript, the indexof method is not available when filtering based on numbers

When attempting to filter the month value in a dropdown, I encountered an error stating that indexOf() is not a function. Here is the code snippet: @Pipe({ name: "monthFilter", }) export class MonthStatusPipe implements PipeTransform { transform ...

The type 'Dispatch<any>' cannot be assigned to the type '() => null'. Error code: ts(2322)

While working on my application context, I encountered a typescript error: 'Type 'Dispatch' is not assignable to type '() => null'.ts(2322)'. I am fairly new to typescript and struggling to understand this error. Below is ...

Troubleshooting: Issue with encoding in Javascript Blob using Ionic file plugin

Could you please help me troubleshoot why this code is not functioning correctly? Note: file is a native plugin var blob = new Blob(["This is the content of my blob"], { type: "text/plain" }); this.file.writeFile(this.file.dataDirectory, 'mylet ...

Tips for preventing the use of Observable within another Observable

My service makes an http request that returns Observables of headlines. The code in my servise.ts file looks like this: servise.ts get(sort: string): Observable<Response> { return this.http.get<any>(this.url, {...}); }) delete(id) { ret ...

The error message received is: `npm ERR! code ERR_TLS_CERT_ALTNAME_INVALID

Setting up a new Angular app after working on an existing one for months was quite challenging. Today, while trying to install the new Angular app through the terminal on my Mac, the process was unusually slow and ended up showing this error: npm ERR! co ...