Php 如何在ng repeat内以angularJs生成发票?
如果我按下按钮并使用ng click event for show(data)功能,它只计算一个产品的答案,但我希望所有产品的答案,那么我可以做什么。这是我的ng repeat部分,显示产品的数据Php 如何在ng repeat内以angularJs生成发票?,php,html,angularjs,Php,Html,Angularjs,如果我按下按钮并使用ng click event for show(data)功能,它只计算一个产品的答案,但我希望所有产品的答案,那么我可以做什么。这是我的ng repeat部分,显示产品的数据 <tr ng-repeat="data in data" ng-init="show(data)"> <td>{{data.product_name}}</td> <td>{{data.type}}</t
<tr ng-repeat="data in data" ng-init="show(data)">
<td>{{data.product_name}}</td>
<td>{{data.type}}</td>
<td>{{data.quantity}}</td>
<td>{{data.sale_prize}}</td>
<td>{{data.sale_prize*data.quantity}}</td>
<td>{{data.discount}}</td>
</tr>
现在,如果我想在所有产品的show(data)
功能中使用这些答案,那么该怎么办?那么,我的显示(数据)
功能是什么呢
<table>
<tr ng-repeat="data in data">
<td>{{data.product_name}}</td>
<td>{{data.type}}</td>
<td>{{data.quantity}}</td>
<td>{{data.sale_prize}}</td>
<td>{{data.sale_prize*data.quantity}}</td>
<td>{{data.discount}}</td>
</tr>
</table>
<button ng-click="showinvoice()">Show Invoice</button>
<br/><Br/>
<div id="invoice" style="display:none">
<label>Sub Total:</label>
<input type="text" placeholder="sale price"
ng-value="invoice.total" readonly="true"/><br />
<label >Tax(2%):</label>
<input type="text" readonly="true"
ng-value="invoice.tax" placeholder="tax"/>
<label >Discount(%):</label>
<input type="text" readonly="true"
ng-value="invoice.discount"
placeholder="discount(%)" /><br />
<label>Total Price:</label>
<input type="text"
ng-value="invoice.total+invoice.tax-invoice.discount"readonly="true" placeholder="Total price"/>
</div>
{{data.product_name}
{{data.type}
{{data.quantity}
{{data.sale_prize}
{{data.sale_prize*data.quantity}
{{data.discount}
出示发票
小计:
税项(2%):
折扣(%):
总价:
Js将如下所示:
$scope.data = [
{
'product_name' : 'sample_one',
'type' : 'sanple_type',
'quantity' : 1,
'sale_prize' : 5000,
'discount' : 3
},
{
'product_name' : 'sample_two',
'type' : 'sanple_type',
'quantity' : 5,
'sale_prize' : 5000,
'discount' : 3
},
{
'product_name' : 'sample_three',
'type' : 'sanple_type',
'quantity' : 1,
'sale_prize' : 5000,
'discount' : 5
}
]
$scope.invoice = {};
var total = 0;
var discount = 0;
for (var i=0; i < $scope.data.length; i++) {
total = total + $scope.data[i].sale_prize*$scope.data[i].quantity;
discount = discount+$scope.data[i].discount;
}
$scope.invoice['total'] = total;
$scope.invoice['tax'] = (total*2)/100;
$scope.invoice['discount'] = (total*discount)/100;
$scope.showinvoice = function () {
$('#invoice').fadeIn()
}
$scope.data=[
{
“产品名称”:“样品一号”,
“类型”:“sanple_类型”,
“数量”:1,
“销售奖”:5000,
“折扣”:3
},
{
“产品名称”:“样本二”,
“类型”:“sanple_类型”,
“数量”:5,
“销售奖”:5000,
“折扣”:3
},
{
“产品名称”:“样品三”,
“类型”:“sanple_类型”,
“数量”:1,
“销售奖”:5000,
“折扣”:5
}
]
$scope.invoice={};
var合计=0;
var贴现=0;
对于(变量i=0;i<$scope.data.length;i++){
总计=总计+$scope.data[i]。销售奖金*$scope.data[i]。数量;
折扣=折扣+$scope.data[i]。折扣;
}
$scope.invoice['total']=总计;
$scope.发票['tax']=(总计*2)/100;
$scope.invoice['折扣]=(总*折扣)/100;
$scope.showinvoice=函数(){
$(“#发票”).fadeIn()
}
我正在分享一个工作演示。这可能对你有帮助
演示:到目前为止您都尝试了什么?你能分享你的jsfiddle吗?对不起,我没有工作的jsfiddle。但是这个ng值只显示了一个产品的计算结果,但是我想要多个产品的结果,那么怎么办呢@加载..计算也以ng重复?你能给我看看你的json数据吗?这个show(data)函数是显示计算结果的。你在静态中显示了什么,但在我的例子中,我是从database@KrishCdbryYes我使用示例数据向您展示了一个示例,但您可以从数据库中获取数据并将其分配给$scope.dataSo,它将类似于$http.get(“某些API链接”)。成功(函数(数据){$scope.data=data;}这取决于您的API响应。没有数据包含您需要逐个显示的项,而发票是通过计算所有数据项生成的最终项。因此,您需要将数据库响应分配给$scope。数据和发票将计算所有数据项。我照您说的做了,但我没有得到结果。@KrishCdbry
<table>
<tr ng-repeat="data in data">
<td>{{data.product_name}}</td>
<td>{{data.type}}</td>
<td>{{data.quantity}}</td>
<td>{{data.sale_prize}}</td>
<td>{{data.sale_prize*data.quantity}}</td>
<td>{{data.discount}}</td>
</tr>
</table>
<button ng-click="showinvoice()">Show Invoice</button>
<br/><Br/>
<div id="invoice" style="display:none">
<label>Sub Total:</label>
<input type="text" placeholder="sale price"
ng-value="invoice.total" readonly="true"/><br />
<label >Tax(2%):</label>
<input type="text" readonly="true"
ng-value="invoice.tax" placeholder="tax"/>
<label >Discount(%):</label>
<input type="text" readonly="true"
ng-value="invoice.discount"
placeholder="discount(%)" /><br />
<label>Total Price:</label>
<input type="text"
ng-value="invoice.total+invoice.tax-invoice.discount"readonly="true" placeholder="Total price"/>
</div>
$scope.data = [
{
'product_name' : 'sample_one',
'type' : 'sanple_type',
'quantity' : 1,
'sale_prize' : 5000,
'discount' : 3
},
{
'product_name' : 'sample_two',
'type' : 'sanple_type',
'quantity' : 5,
'sale_prize' : 5000,
'discount' : 3
},
{
'product_name' : 'sample_three',
'type' : 'sanple_type',
'quantity' : 1,
'sale_prize' : 5000,
'discount' : 5
}
]
$scope.invoice = {};
var total = 0;
var discount = 0;
for (var i=0; i < $scope.data.length; i++) {
total = total + $scope.data[i].sale_prize*$scope.data[i].quantity;
discount = discount+$scope.data[i].discount;
}
$scope.invoice['total'] = total;
$scope.invoice['tax'] = (total*2)/100;
$scope.invoice['discount'] = (total*discount)/100;
$scope.showinvoice = function () {
$('#invoice').fadeIn()
}