public function generate_order_report() { $data_type = $_POST['type_of_data']; $duration = $_POST['duration']; $year = $_POST['year_from']; $report_type = $_POST['type_of_report']; $title = 'test'; $report_name = "Order Report For" . $year; $facility_code = $this->session->userdata('news'); $from_ordertbl = Ordertbl::get_facilitiy_orders($facility_code); $facility_name = Facilities::get_facility_name($facility_code); /**************************************set the style for the table****************************************/ $html_data = '<style>table.data-table {border: 1px solid #DDD;margin: 10px auto;border-spacing: 0px;} table.data-table th {border: none;color: #036;text-align: center;background-color: #F5F5F5;border: 1px solid #DDD;border-top: none;max-width: 450px;} table.data-table td, table th {padding: 4px;} table.data-table td {border: none;border-left: 1px solid #DDD;border-right: 1px solid #DDD;height: 30px;margin: 0px;border-bottom: 1px solid #DDD;} .col5{background:#D8D8D8;}</style>'; //create the report based on the request of the user /**********bug detected mpdf cannot print a report that has nesteded loops the solution is to create the html body before creating the mpdf object****/ $html_data1 = ''; // order analysis $html_data2 = ''; // raw order details foreach ($from_ordertbl as $infor_array) { //setting up the variables $total_item_received = 0; $total_item_ordered = 0; $date = $infor_array->orderDate; $draw = $infor_array->drawing_rights; $total = $infor_array->orderTotal; $bal = number_format($draw - $total, 2, '.', ','); /*****************************setting up the report*******************************************/ $html_data1 .= '<table class="data-table"><thead> <tr><td colspan="16"><p style="font-weight: bold;">Facility Order No: ' . $infor_array->id . ' | KEMSA Order No: ' . $infor_array->kemsaOrderid . ' | Order Date:' . $date . ' | Order Total: ' . number_format($total, 2, '.', ',') . ' | Drawing rights: ' . number_format($draw, 2, '.', ',') . ' | Balance(Drawing rights - Order Total):' . $bal . ' </p></span></td></tr> <tr> <th><strong>KEMSA Code</strong></th><th><strong>Description</strong></th><th><strong>Quantity Ordered</strong></th><th><strong>Unit Cost</strong></th><th class="col5" ><strong><b>Total Cost</b></strong></th> <th><strong>Quantity Ordered</strong></th><th><strong>Quantity Received</strong></th><th class="col5" ><strong><b>Fill rate</b></strong></th> <th><strong><b>Opening Balance</b></strong></th> <th><strong><b>Total Receipts</b></strong></th> <th><strong><b>Total Issues</b></strong></th> <th><strong><b>ADJ</b></strong></th> <th><strong><b>Losses</b></strong></th> <th><strong><b>Closing Stock</b></strong></th> <th><strong><b>Days Out Of stock</b></strong></th> <th><strong><b>Comment</b></strong></th> </tr> </thead><tbody>'; /***********************************************************************************************/ $html_data2 .= '<table class="data-table"><thead> <tr><td colspan="16"><p style="font-weight: bold;">Facility Order No: ' . $infor_array->id . ' | KEMSA Order No: ' . $infor_array->kemsaOrderid . ' | Order Date:' . $date . ' | Order Total: ' . number_format($total, 2, '.', ',') . ' | Drawing rights: ' . number_format($draw, 2, '.', ',') . ' | Balance(Drawing rights - Order Total):' . $bal . ' </p></span></td></tr> <tr> <th><b>KEMSA Code</b></th> <th><b>Description</b></th> <th><b>Order Unit Size</b></th> <th><b>Order Unit Cost</b></th> <th ><b>Opening Balance</b></th> <th ><b>Total Receipts</b></th> <th><b>Total issues</b></th> <th><b>Adjustments</b></th> <th><b>Losses</b></th> <th><b>Closing Stock</b></th> <th><b>No days out of stock</b></th> <th><b>Order Quantity</b></th> <th><b>Order cost(Ksh)</b></th> <th><b>Comment(if any)</b></th> </tr> </thead><tbody>'; /*****************************creating the rows **************************************/ foreach ($infor_array->Ord as $Ord_array) { //setting the variables $o_q = $Ord_array->quantityOrdered; $total_item_ordered = $total_item_ordered + $o_q; $o_p = $Ord_array->price; $o_t = number_format($o_p * $o_q, 2, '.', ','); $o_qr = $Ord_array->quantityRecieved; $total_item_received = $total_item_received + $o_qr; $fill = $o_qr / $o_q * 100; /*******************************begin adding data to the report*****************************************/ $html_data1 .= '<tr><td>' . $Ord_array->kemsa_code . '</td>'; $html_data2 .= '<tr><td>' . $Ord_array->kemsa_code . '</td>'; foreach ($Ord_array->Code as $d) { $name = $d->Drug_Name; $html_data1 .= '<td>' . $name . '</td>'; /*********************************************************************************************/ $html_data2 .= '<td>' . $name . '</td><td>' . $d->Unit_Size . '</td><td>' . $o_p . '</td>'; } $html_data1 .= '<td>' . $o_q . '</td> <td>' . $o_p . '</td> <td class="col5">' . $o_t . '</td> <td>' . $o_q . '</td> <td>' . $o_qr . '</td> <td class="col5">' . $fill . '%' . '</td> <td>' . $Ord_array->o_balance . '</td> <td >' . $Ord_array->t_receipts . '</td> <td >' . $Ord_array->t_issues . '</td> <td >' . $Ord_array->adjust . '</td> <td >' . $Ord_array->losses . '</td> <td >' . $Ord_array->c_stock . '</td> <td >' . $Ord_array->days . '</td> <td >' . $Ord_array->comment . '</td> </tr>'; /****************************************************************************************************************/ $html_data2 .= '<td>' . $Ord_array->o_balance . '</td> <td>' . $Ord_array->t_receipts . '</td> <td >' . $Ord_array->t_issues . '</td> <td>' . $Ord_array->adjust . '</td> <td>' . $Ord_array->losses . '</td> <td >' . $Ord_array->c_stock . '</td> <td>' . $Ord_array->days . '</td> <td >' . $o_q . '</td> <td class="col5">' . $o_t . '</td> <td >' . $Ord_array->comment . '</td> </tr>'; } if ($total_item_ordered == 0) { $total_item_ordered = 1; } $order_fill_rate = $total_item_received / $total_item_ordered * 100; //close the table $html_data1 .= '<tr><td colspan="16"> <b>Total Items Received: ' . $total_item_received . ' | Total Items Ordered : ' . $total_item_ordered . '| Order Fill Rate(Total items received/Total Items Ordered)*100 :' . $order_fill_rate . ' %</td></tr></tbody></table></b><hr /></br></br>'; $html_data2 .= '</tbody></table></b><hr /></br></br>'; } if ($data_type == 'Order Analysis') { $html_data .= $html_data1; } else { if ($data_type == 'Raw Order Data') { $html_data .= $html_data2; } } /**************************finally generate the report***********************/ $this->generate_pdf($report_name, $title, $html_data, $report_type); }