« Back to History
purchase_report.php
|
20260721_154033.php
Initial Bulk Import
Copy Code
<?php require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('purchase_entry'); $pdo = $ctx['pdo']; $company_id = (int)$ctx['company_id']; require_once __DIR__ . '/lib/dompdf/autoload.inc.php'; use Dompdf\Dompdf; $from = $_GET['from'] ?? ''; $to = $_GET['to'] ?? ''; $party = $_GET['party'] ?? ''; $status = $_GET['status'] ?? ''; $pdf = $_GET['pdf'] ?? ''; /* ===== QUERY ===== */ $sql = "SELECT * FROM purchase_entry WHERE company_id=?"; $params = [$company_id]; if($from!=''){ $sql.=" AND purchase_date>=?"; $params[]=$from; } if($to!=''){ $sql.=" AND purchase_date<=?"; $params[]=$to; } if($party!=''){ $sql.=" AND party_name=?"; $params[]=$party; } if($status!=''){ $sql.=" AND verification_status=?"; $params[]=$status; } $sql.=" ORDER BY purchase_date DESC"; $stm=$pdo->prepare($sql); $stm->execute($params); $data=$stm->fetchAll(); /* ===== TOTALS ===== */ $total_purchase=0; $total_verified=0; $total_unverified=0; foreach($data as $r){ $total_purchase += $r['total_amount']; if($r['verification_status']=='verified'){ $total_verified += $r['total_amount']; }else{ $total_unverified += $r['total_amount']; } } /* ===== PDF EXPORT ===== */ if($pdf==1){ $html=' <h2>Purchase Report</h2> <p> Total Purchase: '.number_format($total_purchase,2).'<br> Verified: '.number_format($total_verified,2).'<br> Unverified: '.number_format($total_unverified,2).' </p> <table border="1" width="100%" cellpadding="6"> <tr> <th>ID</th> <th>Date</th> <th>Party</th> <th>Challan</th> <th>Bill</th> <th>Item</th> <th>Qty</th> <th>Amount</th> <th>Status</th> </tr>'; foreach($data as $r){ $vs = $r['verification_status']=='verified'?'Verified':'Unverified'; $html.=' <tr> <td>'.$r['purchase_id'].'</td> <td>'.$r['purchase_date'].'</td> <td>'.$r['party_name'].'</td> <td>'.$r['challan_no'].'</td> <td>'.$r['bill_no'].'</td> <td>'.$r['item_name'].'</td> <td>'.$r['quantity'].'</td> <td>'.number_format($r['total_amount'],2).'</td> <td>'.$vs.'</td> </tr>'; } $html.='</table>'; $dompdf=new Dompdf(); $dompdf->loadHtml($html); $dompdf->setPaper('A4','landscape'); $dompdf->render(); $dompdf->stream("purchase_report.pdf",["Attachment"=>0]); exit; } require_once __DIR__ . '/partials/header.php'; /* ===== PARTY LIST ===== */ $stm=$pdo->prepare(" SELECT party_name FROM party_master WHERE company_id=? AND is_active=1 ORDER BY party_name "); $stm->execute([$company_id]); $party_list=$stm->fetchAll(); ?> <div class="container-fluid mt-4 px-4"> <h4>Purchase Report</h4> <div class="row mb-3"> <div class="col-md-4"> <div class="alert alert-info mb-0"> Total Purchase: <?=number_format($total_purchase,2)?> </div> </div> <div class="col-md-4"> <div class="alert alert-success mb-0"> Verified: <?=number_format($total_verified,2)?> </div> </div> <div class="col-md-4"> <div class="alert alert-warning mb-0"> Unverified: <?=number_format($total_unverified,2)?> </div> </div> </div> <form class="row g-3 mb-3"> <div class="col-md-2"> <label class="form-label">From</label> <input type="date" name="from" value="<?=$from?>" class="form-control"> </div> <div class="col-md-2"> <label class="form-label">To</label> <input type="date" name="to" value="<?=$to?>" class="form-control"> </div> <div class="col-md-3"> <label class="form-label">Party</label> <select name="party" class="form-select"> <option value="">All Party</option> <?php foreach($party_list as $p){ ?> <option value="<?=$p['party_name']?>" <?php if($party==$p['party_name']) echo "selected";?>> <?=$p['party_name']?> </option> <?php } ?> </select> </div> <div class="col-md-2"> <label class="form-label">Status</label> <select name="status" class="form-select"> <option value="">All</option> <option value="verified" <?php if($status=='verified') echo "selected";?>> Verified </option> <option value="unverified" <?php if($status=='unverified') echo "selected";?>> Unverified </option> </select> </div> <div class="col-md-1 d-flex align-items-end"> <button class="btn btn-primary w-100">Search</button> </div> <div class="col-md-1 d-flex align-items-end"> <button type="button" onclick="window.print()" class="btn btn-dark w-100"> Print </button> </div> <div class="col-md-1 d-flex align-items-end"> <a href="?pdf=1&from=<?=$from?>&to=<?=$to?>&party=<?=$party?>&status=<?=$status?>" class="btn btn-danger w-100"> PDF </a> </div> </form> <div class="table-responsive"> <table class="table table-bordered table-striped table-hover w-100"> <thead class="table-light"> <tr> <th>ID</th> <th>Date</th> <th>Party</th> <th>Challan</th> <th>Bill</th> <th>Item</th> <th>Qty</th> <th>Amount</th> <th>Status</th> <th>Video</th> </tr> </thead> <tbody> <?php foreach($data as $row){ ?> <tr> <td><?=$row['purchase_id']?></td> <td><?=$row['purchase_date']?></td> <td><?=$row['party_name']?></td> <td><?=$row['challan_no']?></td> <td><?=$row['bill_no']?></td> <td><?=$row['item_name']?></td> <td><?=$row['quantity']?></td> <td><?=number_format($row['total_amount'],2)?></td> <td> <?php if($row['verification_status']=='verified'){ ?> <span class="badge bg-success">Verified</span> <?php }else{ ?> <span class="badge bg-warning text-dark">Unverified</span> <?php } ?> </td> <td> <?php if($row['video_path']){ ?> <a href="<?=$row['video_path']?>" target="_blank" class="btn btn-sm btn-success"> Play </a> <?php } ?> </td> </tr> <?php } ?> </tbody> </table> </div> </div> <?php require_once __DIR__ . '/partials/footer.php'; ?>