Batch Printing

Hi All,

Is there a way to make batch print on selected IDs in Yii?

eg: I have a page (view) called invoice, which displays the information about selected invoice. With Window Print option I can print this particular invoice.

Now I need to select several invoices ( by check boxes) and print them all by single button click.

I search Yii forums as well as some Javascript forums but couldn’t get any idea yet.

Thanks.

Hi

please give us more details how to print a particular invoice

Also tell us if all invoices information loaded in one request

Hi KonApaz,

Thanks for the reply.

I used javascript to print the div content of invoice as follows.

  1. Call to view from controller

    public function actionPrintinvoice($id) {

      

        $this->render('printinvoice', array(

            'model' => $this->loadModel($id, 'Order'),

        ));

    }

  1. View : Print invoice with Print Button and javascript



<script language="javascript">

function printDiv(divName) {

     var printContents = document.getElementById(divName).innerHTML;

     var originalContents = document.body.innerHTML;


     document.body.innerHTML = printContents;


     window.print();


     document.body.innerHTML = originalContents;

}

</script>


<div valign="top" align="right"><input type="button" onclick="printDiv('printinvoice')" value="Print" /></div>




<div id="printinvoice" >

<?php

//Content 

?>

</div>



I couldn’t get your 2nd question, “Also tell us if all invoices information loaded in one request”.

What I need is select number of invoices from a list of invoices (from a gridview with check boxes) and print all selected invoices.

Thanks,

I suppose you have many divs like that


<div valign="top" align="right"><input type="button" onclick="printDiv('printinvoice1')" value="Print" /></div>

<div valign="top" align="right"><input type="button" onclick="printDiv('printinvoice2')" value="Print" /></div>

<div valign="top" align="right"><input type="button" onclick="printDiv('printinvoice3')" value="Print" /></div>


<div id="printinvoice1" >

<?php 

//Content invoice1

?>

</div>


<div id="printinvoice2" >

<?php

//Content invoice2

?>

</div>


<div id="printinvoice3" >

<?php

//Content invoice3

?>

</div>

My second question was about that, if all invoices information exists in the current page (like above).

If it is true you have to make a concatenation (by javascript) of selected invoices and put this content in one on the fly div (for example selectedInvoices) and then call printDiv(selectedInvoices)

Thanks again KonApaz.

I never thought to have a div per invoice. Currently just view one invoice at one time and print it as explained above.

That means all invoices are not exist in the current page.

But thanks for the idea of using on the fly div. Since it is the best solution I found yet.

Also you could achieved that by ajax request for all selected invoices (calling on the print button) but it easier as I suggested you in the previous post :)

Agree. I’ll test this and comeback with result.

Thank you again.