2016-09-12 56 views
1

我正在創建發票生成器。因爲我想將總量,折扣和所有東西存儲在我的數據庫中。 總計和折扣的計算方法遵循...如何使用angularjs在mysql中存儲數學函數值?

<tr ng-repeat="list in data"> 
    <td> 
    <label class="clabel">Subtotal</label> 
    </td> 
    <td ng-model="subtotal">{{list.sale_price*list.quantity}}</td> 
</tr> 
<tr ng-repeat="list in data"> 
    <td> 
    <label class="clabel">Tax(2%)</label> 
    </td> 
    <td ng-model="tax">{{((list.sale_price*list.quantity)*2)/100}}</td> 
</tr> 
<tr ng-repeat="list in data"> 
    <td> 
    <label class="clabel">Discount(%)</label> 
    </td> 
    <td ng-model="discount">{{((list.sale_price*list.quantity)*list.discount)/100}}</td> 
</tr> 
<tr ng-repeat="list in data"> 
    <td> 
    <label class="clabel">Total</label> 
    </td> 
    <td ng-model="total">{{((list.sale_price*list.quantity)+(((list.sale_price*list.quantity)*2)/100))-(((list.sale_price*list.quantity)*list.discount)/100)}}</td> 
</tr> 
<tr> 
    <td colspan="2"> 
    <button class="btn btn-success" style="margin-left:400px;" ng-click="GenerateBill();updateAll()">Generate Invoice</button> 
    </td> 
</tr> 

現在,我想在我的database.which意味着我要存儲list.sale_price*list.quantity的值保存計算值。

JS部分是在這裏..

$scope.updateAll = function(){ 

    data={ 
     qnt:$scope.qnt, 
     subt:$scope.subtotal, 
     tax:$scope.tax, 
     dis:$scope.discount, 
     total:$scope.total 
    } 
    $http.post("../POS_System/widget/updateAll.php?barcode="+$scope.barcode,data).success(function(data){ 

    }); 

請幫我...

+1

如果您希望我們編寫整個數據,方式過於寬泛基礎層爲你。更何況你還沒有提供任何有關平臺的信息。 –

回答

1

你可以試試這個....

$scope.updateAll=function() 
{ 
    data={ 
       subtotal:$scope.product.sale_prize*$scope.product.quantity, 
       tax:$scope.product.sale_prize * $scope.product.quantity*2/100, 
       discount:$scope.product.sale_prize * $scope.product.quantity*$scope.product.discount/100, 
       total:$scope.product.sale_prize * $scope.product.quantity+$scope.product.sale_prize * $scope.product.quantity*2/100-$scope.product.sale_prize *$scope.product.quantity* $scope.product.discount/100 

     } 

     $http.post("../pos_system/Widgets/updatedata.php?barc="+$scope.barc,data).success(function(data) 
     { 
      //do your stuff here; 
     }); 
} 

讓你的HTML部分這種變化

<tr > 
    <td> 
    <label class="clabel">Subtotal</label> 
    </td> 
    <td><input type="text" class="cinput" placeholder="sale price" ng-value="list.sale_price*list.quantity" readonly="" /> 
    </td> 
</tr> 
<tr > 
    <td> 
    <label class="clabel">Tax(2%)</label> 
    </td> 
    <td><input type="text" class="cinput" placeholder="sale price" ng-value="((list.sale_price*list.quantity)*2)/100" readonly="" /> 
    </td> 
</tr> 
<tr> 
    <td> 
    <label class="clabel">Discount(%)</label> 
    </td> 
    <td> 
    <input type="text" class="cinput" placeholder="sale price" ng-value="((list.sale_price*list.quantity)*list.discount)/100" readonly="" /> 
    </td> 
</tr> 
<tr > 
    <td> 
    <label class="clabel">Total</label> 
    </td> 
    <td > 
    <input type="text" class="cinput" placeholder="sale price" ng-value="((list.sale_price*list.quantity)+(((list.sale_price*list.quantity)*2)/100))-(((list.sale_price*list.quantity)*list.discount)/100)" readonly="" /> 
    </td> 
</tr> 
<tr> 
    <td colspan="2"> 
    <button class="btn btn-success" style="margin-left:400px;" ng-click="GenerateBill();updateAll()">Generate Invoice</button> 
    </td> 
</tr> 
相關問題