Perform Subtraction in HTML Table row using AngularJS in ASP.Net

Last Reply 3 months ago By skp

Posted 3 months ago

Performing subtraction operation from web api data in angularjs

stock =  acceptqty - issuedqty - issueqty

         = 1020-510-510

         = 0

Therefore, stock must be zero.

The subtracted value must change in stock.

$http.get(apiUrl + "/api/Warehouse/GetDetails?invoiceno=" + $scope.selectedInvoice.originalObject.InvoiceNo + "")
.then(function (response) {
    $scope.mydata = JSON.parse(response.data);
    $scope.calc = function (index) {
        $scope.mydata[index].mul = parseFloat($scope.mydata[index].PalletCapacity) * parseFloat($scope.mydata[index].num);
        $scope.$apply();
        $scope.mydata[index].diff = $scope.mydata[index].Numbers - $scope.mydata[index].IssuedQty - $scope.mydata[index].mul;
    }
});

 

Posted 3 months ago

It is just as same as the multiplication operation. The one thing we should notice here is the variable name. We have to carefully use the variable name accordingly.

$http.get(apiUrl + "/api/Warehouse/GetDetails?invoiceno=" + $scope.selectedInvoice.originalObject.InvoiceNo + "")
.then(function (response) {
    $scope.mydata = JSON.parse(response.data);
    $scope.calc = function (index) {
        $scope.mydata[index].mul = parseFloat($scope.mydata[index].PalletCapacity) * parseFloat($scope.mydata[index].num);                            
        //$scope.$apply();               
        $scope.mydata[index].Stock = $scope.mydata[index].Numbers - $scope.mydata[index].IssuedQty - $scope.mydata[index].mul;               
    }                  
});

 

        <div class="bg-white mb-1">
            <div class="row m-1 p-1" ng-repeat="item in mydata">

                <div class="col-md-1 pull-left airways-info-sect">
                    <span class="fli-code">Serial No</span>
                    <span class="airways-name" style="text-align:center;">{{$index + 1}}</span>
                </div>

                <div class="col-md-3 pull-left airways-info-sect">
                    <span class="fli-code">Part Name</span>
                    <span class="airways-name" style="text-align: left;">{{item.PartName}}</span>
                </div>

                <!--<div class="col-md-1 pull-left airways-info-sect">
                    <span class="fli-code">Part No</span>
                    <span class="airways-name ">{{item.PartNo}}</span>

                </div>-->

                <div class="col-md-2 pull-left airways-info-sect">
                    <span class="fli-code">No Of Pallets</span>
                    <span class="airways-name ">
                        <input type="number" min="0" class="" placeholder="" ng-model="item.num" ng-init="item.num=0" ng-change="calc($index)" required="" style="border:1px solid #333; width:20%; text-align:right" /><i class="mr-3 fa fa-plus-square-o" style="font-size:22px; padding-left:5px; position:absolute;"></i>
                    </span>
                </div>

                <div class="col-md-1 pull-left airways-info-sect"> 
                <span class="fli-code">Pallet Qty</span> 
                    <span class="airways-name" style="text-align:right;">{{item.PalletCapacity}}</span>  
                </div>

                <div class="col-md-1 pull-left airways-info-sect"> 
                <span class="fli-code">Accept Qty</span> 
                <span class="airways-name">{{item.Numbers}}</span>  
                </div>

                <div class="col-md-1 pull-left airways-info-sect"> 
                <span class="fli-code">Issued Qty</span> 
                    <span class="airways-name" style="text-align:right;">{{item.IssuedQty}}</span>  
                </div>

                <div class="col-md-1 pull-left airways-info-sect">
                    <span class="fli-code">Issue Qty</span>
                    <input type="number" class="" placeholder="" ng-model="item.mul" ng-init="item.mul=0" required="" style="border: 1px solid #333; width: 90%; text-align: right" />
                </div>

                <div class="col-md-1 pull-left airways-info-sect">
                <span class="fli-code">Stock</span> 
                    <span class="airways-name" style="text-align:right;">{{item.Stock}}</span>  
                </div>
            </div>
        </div>