打印收据PHP

时间:2018-04-03 01:00:18

标签: php html fpdf

我有一个工作的PHP表单,它还有一个按钮,可以打开一个窗口,从帐户中收取费用。

是否可以设置自动打印功能,只要表单处理完成,用户就会进入打印屏幕。我能找到的唯一解决方案是打印整个屏幕,但我更愿意自己设计收据。 FPDF会在这方面工作吗?

以下是Fees.php表单代码:

<link rel="shortcut icon" href="img/icon.ico" type="image/x-icon"/>
<?php
include("php/dbconnect.php");

$errormsg= '';
if(isset($_POST['save']))
{
$paid = mysqli_real_escape_string($conn,$_POST['paid']);
$submitdate = mysqli_real_escape_string($conn,$_POST['submitdate']);
$transcation_remark = 
mysqli_real_escape_string($conn,$_POST['transcation_remark']);
$sid = mysqli_real_escape_string($conn,$_POST['sid']);

$sql = "select fees,balance  from student where id = '$sid'";
$sq = $conn->query($sql);
$sr = $sq->fetch_assoc();
$totalfee = $sr['fees'];
if($sr['balance']>0)
{
$sql = "insert into 
fees_transaction(stdid,submitdate,transcation_remark,paid) 
values('$sid','$submitdate','$transcation_remark','$paid') ";
$conn->query($sql);
$sql = "SELECT sum(paid) as totalpaid FROM fees_transaction WHERE stdid = '$sid'";
$tpq = $conn->query($sql);
$tpr = $tpq->fetch_assoc();
$totalpaid = $tpr['totalpaid'];
$tbalance = $totalfee - $totalpaid;

$sql = "update student set balance='$tbalance' where id = '$sid'";
$conn->query($sql);

echo '<script type="text/javascript">window.location="fees.php?act=1";</script>';
}
}

if(isset($_REQUEST['act']) && @$_REQUEST['act']=="1")
{
$errormsg = "<div class='alert alert-success'><a href='#' class='close' 
data-dismiss='alert' aria-label='close'>&times;</a><strong>Success!</strong> 
Fees submit successfully</div>";
}

?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Accounts | iBroker Finance</title>

<!-- BOOTSTRAP STYLES-->
<link href="css/bootstrap.css" rel="stylesheet" />
<!-- FONTAWESOME STYLES-->
<link href="css/font-awesome.css" rel="stylesheet" />
   <!--CUSTOM BASIC STYLES-->
<link href="css/basic.css" rel="stylesheet" />
<!--CUSTOM MAIN STYLES-->
<link href="css/custom.css" rel="stylesheet" />
<!-- GOOGLE FONTS-->
<link href='http://fonts.googleapis.com/css?family=Open+Sans' 
rel='stylesheet' type='text/css' />

<link href="css/ui.css" rel="stylesheet" />
<link href="css/jquery-ui-1.10.3.custom.min.css" rel="stylesheet" />    
<link href="css/datepicker.css" rel="stylesheet" /> 
   <link href="css/datatable/datatable.css" rel="stylesheet" />

<script src="js/jquery-1.10.2.js"></script> 
<script type='text/javascript' src='js/jquery/jquery-ui-1.10.1.custom.min.js'></script>
<script type="text/javascript" src="js/validation/jquery.validate.min.js"> 
</script>

     <script src="js/dataTable/jquery.dataTables.min.js"></script>



</head>
<?php
include("php/header.php");
?>
    <div id="page-wrapper">
        <div id="page-inner">
            <div class="row">
                <div class="col-md-12">
                    <h1 class="page-head-line">Manage Accounts 

                    </h1>

                </div>
            </div>



    <?php
    echo $errormsg;
    ?>



<div class="row" style="margin-bottom:20px;">
<div class="col-md-12">
<fieldset class="scheduler-border" >
<legend  class="scheduler-border">Search:</legend>
<form class="form-inline" role="form" id="searchform">
<div class="form-group">
<label for="email">Name</label>
 <input type="text" class="form-control" id="student" name="student">
</div>

<div class="form-group">
<label for="email"> Date Of Joining </label>
<input type="text" class="form-control" id="doj" name="doj" >
</div>

<div class="form-group">
<label for="email"> Branch </label>
<select  class="form-control" id="branch" name="branch" >
    <option value="" >Select Branch</option>
                                <?php
                                $sql = "select * from branch where delete_status='0' order by branch.branch asc";
                                $q = $conn->query($sql);

                                while($r = $q->fetch_assoc())
                                {
                                echo '<option value="'.$r['id'].'"  '.(($branch==$r['id'])?'selected="selected"':'').'>'.$r['branch'].'</option>';
                                }
                                ?>
 </select>
</div>

<button type="button" class="btn btn-success btn-sm" id="find" > Find 
</button>
<button type="reset" class="btn btn-danger btn-sm" id="clear" > Clear 
</button>
</form>
</fieldset>

</div>
</div>

<script type="text/javascript">
$(document).ready( function() {

/*
$('#doj').datepicker( {
    changeMonth: true,
    changeYear: true,
    showButtonPanel: false,
    dateFormat: 'mm/yy',
    onClose: function(dateText, inst) { 
        $(this).datepicker('setDate', new Date(inst.selectedYear, 
inst.selectedMonth, 1));
    }
});

*/

/******************/    
 $("#doj").datepicker({

    changeMonth: true,
    changeYear: true,
    showButtonPanel: true,
    dateFormat: 'mm/yy',
    onClose: function(dateText, inst) {
        var month = $("#ui-datepicker-div .ui-datepicker-month 
:selected").val();
        var year = $("#ui-datepicker-div .ui-datepicker-year 
:selected").val();
        $(this).val($.datepicker.formatDate('MM yy', new Date(year, month, 
1)));
    }
});

$("#doj").focus(function () {
    $(".ui-datepicker-calendar").hide();
    $("#ui-datepicker-div").position({
        my: "center top",
        at: "center bottom",
        of: $(this)
    });
});

/*****************/

$('#student').autocomplete({
            source: function( request, response ) {
                $.ajax({
                    url : 'ajx.php',
                    dataType: "json",
                    data: {
                       name_startsWith: request.term,
                       type: 'studentname'
                    },
                     success: function( data ) {

                         response( $.map( data, function( item ) {

                            return {
                                label: item,
                                value: item
                            }
                        }));
                    }



                });
            }
            /*,
            autoFocus: true,
            minLength: 0,
             select: function( event, ui ) {
                      var abc = ui.item.label.split("-");
                      //alert(abc[0]);
                       $("#student").val(abc[0]);
                       return false;

                      },
             */



          });


$('#find').click(function () {
mydatatable();
    });


$('#clear').click(function () {

$('#searchform')[0].reset();
mydatatable();
    });

function mydatatable()
{

          $("#subjectresult").html('<table class="table table-striped table-bordered table-hover" id="tSortable22"><thead><tr><th>Name/Contact</th> <th>Premium Amount Incl Stamp Fee</th><th>Oustanding</th><th>Branch</th><th>Joining Date</th><th>Action</th></tr></thead><tbody></tbody></table>');

            $("#tSortable22").dataTable({
                              'sPaginationType' : 'full_numbers',
                             "bLengthChange": false,
              "bFilter": false,
              "bInfo": false,
                               'bProcessing' : true,
                               'bServerSide': true,
                               'sAjaxSource': 
"datatable.php?"+$('#searchform').serialize()+"&type=feesearch",
                               'aoColumnDefs': [{
                               'bSortable': false,
                               'aTargets': [-1] /* 1st one, start by the 
right */
                                            }]
                               });


}

////////////////////////////
$("#tSortable22").dataTable({

              'sPaginationType' : 'full_numbers',
              "bLengthChange": false,
              "bFilter": false,
              "bInfo": false,

              'bProcessing' : true,
              'bServerSide': true,
              'sAjaxSource': "datatable.php?type=feesearch",

              'aoColumnDefs': [{
              'bSortable': false,
              'aTargets': [-1] /* 1st one, start by the right */
          }]
        });

///////////////////////////     



});


function GetFeeForm(sid)
{

$.ajax({
        type: 'post',
        url: 'getfeeform.php',
        data: {student:sid,req:'1'},
        success: function (data) {
          $('#formcontent').html(data);
          $("#myModal").modal({backdrop: "static"});
        }
      });


}

</script>




<style>
#doj .ui-datepicker-calendar
 {
display:none;
}

</style>

    <div class="panel panel-default">
                    <div class="panel-heading">
                        Account Management  
                    </div>
                    <div class="panel-body">
                        <div class="table-sorting table-responsive" 
id="subjectresult">
                            <table class="table table-striped table-bordered 
table-hover" id="tSortable22">
                                <thead>
                                    <tr>

                                        <th>Name/Payment Plan</th>                                            
                                        <th>Premium Amount Incl Stamp 
Fee</th>
                                        <th>Outstanding</th>
                                        <th>Insurer</th>
                                        <th>Joining Date</th>
                                        <th>Action</th>
                                    </tr>
                                </thead>
                                <tbody>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>


<!-------->

<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog modal-lg">
  <div class="modal-content">
    <div class="modal-header">
       <button type="button" class="close" data-dismiss="modal">&times; 
</button>
      <h4 class="modal-title">Take Fee</h4>
    </div>
    <div class="modal-body" id="formcontent">

    </div>
    <div class="modal-footer">
      <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
    </div>
  </div>
</div>
</div>


<!--------->


        </div>
        <!-- /. PAGE INNER  -->
    </div>
    <!-- /. PAGE WRAPPER  -->
</div>
<!-- /. WRAPPER  -->

<div id="footer-sec">
  iBroker Finance System | Developed By Siyakha Technology
</div>


<!-- BOOTSTRAP SCRIPTS -->
<script src="js/bootstrap.js"></script>
<!-- METISMENU SCRIPTS -->
<script src="js/jquery.metisMenu.js"></script>
   <!-- CUSTOM SCRIPTS -->
<script src="js/custom1.js"></script>


</body>
</html>

1 个答案:

答案 0 :(得分:0)

对于打印样式,请使用print媒体查询

@media print {
    body {
        background-color: lightgreen;
    }
}

另一种方法是将现有的css文件与print media属性链接

<link rel="stylesheet" type="text/css" media="print" href="print.css">

对于自动打印,只需在js代码中使用window.print()