$totalsw = $totalsw + $result['totalsewa'];
    $totalbyr = $totalbyr + $result['totalbayar'];
    $totalsisa = $totalsisa + $result['sisakekurangan'];
}
$pdf->SetFont('Arial', 'B', 9);
$pdf->SetWidths(array(20.5, 2.6, 2.6, 2.6));
$pdf->Row(array("SUBTOTAL", number_format($totalsw, 0, ',', '.') . ",-", number_format($totalbyr, 0, ',', '.') . ",-", number_format($totalsisa, 0, ',', '.') . ",-"));
$pdf->SetWidths(array(28.3));
$pdf->Row(array("SEWA KENDARAAN NON RETAIL"));
$pdf->SetFont('Arial', '', 9);
$pdf->SetWidths(array(2.3, 2.5, 2.5, 2.5, 3.7, 2.2, 2.2, 2.6, 2.6, 2.6, 2.6));
$pdf->SetHeight(0.1);
$pdf->SetAligns(array('C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C'));
$query_datakorporate = $getquerykorporate;
$querykorp = mysql_query($query_datakorporate) or die("Query gagal");
while ($resultkorp = mysql_fetch_array($querykorp)) {
    $pdf->Row(array($resultkorp['marketing'], DateToIndoAngka($resultkorp['mulai']), $resultkorp['no_ref'], $resultkorp['kendaraan'], $resultkorp['merk'] . '-' . $resultkorp['tipekendaraan'], DateToIndoAngka($resultkorp['mulai']), DateToIndoAngka($resultkorp['sampai']), $resultkorp['nama'], number_format($resultkorp['total'], 0, ',', '.') . ",-", number_format($resultkorp['totalbayar'], 0, ',', '.') . ",-", number_format($resultkorp['sisakekurangan'], 0, ',', '.') . ",-"));
    $totalswkorporate = $totalswkorporate + $resultkorp['total'];
    $totalbyrkorporate = $totalbyrkorporate + $resultkorp['totalbayar'];
    $totalsisakorporate = $totalsisakorporate + $resultkorp['sisakekurangan'];
}
$pdf->SetFont('Arial', 'B', 9);
$pdf->SetWidths(array(20.5, 2.6, 2.6, 2.6));
$pdf->Row(array("SUBTOTAL", number_format($totalswkorporate, 0, ',', '.') . ",-", number_format($totalbyrkorporate, 0, ',', '.') . ",-", number_format($totalsisakorporate, 0, ',', '.') . ",-"));
$pdf->SetWidths(array(28.3));
$pdf->Row(array(""));
$pdf->SetWidths(array(20.5, 2.6, 2.6, 2.6));
$pdf->SetFont('Arial', 'B', 10);
$pdf->Row(array("GRAND TOTAL", number_format($totalsw + $totalswkorporate, 0, ',', '.') . ",-", number_format($totalbyr + $totalbyrkorporate, 0, ',', '.') . ",-", number_format($totalsisa + $totalsisakorporate, 0, ',', '.') . ",-"));
$pdf->Ln();
$pdf->Output('Laporan Hasil Sewa Cabang ' . $gudang . ' Periode ' . DateToIndo($mulai) . " - " . DateToIndo($akhir) . '.pdf', 'D');
    $totaloperasional += $result['operasional'];
    $total += $result['total'];
}
$pdf->SetFont('Arial', 'B', 9);
$pdf->SetWidths(array(14.5, 2.2, 2.6, 2.3, 2.6, 2.6, 2.6, 2.6, 2.6));
$pdf->Row(array("SUBTOTAL", number_format($totalangsuran, 0, ',', '.') . ",-", number_format($totaluangmuka, 0, ',', '.') . ",-", "0,-", "0,-", number_format($totaltunai, 0, ',', '.') . ",-", number_format($totaltrasfer, 0, ',', '.') . ",-", number_format($totaloperasional, 0, ',', '.') . ",-", number_format($total, 0, ',', '.') . ",-"));
$pdf->SetWidths(array(34.6));
$pdf->Row(array("SEWA KENDARAAN NON RETAIL (CORPORATE)"));
$pdf->SetFont('Arial', '', 9);
$pdf->SetWidths(array(2.3, 2.5, 2.5, 2.5, 2.5, 2.2, 2.2, 2.6, 2.3, 2.6, 2.6, 2.6, 2.6, 2.6));
$pdf->SetHeight(0.1);
$pdf->SetAligns(array('C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C'));
$query_datakorporate = $getquerykorporate;
$querykorp = mysql_query($query_datakorporate) or die("Query gagal");
while ($resultkorp = mysql_fetch_array($querykorp)) {
    $pdf->Row(array($resultkorp['user'], $resultkorp['customer'], $resultkorp['no_ref'], DateToIndoAngka($resultkorp['periodeawal']), DateToIndoAngka($resultkorp['periodeakhir']), $resultkorp['kendaraan'], number_format($resultkorp['angsuran'], 0, ',', '.') . ",-", number_format($resultkorp['uangmuka'], 0, ',', '.') . ",-", "0,-", "0,-", number_format($resultkorp['tunai'], 0, ',', '.') . ",-", number_format($resultkorp['transfer'], 0, ',', '.') . ",-", number_format($resultkorp['operasional'], 0, ',', '.') . ",-", number_format($resultkorp['total'], 0, ',', '.') . ",-"));
    $totalangsurankorporate += $resultkorp['angsuran'];
    $totaluangmukakorporate += $resultkorp['uangmuka'];
    $totaltrasferkorporate += $resultkorp['transfer'];
    $totaltunaikorporate += $resultkorp['tunai'];
    $totaloperasionalkorporate += $resultkorp['operasional'];
    $totalkorporate += $resultkorp['total'];
}
$pdf->SetFont('Arial', 'B', 9);
$pdf->SetWidths(array(14.5, 2.2, 2.6, 2.3, 2.6, 2.6, 2.6, 2.6, 2.6));
$pdf->Row(array("SUBTOTAL", number_format($totalangsurankorporate, 0, ',', '.') . ",-", number_format($totaluangmukakorporate, 0, ',', '.') . ",-", "0,-", "0,-", number_format($totaltunaikorporate, 0, ',', '.') . ",-", number_format($totaltrasferkorporate, 0, ',', '.') . ",-", number_format($totaloperasionalkorporate, 0, ',', '.') . ",-", number_format($totalkorporate, 0, ',', '.') . ",-"));
$pdf->SetWidths(array(34.6));
$pdf->Row(array(""));
$pdf->SetWidths(array(14.5, 2.2, 2.6, 2.3, 2.6, 2.6, 2.6, 2.6, 2.6));
$pdf->SetFont('Arial', 'B', 10);
$pdf->Row(array("GRAND TOTAL", number_format($totalangsuran + $totalangsurankorporate, 0, ',', '.') . ",-", number_format($totaluangmuka + $totaluangmukakorporate, 0, ',', '.') . ",-", "0,-", "0,-", number_format($totaltunai + $totaltunaikorporate, 0, ',', '.') . ",-", number_format($totaltrasfer + $totaltrasferkorporate, 0, ',', '.') . ",-", number_format($totaloperasional + $totaloperasionalkorporate, 0, ',', '.') . ",-", number_format($total + $totalkorporate, 0, ',', '.') . ",-"));