mysql - Improvement to PHP Code to Generate Table and export to mPDF -


how possibly re-code run faster display table follows:

image 1

image 2

this code runs after getting specific period here:

(input::get('start') !== '' && input::get('end') !== '') 

then gets data table of $codes here:

$codes = db::getinstance()->query("select * code order code asc"); 

after that, checks existing $transactions tracing id of $codes here:

$items1 = db::getinstance()->query("select * transactions order code asc"); foreach($items1->results() $item1) { $date = strtotime($item1->transaction_date); if($date >= $datestart && $date <= $dateend)  { if($code->id === $item1->account) { 

this whole code:

<?php if(input::get('start') !== '' && input::get('end') !== '') { ?> <!-- main content --> <section class="content invoice"> <!-- title row --> <div class="row"> <div class="col-md-6 text-left-custom pull-left"> <h3> malaybalay city water district <br> <small>sumpong, sayre highway</small> <br> <small>malaybalay city, bukidnon</small> <br> </h3> </div><!-- /.col --> <h4 class="page-header"> <small class="pull-right">date: <?php echo date('f d, y');?></small> </h4> </div> <!-- info row --> <div class="row invoice-info font-l"> <div class="col-sm-12 invoice-col text-center-custom"> <h3><b>report on stocks , supplies count</b></h3> <h4>as of <b><?php echo escape(date("f y",$dateend)); ?></b></h4></br> </div><!-- /.col --> <hr> </div><!-- /.row -->  <!-- table row -->  <div class="row"> <div class="col-xs-12 table-responsive"> <table class="table table-striped table-condensed font-m" id="report_transactions_table"> <thead> <tr> <th style="text-align: center;">transaction date<br/><i>(yyyy-mm-dd)</i></th> <th style="text-align: center;">transaction type</th> <th style="text-align: center;">division</th> <th style="text-align: center;">quantity</th> <th style="text-align: center;">cost</th> <th style="text-align: center;">balance</th> <th style="text-align: center;">remarks</th> </tr> </thead> <tbody> <?php $grandtotal = 0; $codes = db::getinstance()->query("select * code order code asc"); foreach($codes->results() $code) { if($code->id >= 45){ $count1 = 0; $count2 = 0; $total = 0; $counter_code = 0;  $items1 = db::getinstance()->query("select * transactions order code asc"); foreach($items1->results() $item1) { $date = strtotime($item1->transaction_date); if($date >= $datestart && $date <= $dateend)  { if($code->id === $item1->account) { $counter_code = $counter_code + 1; } } } if($counter_code){ ?> <tr> <td colspan="8" style="text-align: left; vertical-align: middle;"><b><?php echo $code->code . " (".$code->description.")"; ?></b></td> </tr>  <?php }  $supplies = db::getinstance()->query("select * supplies order code asc"); foreach($supplies->results() $supply) { if($supply->account === $code->id){ $counter_supplies = 0; $items2 = db::getinstance()->query("select * transactions order code asc"); foreach($items2->results() $item2) { $date = strtotime($item2->transaction_date); if($date >= $datestart && $date <= $dateend)  { if($supply->id === $item2->code) { $counter_supplies = $counter_supplies + 1; } } }  if($counter_supplies){ ?>  <tr> <td colspan="8" style="text-align: left; vertical-align: middle;"><?php echo $code->code ."-". $supply->code . " (".$supply->description.")"; ?></td> </tr> <tr> <td style="text-align: left; vertical-align: middle;"><b>beginning balance</b></td> <td style="text-align: center; vertical-align: middle;">--</td> <td style="text-align: center; vertical-align: middle;">--</td> <td style="text-align: center; vertical-align: middle;">--</td> <td style="text-align: center; vertical-align: middle;">--</td> <td style="text-align: center; vertical-align: middle;"><b> <?php $beg = 0; $items = db::getinstance()->query("select * transactions order id asc"); foreach($items->results() $item) { $date = strtotime($item->transaction_date); if($date < $datestart)  { if(($code->id === $item->account) && ($supply->id === $item->code)){ if($item->transaction_type === "1"){ $beg = $beg + $item->quantity;  } else if($item->transaction_type === "2"){ $beg = $beg - $item->quantity;  } else if($item->transaction_type === "3"){ $beg = $beg + $item->quantity;  } } } } echo $beg; ?> </b></td> <td style="text-align: center; vertical-align: middle;"></td> </tr>   <?php  } $beginning = 0; $balance = 0; $trans = db::getinstance()->query("select * transactions order id asc"); foreach($trans->results() $tran) { $date = strtotime($tran->transaction_date); if($date < $datestart)  { if(($code->id === $tran->account) && ($supply->id === $tran->code)){ if($tran->transaction_type === "1"){ $beginning = $beginning + $tran->quantity;  } else if($tran->transaction_type === "2"){ $beginning = $beginning - $tran->quantity;  } else if($tran->transaction_type === "3"){ $beginning = $beginning + $tran->quantity;  } } } } $balance = $balance + $beginning; $transactions = db::getinstance()->query("select * transactions order transaction_date asc"); foreach($transactions->results() $transaction) { $date = strtotime($transaction->transaction_date); if($date >= $datestart && $date <= $dateend)  { if(($code->id === $transaction->account) && ($supply->id === $transaction->code)){ $count2 = $count2 + 1; //$total = $total + $transaction->unit_value; ?> <tr> <td style="text-align: center; vertical-align: middle;"><?php echo $transaction->transaction_date; ?></td> <td style="text-align: center; vertical-align: middle;"> <?php  if($transaction->transaction_type === "1"){ echo "receipt"; } else if($transaction->transaction_type === "2"){ echo "issuance"; } else if($transaction->transaction_type === "3"){ echo "return"; } ;?> </td> <td style="text-align: center; vertical-align: middle;"> <?php  if($transaction->division === "afd"){ echo "administrative/finance";  } else if($transaction->division === "csd"){ echo "commercial services"; } else if($transaction->division === "epd"){ echo "engineering/production"; } ?> </td> <td style="text-align: center; vertical-align: middle;"> <?php  if($transaction->transaction_type === "1"){ echo $transaction->quantity;  } else if($transaction->transaction_type === "2"){ echo "(".$transaction->quantity.")"; } else if($transaction->transaction_type === "3"){ echo $transaction->quantity; }  ?> </td> <td style="text-align: center; vertical-align: middle;"><?php if($transaction->cost===""){ echo ""; } else { echo number_format($transaction->cost,2);} ?></td> <td style="text-align: center; vertical-align: middle;"> <?php  if($transaction->transaction_type === "1"){ echo $balance = $balance + $transaction->quantity;  } else if($transaction->transaction_type === "2"){ echo $balance = $balance - $transaction->quantity;  } else if($transaction->transaction_type === "3"){ echo $balance = $balance + $transaction->quantity;  } ?> </td> <td style="text-align: center; vertical-align: middle;"><?php echo $transaction->remarks; ?></td> </tr> <?php $count1 = $count1 + 1; } } }  } } } }  ?> </tbody>  </table> </div><!-- /.col --> </div><!-- /.row --> <hr style="border-top: 2px solid black;"> </br> </br>   <!-- row not atransactionar when printing --> <!--div class="row no-print"> <div class="col-xs-12"> <button class="btn btn-default" onclick="window.print();"><i class="fa fa-print"></i> print</button> <button class="btn btn-success pull-right"><i class="fa fa-credit-card"></i> submit payment</button> <button class="btn btn-primary pull-right" style="margin-right: 5px;"><i class="fa fa-download"></i> generate pdf</button> </div> </div--> </section><!-- /.content -->  <?php } ?> 

also, mpdf runs when handling small rows, cannot handle table mentioned above since same running on same codes.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -