public function decommission() { //Change status of commodities to decommissioned $date = date('y-m-d'); $facility_code = $this->session->userdata('facility_id'); $user_id = $this->session->userdata('user_id'); $facility_name_array = Facilities::get_facility_name_($facility_code)->toArray(); $facility_name = $facility_name_array[0]['facility_name']; $myobj1 = Doctrine::getTable('Districts')->find($facility_name_array[0]['district']); $disto_name = $myobj1->district; $county = $myobj1->county; $myobj2 = Doctrine::getTable('Counties')->find($county); $county_name = $myobj2->county; $total = 0; //Create PDF of Expired Drugs that are to be decommisioned. check here $decom = Facility_stocks::get_facility_expired_stuff($facility_code); /*****************************setting up the report*******************************************/ if (count($decom) > 0) { $body = ''; $body .= "<style> table {\n border-collapse: collapse;\n}td,th{\n\tpadding: 12px;\n\ttext-align:center;\n}\n\n*{margin:0;padding:0}*{font-family:'Helvetica Neue',Helvetica,Helvetica,Arial,sans-serif}img{max-width:100%}.collapse{padding:0}body{-webkit-font-smoothing:antialiased;-webkit-text-size-adjust:none;width:100%!important;height:100%}a{color:#2BA6CB}.btn{text-decoration:none;color:#FFF;background-color:#666;padding:10px 16px;font-weight:700;margin-right:10px;text-align:center;cursor:pointer;display:inline-block}p.callout{padding:15px;background-color:#ECF8FF;margin-bottom:15px}.callout a{font-weight:700;color:#2BA6CB}table.social{background-color:#ebebeb}.social .soc-btn{padding:3px 7px;font-size:12px;margin-bottom:10px;text-decoration:none;color:#FFF;font-weight:700;display:block;text-align:center}a.fb{background-color:#3B5998!important}a.tw{background-color:#1daced!important}a.gp{background-color:#DB4A39!important}a.ms{background-color:#000!important}.sidebar .soc-btn{display:block;width:100%}table.head-wrap{width:100%}.header.container table td.logo{padding:15px}.header.container table td.label{padding:15px 15px 15px 0}table.body-wrap{width:100%}table.footer-wrap{width:100%;clear:both!important}.footer-wrap .container td.content p{border-top:1px solid #d7d7d7;padding-top:15px;font-size:9px;font-weight:500}h1,h2,h3,h4,h5,h6{font-family:HelveticaNeue-Light,'Helvetica Neue Light','Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif;line-height:1.1;margin-bottom:15px;color:#000}h1 small,h2 small,h3 small,h4 small,h5 small,h6 small{font-size:60%;color:#6f6f6f;line-height:0;text-transform:none}h1{font-weight:200;font-size:44px}h2{font-weight:200;font-size:37px}h3{font-weight:500;font-size:27px}h4{font-weight:500;font-size:23px}h5{font-weight:900;font-size:17px}h6{font-weight:900;font-size:14px;text-transform:uppercase;color:#444}.collapse{margin:0!important}p,ul{margin-bottom:10px;font-weight:400;font-size:14px;line-height:1.6}p.lead{font-size:17px}p.last{margin-bottom:0}ul li{margin-left:5px;list-style-position:inside}ul.sidebar{background:#ebebeb;display:block;list-style-type:none}ul.sidebar li{display:block;margin:0}ul.sidebar li a{text-decoration:none;color:#666;padding:10px 16px;cursor:pointer;border-bottom:1px solid #777;border-top:1px solid #FFF;display:block;margin:0}ul.sidebar li a.last{border-bottom-width:0}ul.sidebar li a h1,ul.sidebar li a h2,ul.sidebar li a h3,ul.sidebar li a h4,ul.sidebar li a h5,ul.sidebar li a h6,ul.sidebar li a p{margin-bottom:0!important}.container{display:block!important;max-width:100%!important;margin:0 auto!important;clear:both!important}.content{padding:15px;max-width:80%px;margin:0 auto;display:block}.content table{width:100%}.column{width:300px;float:left}.column tr td{padding:15px}.column-wrap{padding:0!important;margin:0 auto;max-width:600px!important}.column table{width:100%}.social .column{width:280px;min-width:279px;float:left}.clear{display:block;clear:both}@media only screen and (max-width:600px){a[class=btn]{display:block!important;margin-bottom:10px!important;background-image:none!important;margin-right:0!important}div[class=column]{width:auto!important;float:none!important}table.social div[class=column]{width:auto!important}}</style>"; $body .= "<table class='' style='background-color: #ECF8FF;' >\n<tr>\n<td>MFL No: <strong>{$facility_code}</strong> </td>\n<td>Health Facility Name: <strong>{$facility_name}</strong></td>\n<td>County: <strong>{$county_name}</strong></td>\n<td>Subcounty: <strong>{$disto_name}</strong></td>\n</tr>\n</table>" . ' <table class="" style="margin:8px;word-wrap: break-word;"> <thead style="font-size:12px"> <tr><th><strong>Source</strong></th> <th><strong>Description</strong></th> <th><strong>Commodity Code</strong></th> <th><strong>Unit Cost(Ksh)</strong></th> <th><strong>Batch Affected</strong></th> <th><strong>Manufacturer</strong></th> <th><strong>Expiry Date</strong></th> <th><strong>Expiry Days</strong></th> <th><strong>Expired(Pack Size)</strong></th> <th><strong>Expired(Unit Size)</strong></th> <th><strong>Cost of Expired (Ksh)</strong></th> </tr> </thead><tbody>'; /*******************************begin adding data to the report*****************************************/ foreach ($decom as $drug) { $commodity_id = $drug['commodity_id']; $batch = $drug['batch_no']; $mau = $drug['manufacture']; $commodity_name = $drug['commodity_name']; $commodity_code = $drug['commodity_code']; $unit_size = $drug['unit_size']; $unit_cost = str_replace(",", '', $drug['unit_cost']); $current_balance = $drug['current_balance']; $total_commodity_units = $drug['total_commodity_units']; $expiry_date = $drug['expiry_date']; $current_balance_pack = round($current_balance / $total_commodity_units, 1); $cost = $current_balance_pack * $unit_cost; $formatme = new DateTime($expiry_date); $newdate = $formatme->format('d M Y'); $facility_stock_id = $drug['facility_stock_id']; $total = $total + $cost; $source = $drug['source_name']; //get the current balance of the commodity $facility_stock = Facility_Stocks::get_facility_commodity_total($facility, $commodity_id)->toArray(); $mydata3 = array('facility_code' => $facility_code, 's11_No' => '(Loss) Expiry', 'commodity_id' => $commodity_id, 'batch_no' => $batch, 'expiry_date' => date('y-m-d', strtotime(str_replace(",", " ", $expiry_date))), 'balance_as_of' => $facility_stock[0]['commodity_balance'], 'date_issued' => date('y-m-d'), 'qty_issued' => 0, 'adjustmentnve' => $current_balance * -1, 'issued_to' => 'N/A', 'issued_by' => $this->session->userdata('user_id')); $seconds_diff = strtotime(date("y-m-d")) - strtotime($expiry_date); $date_diff = floor($seconds_diff / 3600 / 24); Facility_Issues::update_issues_table($mydata3); $inserttransaction = Doctrine_Manager::getInstance()->getCurrentConnection()->execute("UPDATE `facility_transaction_table` SET losses =losses+{$current_balance}, closing_stock=closing_stock-{$current_balance}\n WHERE `commodity_id`= '{$commodity_id}' and status='1' and facility_code={$facility_code} "); /// update the facility issues and set the commodity to expired $inserttransaction = Doctrine_Manager::getInstance()->getCurrentConnection()->execute("UPDATE `facility_stocks` SET status =2 WHERE `id`= '{$facility_stock_id}'"); if ($current_balance_pack > 0) { $body .= '<tr style="font-size:12px;padding:4px"><td>' . $source . '</td> <td>' . $commodity_name . '</td> <td>' . $commodity_code . '</td> <td>' . $unit_cost . '(' . $unit_size . ')' . '</td> <td>' . $batch . '</td> <td>' . $mau . '</td> <td>' . $newdate . '</td> <td>' . $date_diff . '</td> <td>' . $current_balance_pack . '</td> <td>' . $current_balance . '</td> <td>' . number_format($cost, 2, '.', ',') . '</td> </tr>'; } } $body .= ' <tr> <td colspan="12"> <b style="float: right; margin:1.0em;font-size:14px">TOTAL cost(Ksh) of Expiries: ' . number_format($total, 2, '.', ',') . '</b> </tr> </tbody> </table>'; $html_body .= "<!-- BODY -->\n<table class='body-wrap'>\n\t<tr>\n\t\t<td></td>\n\t\t<td class='container' bgcolor='#FFFFFF'>\n\n\t\t\t<div class='content'>\n\t\t\t<table>\n\t\t\t\t<tr>\n\t\t\t\t\t<td>\n\t\t\t\t\t\t<h3>Hello,</h3>\n\t\t\t\t\t\t<p class='lead'>Find attached decommissioned commodities for {$facility_name} ({$facility_code}).</p>\n\t\t\t\t\t\t<p>{$body}</p>\n\t\t\t\t\t\t<!-- Callout Panel -->\n\t\t\t\t\t\t<p class='callout'>\n\t\t\t\t\t\t\t<a href='health-cmp.or.ke'>Click here! »</a> to follow up.\n\t\t\t\t\t\t</p><!-- /Callout Panel -->\n\n\t\t\t\t\t\t<!-- social & contact -->\n\t\t\t\t\t\t<table class='social' width='100%'>\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<td>\n\n\t\t\t\t\t\t\t\t\t<!-- column 1 -->\n\t\t\t\t\t\t\t\t\t<table align='left' class='column'>\n\n\t\t\t\t\t\t\t\t\t</table><!-- /column 1 -->\n\n\t\t\t\t\t\t\t\t\t<!-- column 2 -->\n\t\t\t\t\t\t\t\t\t<table align='left' class='column'>\n\t\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t\t<td>\n\n\t\t\t\t\t\t\t\t\t\t\t\t<h5 class=''>Contact Info:</h5>\n\t\t\t\t\t\t\t\t\t\t\t\t<p>Phone: <strong>+254720167245</strong><br/>\n Email: <strong><a href='emailto:hcmpkenya@gmail.com'>hcmpkenya@gmail.com</a></strong></p>\n\n\t\t\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t</table><!-- /column 2 -->\n\n\t\t\t\t\t\t\t\t\t<span class='clear'></span>\n\n\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t</table><!-- /social & contact -->\n\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\t\t\t</table>\n\t\t\t</div><!-- /content -->\n\n\t\t</td>\n\t\t<td></td>\n\t</tr>\n</table><!-- /BODY -->"; $file_name = 'Facility_Expired_Commodities_' . $facility_name . "_" . $facility_code . "_" . $date; $pdf_data = array("pdf_title" => "Facility Expired Commodities For {$facility_name}", 'pdf_html_body' => $body, 'pdf_view_option' => 'save_file', 'file_name' => $file_name); $this->hcmp_functions->create_pdf($pdf_data); if ($this->hcmp_functions->send_stock_decommission_email($html_body, 'Decommission Report For ' . $facility_name, './pdf/' . $file_name . '.pdf')) { delete_files('./pdf/' . $file_name . '.pdf'); $this->session->set_flashdata('system_success_message', 'Stocks Have Been Decommissioned'); } //updates the log tables with the action $user = $this->session->userdata('user_id'); $user_action = "decommissioned"; //updates the log table accordingly based on the action carried out by the user involved $update = Doctrine_Manager::getInstance()->getCurrentConnection(); $update->execute("update log set {$user_action} = 1\n\t\t\twhere `user_id`= {$user}\n\t\t\tAND action = 'Logged In'\n\t\t\tand UNIX_TIMESTAMP( `end_time_of_event`) = 0"); } redirect('reports/facility_stock_data'); }
public function update_facility_transaction($msg = NULL) { $option = $_POST['option']; //setting up the variables $id = $_POST['id']; $open = $_POST['open']; $recepits = $_POST['receipts']; $issues = $_POST['issues']; $adjustments = $_POST['adjustments']; $losses = $_POST['losses']; $closing = $_POST['closing']; $nodays = $_POST['days']; $drug_id = $_POST['drug_id']; $j = count($id); //updating the facility transaction table automatically $facility_c = $this->session->userdata('news'); $user_id = $this->session->userdata('user_id'); if ($option != "update stock levels") { for ($i = 0; $i < $j; $i++) { $myobj = Doctrine::getTable('Facility_Transaction_Table')->find($id[$i]); $myobj->Opening_Balance = $open[$i]; $myobj->Total_Receipts = $recepits[$i]; $myobj->Total_Issues = $issues[$i]; $myobj->Adj = $adjustments[$i]; $myobj->Losses = $losses[$i]; $myobj->Closing_Stock = $closing[$i]; $myobj->Days_Out_Of_Stock = $nodays[$i]; $myobj->save(); } $note = TRUE; redirect("order_management/new_order/{$note}"); } else { for ($i = 0; $i < $j; $i++) { $myobj = Doctrine::getTable('Facility_Transaction_Table')->find($id[$i]); $myobj->Opening_Balance = $open[$i]; $myobj->Total_Receipts = $recepits[$i]; $myobj->Total_Issues = $issues[$i]; $myobj->Adj = $adjustments[$i]; $myobj->Losses = $losses[$i]; $myobj->Closing_Stock = $closing[$i]; $myobj->Days_Out_Of_Stock = $nodays[$i]; $myobj->save(); /*********************************************step one get the totals of the previous issues*************************/ $qty_issued = 0; $inserttransaction = Doctrine_Manager::getInstance()->getCurrentConnection()->fetchAll("SELECT SUM( `qty_issued` ) AS qty_issued\n FROM facility_issues\n WHERE `facility_code` = '{$facility_c}'\n AND `kemsa_code` = '{$drug_id[$i]}' AND availability='1' "); /**********************************totals of all the issues of that particular ordering window*****************************/ $qty_issued = $inserttransaction[0]['qty_issued']; if (empty($qty_issued)) { $qty_issued = 0; } // echo "qty_issued $qty_issued <br>"; /***********************************get the balances of the particular commodidty for that window********************************/ $inserttransaction1 = Doctrine_Manager::getInstance()->getCurrentConnection()->fetchAll("SELECT SUM( `balance` ) AS qty_balance\n FROM facility_stock\n WHERE `facility_code` = '{$facility_c}'\n AND `kemsa_code` = '{$drug_id[$i]}' and status='1' "); /**********************************totals of balances of the particular commodidty for that window*****************************/ $qty_bal = $inserttransaction1[0]['qty_balance']; // echo "qty bal $qty_bal <br>"; // echo "number of issues $issues[$i]</br> "; /**********************************check if there is any difference between what the user has inputed and the acutal issues*****************************/ $slag_qty = $issues[$i] - $qty_issued; //echo "slag $slag_qty <br>"; //$real_slag=$slag_qty; //$real_b=0; if ($issues[$i] > $qty_issued && $qty_bal >= $slag_qty) { //echo "ok <br>"; $query = Doctrine_Query::create()->select("*")->from("facility_stock")->where("Facility_Code='{$facility_c}' and status='1'")->andwhere("kemsa_code='{$drug_id[$i]}'")->orderby('expiry_date asc'); $drugs = $query->execute(); foreach ($drugs as $data) { $table_bal = $data->balance; $real_b = 0; $update_value = 0; if ($table_bal > $slag_qty && $slag_qty > 0) { //echo "$table_bal>$slag_qty<br>"; $real_b = $table_bal - $slag_qty; $update_value = $slag_qty; //echo "real_b $real_b update_value $update_value <br>"; //echo $update_value.'$update_value $table_bal>=$issues[$i]</br>'; $inserttransactiona = Doctrine_Manager::getInstance()->getCurrentConnection()->execute("update facility_stock set balance={$real_b} where id={$data->id} "); //echo "update facility_stock set qty_balance=$real_b where id=$data->id what to update </br>"; $mydata = array('facility_code' => $facility_c, 'kemsa_code' => $drug_id[$i], 's11_No' => 'N/A', 'batch_no' => $data->batch_no, 'expiry_date' => $data->expiry_date, 'qty_issued' => $update_value, 'issued_to' => 'PHARMACY', 'balanceAsof' => $table_bal, 'date_issued' => date('y-m-d'), 'issued_by' => $user_id); $u = new Facility_Issues(); $u->fromArray($mydata); $u->save(); $slag_qty = 0; //echo "new slag_qty $slag_qty <br>"; } elseif ($table_bal <= $slag_qty && $slag_qty > 0) { // echo "$table_bal<=$slag_qty<br>"; $update_value = $table_bal; $real_b = 0; echo " real_b {$real_b} update_value {$update_value} <br>"; echo "new slag_qty {$slag_qty} <br>"; $slag_qty = $slag_qty - $table_bal; $inserttransactiona = Doctrine_Manager::getInstance()->getCurrentConnection()->execute("update facility_stock set balance={$real_b} where id={$data->id} "); $mydata = array('facility_code' => $facility_c, 'kemsa_code' => $drug_id[$i], 's11_No' => 'N/A', 'batch_no' => $data->batch_no, 'expiry_date' => $data->expiry_date, 'qty_issued' => $update_value, 'issued_to' => 'PHARMACY', 'balanceAsof' => $table_bal, 'date_issued' => date('y-m-d'), 'issued_by' => $user_id); $u = new Facility_Issues(); $u->fromArray($mydata); $u->save(); } //echo $table_bal.'drug balance G8</br> '; //echo $real_b.' slag after deduction </br>'; //exit; /**/ } //exit; } } $msg = "Stock details have been updated"; redirect("stock_management/stock_level/{$msg}"); } }
public function Decommission() { //Change status of commodities to decommissioned $date = date('Y-m-d'); $facility = $this->session->userdata('news'); $facility_code = $this->session->userdata('news'); $user_id = $this->session->userdata('user_id'); $facility_name_array = Facilities::get_facility_name_($facility_code); $facility_name = $facility_name_array['facility_name']; $districtName = $this->session->userdata('full_name'); $myobj1 = Doctrine::getTable('Districts')->find($facility_name_array['district']); $disto_name = $myobj1->district; $county = $myobj1->county; $myobj2 = Doctrine::getTable('Counties')->find($county); $county_name = $myobj2->county; $myobj3 = Doctrine::getTable('user')->find($user_id); $creator_name1 = $myobj3->fname; $creator_name2 = $myobj3->lname; $total = 0; //Create PDF of Expired Drugs that are to be decommisioned. check here $decom = Facility_Stock::get_facility_expired_stuff($date, $facility); //create the report title $html_title = "<div ALIGN=CENTER><img src='Images/coat_of_arms.png' height='70' width='70'style='vertical-align: top;' > </img></div>\n \n <div style='text-align:center; font-family: arial,helvetica,clean,sans-serif;display: block; font-weight: bold; font-size: 14px;'>\n Ministry of Health</div>\n <div style='text-align:center; font-family: arial,helvetica,clean,sans-serif;display: block; font-weight: bold;display: block; font-size: 13px;'>Health Commodities Management Platform</div>\n <div style='text-align:center; font-family: arial,helvetica,clean,sans-serif;display: block; font-weight: bold;display: block; font-size: 13px;'>Expired Commodities Between " . date("F", strtotime("-1 month")) . " - " . date("F") . " " . date('Y') . "</div><hr /> "; /*****************************setting up the report*******************************************/ $html_body = ''; $html_body .= '<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:#C9C299;}</style>' . "<table class='data-table' width=100%>\n<tr>\n<td>MFL No: {$facility_code}</td> \n<td>Health Facility Name: {$facility_name}</td>\n<td>County: {$county_name}</td> \n<td>Subcounty: {$disto_name}</td>\n</tr>\n</table>" . ' <table class="data-table" width=100%> <thead> <tr><th><strong>Source</strong></th> <th><strong>Description</strong></th> <th><strong>Unit Size</strong></th> <th><strong>Batch No Affected</strong></th> <th><strong>Manufacturer</strong></th> <th><strong>Expiry Date</strong></th> <th><strong># of Days From Expiry</strong></th> <th><strong>Stock Expired(Unit Size)</strong></th> <th><strong>Unit Cost (Ksh)</strong></th> <th><strong>Cost of Expired (Ksh)</strong></th> </tr> </thead><tbody>'; /*******************************begin adding data to the report*****************************************/ foreach ($decom as $drug) { $drug_id = $drug['drug_id']; $batch = $drug['batch_no']; $mau = $drug['manufacture']; $name = $drug['drug_name']; $code = $drug['kemsa_code']; $code = isset($code) ? "KEMSA: code" . $code : ''; $unitS = $drug['unit_size']; $unitC = $drug['unit_cost']; $calc = $drug['balance']; $total_units = $drug['total_units']; $thedate = $drug['expiry_date']; $balance = round($calc / $total_units, 1); $cost = $balance * $unitC; $formatme = new DateTime($thedate); $myvalue = $formatme->format('d M Y'); $total = $total + $cost; //get the current balance of the commodity $facility_stock = Facility_Stock::get_facility_drug_total($facility, $drug_id)->toArray(); $mydata3 = array('facility_code' => $facility, 's11_No' => '(Loss) Expiry', 'kemsa_code' => $drug_id, 'batch_no' => $batch, 'expiry_date' => $thedate, 'receipts' => $calc * -1, 'balanceAsof' => $facility_stock[0]['balance'], 'date_issued' => date('y-m-d'), 'issued_to' => 'N/A', 'issued_by' => $this->session->userdata('identity')); $seconds_diff = strtotime(date("y-m-d")) - strtotime($myvalue); $date_diff = floor($seconds_diff / 3600 / 24); Facility_Issues::update_issues_table($mydata3); $inserttransaction_1 = Doctrine_Manager::getInstance()->getCurrentConnection()->fetchAll("select `losses` from `facility_transaction_table`\n WHERE `kemsa_code`= '{$drug_id}' and availability='1' and facility_code={$facility}; "); $new_value = $inserttransaction_1[0]['losses'] + $calc; $inserttransaction = Doctrine_Manager::getInstance()->getCurrentConnection(); $inserttransaction1 = Doctrine_Manager::getInstance()->getCurrentConnection(); $inserttransaction2 = Doctrine_Manager::getInstance()->getCurrentConnection(); // update the transaction table with the loss $inserttransaction->execute("UPDATE `facility_transaction_table` SET losses ={$new_value}\n WHERE `kemsa_code`= '{$drug_id}' and availability='1' and facility_code={$facility}; "); // update the transaction table with the new closing balance $inserttransaction1->execute("UPDATE `facility_transaction_table` SET closing_stock = (SELECT SUM(balance)\n\t\t\t FROM facility_stock WHERE kemsa_code = '{$drug_id}' and status='1' and facility_code='{$facility}')\n WHERE `kemsa_code`= '{$drug_id}' and availability='1' and facility_code ='{$facility}'; "); /// update the facility issues and set the commodity to expired $inserttransaction->execute("UPDATE `facility_stock` SET status =2\n WHERE `kemsa_code`= '{$drug_id}' and facility_code={$facility}; "); $html_body .= '<tr><td>' . $code . '</td> <td>' . $name . '</td> <td >' . $unitS . '</td> <td>' . $batch . '</td> <td>' . $mau . '</td> <td>' . $myvalue . '</td> <td>' . $date_diff . '</td> <td >' . $calc . '</td> <td >' . $unitC . '</td> <td >' . number_format($cost, 2, '.', ',') . '</td> </tr>'; /***********************************************************************************************/ } $html_body .= ' <tr> <td colspan="10"> <b style="float: right; margin-right:5.0em">TOTAL cost(Ksh) of Expiries: ' . number_format($total, 2, '.', ',') . '</b> </tr> </tbody> </table>'; $this->load->library('mpdf'); $this->load->helper('file'); $this->mpdf = new mPDF('', 'A4-L', 0, '', 15, 15, 16, 16, 9, 9, ''); $this->mpdf->WriteHTML($html_title); $this->mpdf->defaultheaderline = 1; $this->mpdf->simpleTables = true; $this->mpdf->WriteHTML($html_body); $this->mpdf->SetFooter("{DATE d/m/Y }|{PAGENO}/{nb}|Prepared by: {$creator_name1} {$creator_name2}"); $report_name = 'Facility_Expired_Commodities_' . $facility . "_" . $date . "_" . $facility_name; if (!write_file('./pdf/' . $report_name . '.pdf', $this->mpdf->Output('$report_name', 'S'))) { $this->session->set_flashdata('system_error_message', 'An error occured, when creating a PDF contact system ADMIN'); redirect("/"); } else { if (!$this->send_stock_decommission_email($html_body, 'Decommission Report For ' . $facility, './pdf/' . $report_name . '.pdf')) { delete_files('./pdf/' . $report_name . '.pdf'); $this->session->set_flashdata('system_success_message', 'Stocks Have Been Decommissioned'); redirect("/"); } else { $this->session->set_flashdata('system_error_message', 'An error occured, the items were decommissioned but there was a problem in sending an email file:' . $report_name . '.pdf'); redirect("/"); } } }
function moh_consumption_report() { if ($this->input->post('id')) { $data['name'] = $this->input->post('ajax'); $year = date("Y"); $drug_id = $this->input->post('id'); $data['detail'] = Facility_Issues::get_consumption_per_drug($drug_id, $year); $district = $this->session->userdata('district1'); $data['facilities'] = Facilities::getFacilities($district); $this->load->view("moh/ajax_reports/test", $data); } }
public function donation() { $facility_c = $this->session->userdata('news'); $usernow = $this->session->userdata('identity'); $kemsa_code = $_POST['drug_id']; $expiry_date = $_POST['expiry_date']; $batch_no = $_POST['batchNo']; $manuf = $_POST['manuf']; $a_stock = $_POST['qreceived']; $source = $_POST['source']; $count = count($kemsa_code); $orderDate = date('y-m-d H:i:s'); for ($i = 0; $i <= $count; $i++) { if (isset($kemsa_code[$i]) && $kemsa_code[$i] != '') { $mydata = array('facility_code' => $facility_c, 'kemsa_code' => $kemsa_code[$i], 'batch_no' => $batch_no[$i], 'manufacture' => $manuf[$i], 'expiry_date' => date('y-m-d', strtotime($expiry_date[$i])), 'balance' => $a_stock[$i], 'quantity' => $a_stock[$i], 'stock_date' => $orderDate, 'sheet_no' => $source[$i], 'source' => $source[$i]); ////get the current balance of the same commodity before adding new stock level $current_bal = Facility_Stock::getAll($kemsa_code[$i], $facility_c); ///updating the facility stock with the new data from the donation Facility_Stock::update_facility_stock($mydata); //adding data to issues table $mydata = array('facility_code' => $facility_c, 'kemsa_code' => $kemsa_code[$i], 's11_No' => "(+ve Adj) Stock Addition", 'batch_no' => $batch_no[$i], 'expiry_date' => date('y-m-d', strtotime($expiry_date[$i])), 'qty_issued' => 0, 'balanceAsof' => $current_bal[0]['total_balance'], 'receipts' => $a_stock[$i], 'date_issued' => date('y-m-d'), 'issued_to' => "Source :" . $source[$i], 'issued_by' => $usernow); $u = new Facility_Issues(); $u->fromArray($mydata); $u->save(); } } //getting facility regarding the stocks added above ^ $data = Facility_Stock::count_facility_stock($facility_c, $orderDate); foreach ($data as $infor) { $qty = $infor->quantity1; $kemsa_code_ = $infor->kemsa_code; $facility_has_commodity = Facility_Transaction_Table::get_if_drug_is_in_table($facility_c, $kemsa_code_); if ($facility_has_commodity > 0) { $inserttransaction_1 = Doctrine_Manager::getInstance()->getCurrentConnection()->fetchAll("select `adj` from `facility_transaction_table`\n WHERE `kemsa_code`= '{$kemsa_code_}' and availability='1' and facility_code={$facility_c}; "); $new_value = $inserttransaction_1[0]['adj'] + $qty; $inserttransaction = Doctrine_Manager::getInstance()->getCurrentConnection(); $inserttransaction->execute("UPDATE `facility_transaction_table` SET adj ={$new_value}\n WHERE `kemsa_code`= '{$kemsa_code_}' and availability='1' and facility_code={$facility_c}; "); $inserttransaction1 = Doctrine_Manager::getInstance()->getCurrentConnection(); $inserttransaction1->execute("UPDATE `facility_transaction_table` SET closing_stock = (SELECT SUM(balance)\n\t\t\t FROM facility_stock WHERE kemsa_code = '{$kemsa_code_}' and status='1' and facility_code='{$facility_c}')\n WHERE `kemsa_code`= '{$kemsa_code_}' and availability='1' and facility_code ='{$facility_c}'; "); } else { $mydata2 = array('Facility_Code' => $facility_c, 'Kemsa_Code' => $kemsa_code_, 'Opening_Balance' => 0, 'Total_Issues' => 0, 'Total_Receipts' => 0, 'Adj' => $qty, 'Closing_Stock' => $qty, 'availability' => 1); Facility_Transaction_Table::update_facility_table($mydata2); } } $this->send_stock_update_sms(); $this->session->set_flashdata('system_success_message', "You have received {$count} item(s)"); redirect('issues_main'); }
public function stock_level($msg = Null) { $facility_c = $this->session->userdata('news'); $checker = $this->uri->segment(3); $data['title'] = "Stock"; $data['content_view'] = "facility/facility_data/stock_level_v"; $data['banner_text'] = "Physical Stock"; $data['link'] = "order_management"; if (isset($msg)) { $data['msg'] = $msg; $data['update'] = 'update stock levels'; } if ($msg == NULL) { $data['update'] = NULL; $data['msg'] = " "; $data['checker'] = "no_order"; } if ($checker == "v") { $data['msg'] = "Verify that the system stock levels are the same as your physical stock count"; $data['update'] = 'update stock levels'; } if ($msg == 'c0N123') { $data['update'] = NULL; $data['msg'] = "Please confirm your stock details before placing your order"; } $data['facility_order'] = Facility_Transaction_Table::get_all($facility_c); $data['max_date'] = Facility_Stock::get_max_date($facility_c)->toArray(); $data['name_of_person'] = Facility_Issues::get_last_person_who_issues($facility_c); //$data['quick_link'] = "stock_level"; $this->load->view("template", $data); }
public function decommission() { //Change status of commodities to decommissioned $date = date('y-m-d'); $facility_code = $this->session->userdata('facility_id'); $user_id = $this->session->userdata('user_id'); $facility_name_array = Facilities::get_facility_name_($facility_code)->toArray(); $facility_name = $facility_name_array[0]['facility_name']; $myobj1 = Doctrine::getTable('Districts')->find($facility_name_array[0]['district']); $disto_name = $myobj1->district; $county = $myobj1->county; $myobj2 = Doctrine::getTable('Counties')->find($county); $county_name = $myobj2->county; $total = 0; //Create PDF of Expired Drugs that are to be decommisioned. check here $decom = Facility_stocks::get_facility_expired_stuff($facility_code); /*****************************setting up the report*******************************************/ if (count($decom) > 0) { $html_body = ''; $html_body .= "<table class='data-table' width=100%>\n<tr>\n<td>MFL No: {$facility_code}</td> \n<td>Health Facility Name: {$facility_name}</td>\n<td>County: {$county_name}</td> \n<td>Subcounty: {$disto_name}</td>\n</tr>\n</table>" . ' <table class="data-table" width=100%> <thead> <tr><th><strong>Source</strong></th> <th><strong>Description</strong></th> <th><strong>Commodity Code</strong></th> <th><strong>Unit Size</strong></th> <th><strong>Unit Cost (Ksh)</strong></th> <th><strong>Batch No Affected</strong></th> <th><strong>Manufacturer</strong></th> <th><strong>Expiry Date</strong></th> <th><strong># of Days From Expiry</strong></th> <th><strong>Stock Expired(Pack Size)</strong></th> <th><strong>Stock Expired(Unit Size)</strong></th> <th><strong>Cost of Expired (Ksh)</strong></th> </tr> </thead><tbody>'; /*******************************begin adding data to the report*****************************************/ foreach ($decom as $drug) { $commodity_id = $drug['commodity_id']; $batch = $drug['batch_no']; $mau = $drug['manufacture']; $commodity_name = $drug['commodity_name']; $commodity_code = $drug['commodity_code']; $unit_size = $drug['unit_size']; $unit_cost = str_replace(",", '', $drug['unit_cost']); $current_balance = $drug['current_balance']; $total_commodity_units = $drug['total_commodity_units']; $expiry_date = $drug['expiry_date']; $current_balance_pack = round($current_balance / $total_commodity_units, 1); $cost = $current_balance_pack * $unit_cost; $formatme = new DateTime($expiry_date); $newdate = $formatme->format('d M Y'); $facility_stock_id = $drug['facility_stock_id']; $total = $total + $cost; $source = $drug['source_name']; //get the current balance of the commodity $facility_stock = Facility_Stocks::get_facility_commodity_total($facility, $commodity_id)->toArray(); $mydata3 = array('facility_code' => $facility_code, 's11_No' => '(Loss) Expiry', 'commodity_id' => $commodity_id, 'batch_no' => $batch, 'expiry_date' => date('y-m-d', strtotime(str_replace(",", " ", $expiry_date))), 'balance_as_of' => $facility_stock[0]['commodity_balance'], 'date_issued' => date('y-m-d'), 'qty_issued' => 0, 'adjustmentnve' => $current_balance * -1, 'issued_to' => 'N/A', 'issued_by' => $this->session->userdata('user_id')); $seconds_diff = strtotime(date("y-m-d")) - strtotime($expiry_date); $date_diff = floor($seconds_diff / 3600 / 24); Facility_Issues::update_issues_table($mydata3); $inserttransaction = Doctrine_Manager::getInstance()->getCurrentConnection()->execute("UPDATE `facility_transaction_table` SET losses =losses+{$current_balance}, closing_stock=closing_stock-{$current_balance}\n WHERE `commodity_id`= '{$commodity_id}' and status='1' and facility_code={$facility_code} "); /// update the facility issues and set the commodity to expired $inserttransaction = Doctrine_Manager::getInstance()->getCurrentConnection()->execute("UPDATE `facility_stocks` SET status =2 WHERE `id`= '{$facility_stock_id}'"); if ($cost > 0) { $html_body .= '<tr><td>' . $source . '</td> <td>' . $commodity_name . '</td> <td>' . $commodity_code . '</td> <td>' . $unit_size . '</td> <td>' . $unit_cost . '</td> <td>' . $batch . '</td> <td>' . $mau . '</td> <td>' . $newdate . '</td> <td>' . $date_diff . '</td> <td>' . $current_balance_pack . '</td> <td>' . $current_balance . '</td> <td>' . number_format($cost, 2, '.', ',') . '</td> </tr>'; } } $html_body .= ' <tr> <td colspan="12"> <b style="float: right; margin-right:5.0em">TOTAL cost(Ksh) of Expiries: ' . number_format($total, 2, '.', ',') . '</b> </tr> </tbody> </table>'; $file_name = 'Facility_Expired_Commodities_' . $facility_name . "_" . $facility_code . "_" . $date; $pdf_data = array("pdf_title" => "Facility Expired Commodities For {$facility_name}", 'pdf_html_body' => $html_body, 'pdf_view_option' => 'save_file', 'file_name' => $file_name); $this->hcmp_functions->create_pdf($pdf_data); if ($this->hcmp_functions->send_stock_decommission_email($html_body, 'Decommission Report For ' . $facility_name, './pdf/' . $file_name . '.pdf')) { delete_files('./pdf/' . $file_name . '.pdf'); $this->session->set_flashdata('system_success_message', 'Stocks Have Been Decommissioned'); } $user = $this->session->userdata('user_id'); $user_action = "decommission"; Log::log_user_action($user, $user_action); } redirect('reports/facility_stock_data'); }
public function get_commodityIpdf() { $from = $_POST['datefromB']; $to = $_POST['datetoB']; $facility_Name = $_POST['facilitycode1']; $report_name = 'Commodity Issues Summary Between ' . $from . ' & ' . $to; $report = Facility_Issues::getcissues(); //$names= User::getsome($id); $title = 'test'; /**************************************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:#C9C299;}</style>'; $html_data1 = ''; /*****************************setting up the report*******************************************/ $html_data1 .= '<table class="data-table"><thead> <tr > <th ><strong>Kemsa Code</strong></th> <th ><strong>Description</strong></th> <th ><strong>Date</strong></th> <th><strong>Reference/S11 No</strong></th> <th><strong>Batch No</strong></th> <th><strong>Expiry Date</strong></th> <th><strong>Receipts/Opening Bal.</strong></th> <th><strong>Issues</strong></th> <th><strong>Closing Bal.</strong></th> <th><strong>Issuing/Receiving Officer</strong></th> <th ><strong><b>Service Point</b></strong></th> </tr> </thead><tbody>'; /*******************************begin adding data to the report*****************************************/ foreach ($report as $user) { foreach ($user->Code as $d) { foreach ($user->stock_Drugs as $value) { $drugsname = $value->Drug_Name; $code = $value->Kemsa_Code; $fname = $d->fname; $lname = $d->lname; $thedate = $user->date_issued; $thedate1 = $user->expiry_date; $formatme = new DateTime($thedate); $formatme1 = new DateTime($thedate1); $myvalue = $formatme->format('d M Y'); $myvalue1 = $formatme1->format('d M Y'); $html_data1 .= '<tr> <td>' . $code . '</td> <td>' . $drugsname . '</td> <td>' . $myvalue . '</td> <td>' . $user->s11_No . '</td> <td>' . $user->batch_no . '</td> <td>' . $myvalue1 . '</td> <td>' . $user->balanceAsof + $user->qty_issued . '</td> <td >' . $user->qty_issued . '</td> <td >' . $user->balanceAsof . '</td> <td>' . $lname . ' ' . $fname . '</td> <td >' . $user->issued_to . '</td> </tr>'; /***********************************************************************************************/ } } } $html_data1 .= '</tbody></table>'; $html_data .= $html_data1; $this->generatecommodityI_pdf($report_name, $title, $html_data, $to, $from, $facility_Name); }