我们通过以下公式计算显示总佣金 总佣金=佣金*行数
对于某些行,我们有值=“已退回或已取消”。 如果value =“已退回或已取消”,我们不想计算这些行来计算佣金。
对于下面的图片,现在TC = 60,但我们需要 40 ,因为前2行有值已交付&取消。
PHP
function getDesignerCollection()
{
foreach($order as $orderData)
{
while ($k < count($orderitemsarray))
{
if ($orderitemsarray[$k] != '0')
{
$stmtorders = $user_home->runQuery("SELECT * FROM order_details");
$stmtorders->execute(array(":dorder_id" => $orderData['entity_id']));
$roworders = $stmtorders->fetch(PDO::FETCH_ASSOC);
if($accountType == "admin")
{
$delivery_status='';
while($datas = $stmt1->fetch())
{
$delivery_status=$datas['delivery_status'];
if($datas['delivery_status']=='P'){$delivery_status='Pending';}
if($datas['delivery_status']=='D'){$delivery_status='Delivered';}
if($datas['delivery_status']=='R'){$delivery_status='Returned';}
if($datas['delivery_status']=='C'){$delivery_status='Cancelled';}
}
$stmt = $user_home->runQuery("SELECT commission1 FROM tbl_users where userID=:uid");
$stmt->execute(array(":uid" => $_SESSION['userSession']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$commission = $row['commission1'] ;
$responce[] = array(
$commission,
$delivery_status,
);
}
脚本
$(".delete_grid").append("Number of rows : "+mygrid.dataset.getSize());
// Total Commission
var numRows=mygrid.dataset.getSize();
var commission =(mygrid.dataset.data[0][8]);
var total_commission=numRows * commission;
$(".delete_grid").append(" , Total commission : "+total_commission);
var __TEST_DATA__=eval('<?php
echo getDesignerCollection(); ?>');
var grid_demo_id = "myGrid" ;
var dsOption= {
fields :[
{name : 'commission1' },
{name : 'delivery_status' },
],
recordType : 'array',
data : __TEST_DATA__
}
var colsOption = [
{id: 'commission1' , header: "commission1" , width :"80"},
{id: 'delivery_status' , header: "Deliver Status" , width :"130"},
];
答案 0 :(得分:0)
使用php中的变量,如下所示
$delivery_status='';
$count = 0;
while($datas = $stmt1->fetch())
{
$delivery_status=$datas['delivery_status'];
if($datas['delivery_status']=='P'){$delivery_status='Pending'; }
if($datas['delivery_status']=='D'){$delivery_status='Delivered'; }
if($datas['delivery_status']=='R'){$delivery_status='Returned'; }
if($datas['delivery_status']=='C'){$delivery_status='Cancelled'; }
if($datas['delivery_status'] != 'R' && $datas['delivery_status'] != 'C'){
$count++;
}
}
现在,您可以将totalCommission
计为
$totalCommission = $count * $commission
答案 1 :(得分:0)
var commission=0;
for (var i = 0; i < mygrid.dataset.data.length; i++) {
console.log(mygrid.dataset.data[i]);
if(mygrid.dataset.data[i][10] != "Returned" && mygrid.dataset.data[i][10] != "Cancelled"){
commission=commission+parseInt(mygrid.dataset.data[i][8]);
}
console.log(commission);
}
$(".delete_grid").append(" , Total commission : "+commission);