profit
컬럼이있는 보고서가 있습니다. 이익 기둥의 모든 가치를 더하고 그 날의 총 이익을 얻어야합니다. 내가 도움이 되었기 때문에 어떤 도움을 주셔서 감사합니다.FPDF에서 이익 합계를 계산하십시오.
$result = mysqli_query($connection, "SELECT S.sales_id, I.item_name, ST.stock_code,
S.date, S.unit_price, SUM(S.qty), (SUM(S.qty)*S.unit_price),
((SUM(S.qty)*S.unit_price)-(SUM(S.qty)*P.unit_cost)) FROM sales S
INNER JOIN items I ON S.item_id=I.item_id
INNER JOIN stock ST ON S.stock_id=ST.stock_id
INNER JOIN purchase_items P ON S.purchase_id=P.purchase_id
WHERE S.date BETWEEN '$date 00:00:00' AND '$date 23:59:59' GROUP BY S.item_id");
$qty = $row['SUM(S.qty)'];
$unit_price = $row['unit_price'];
$amount = $row['(SUM(S.qty)*S.unit_price)'];
$profit = $row['((SUM(S.qty)*S.unit_price)-(SUM(S.qty)*P.unit_cost))'];
$dailyProfit = $row['(SUM(SUM(S.qty)*S.unit_price)-(SUM(S.qty)*P.unit_cost)))'];
$pdf->Cell(25,10,$dailyProfit,'B',0,'J',1);
이 지난 항목의 profit
, 어떻게이 매일 sum(profit)
를 얻기 위해 수정해야 만 하나 개의 레코드를 검색?
업데이트 코드
$result = mysqli_query($connection, "SELECT S.sales_id, I.item_name, ST.stock_code, S.date,
S.unit_price, SUM(S.qty) AS line_qty, (SUM(S.qty)*S.unit_price) AS line_total,
((SUM(S.qty)*S.unit_price)-(SUM(S.qty)*P.unit_cost)) AS line_profit
FROM sales S
INNER JOIN items I ON S.item_id=I.item_id
INNER JOIN stock ST ON S.stock_id=ST.stock_id
INNER JOIN purchase_items P ON S.purchase_id=P.purchase_id
WHERE S.date BETWEEN '$date 00:00:00' AND '$date 23:59:59' GROUP BY S.item_id");
$qty = $row['line_qty'];
$unit_price = $row['unit_price'];
$amount = $row['line_total'];
$profit = $row['line_profit'];
$aRows = array();
while ($oRow = mysqli_fetch_assoc($result)) $aRows[] = $oRow;
mysqli_free_result($result);
$dTotalProfit = 0;
if (count($aRows) > 0) foreach ($aRows as $aRow) {
$dTotalProfit += $aRow['line_profit'];
//$pdf->Cell(25, 10, $aRow['line_qty'], 'B', 0, 'J', 1);
}
$totalProfit = number_format($dTotalProfit, 2);
$pdf->Cell(220, 10, 'Daily Total Profit:', 'B', 0, 'R', 1);
$pdf->Cell(25, 10, $totalProfit, 'B', 0, 'J', 1);
그리고 지금까지 시도한 것을 보여주는 코드가 있습니까? – Kitson88
아, 미안해 .... 이제 볼 수있어. – Kitson88
나는 당신이 그 item_id에 의해 그룹을한다고 생각한다. 그 특정 아이템을 기반으로하는 하나의 레코드의 결과를 얻는다. 그래서 array_sum()을 사용하여 하루 종일 이익을 계산해야한다. – jilesh