public function paymentAction()
 {
     if ($this->request->isPost()) {
         $orderarray = $this->request->getPost('orderarray');
         $orderarray = json_decode($orderarray, TRUE);
         $sum = 0;
         foreach ($orderarray as $veg) {
             $sum += $veg[m_price] * $veg[quant];
         }
         //echo $sum;
         $auth = $this->session->get('auth');
         $id = $auth[uid];
         $orders = new Orders();
         $orders->u_id = $id;
         $orders->o_price = $sum;
         $orders->o_date = date("Y-m-d");
         $orders->o_payment = "Failed";
         $orders->o_delivery = 0;
         if ($orders->save() == false) {
             foreach ($orders->getMessages() as $message) {
                 echo $message;
             }
         } else {
             foreach ($orderarray as $veg) {
                 $orderdetails = new Orderdetails();
                 $orderdetails->o_id = $orders->o_id;
                 $orderdetails->m_id = $veg[m_id];
                 $orderdetails->od_quantity = $veg[quant];
                 $orderdetails->od_prepared = 0;
                 if ($orderdetails->save() == false) {
                     foreach ($orderdetails->getMessages() as $message) {
                         echo $message;
                     }
                 } else {
                     $user = Userdetails::findFirst(array("(u_id = :id:)", 'bind' => array('id' => $id)));
                     if ($user != false) {
                         $datename = $user->u_fname;
                         $dataemail = $user->u_email;
                         $dataphone = $user->u_phno;
                         $dataamount = $sum;
                         $url = "https://www.instamojo.com/slickaccount/test-for-integration-monthly-payment/?intent=buy&data_name=" . $dataname . "&data_email=" . $dataemail . "&data_phone=" . $dataphone . "&data_amount=" . $dataamount . "&data_readonly=data_phone&data_readonly=data_name&data_readonly=data_email";
                         header('Location: ' . $url);
                     }
                 }
             }
         }
     }
 }
예제 #2
0
 /**
  * @copydoc DBElement::check_values_validity()
  */
 public static function check_values_validity(&$database, &$current_user, &$log, &$values, $is_new, &$element = NULL)
 {
     // first, we let all parent classes to check the values
     parent::check_values_validity($database, $current_user, $log, $values, $is_new, $element);
     // set the type of the boolean attributes
     settype($values['manual_input'], 'boolean');
     // check "orderdetails_id"
     try {
         $orderdetails = new Orderdetails($database, $current_user, $log, $values['orderdetails_id']);
         // save orderdetails attributes to update its "last_modified" and "last_modified" of the part
         $orderdetails->set_attributes(array());
     } catch (Exception $e) {
         debug('error', 'Ungültige "orderdetails_id": "' . $values['orderdetails_id'] . '"' . "\n\nUrsprüngliche Fehlermeldung: " . $e->getMessage(), __FILE__, __LINE__, __METHOD__);
         throw new Exception('Die gewählten Einkaufsinformationen existieren nicht!');
     }
     // check "price"
     if (!is_numeric($values['price']) || $values['price'] < 0) {
         debug('error', 'Ungültiger Preis: "' . $values['price'] . '"', __FILE__, __LINE__, __METHOD__);
         throw new Exception('Der neue Preis ist ungültig!');
     }
     // check "price_related_quantity"
     if (!is_int($values['price_related_quantity']) && !ctype_digit($values['price_related_quantity']) || $values['price_related_quantity'] < 1) {
         debug('error', '"price_related_quantity" = "' . $values['price_related_quantity'] . '"', __FILE__, __LINE__, __METHOD__);
         throw new Exception('Die Preisbezogene Menge ist ungültig!');
     }
     // check "min_discount_quantity"
     if (!is_int($values['min_discount_quantity']) && !ctype_digit($values['min_discount_quantity']) || $values['min_discount_quantity'] < 1) {
         debug('error', '"min_discount_quantity" = "' . $values['min_discount_quantity'] . '"', __FILE__, __LINE__, __METHOD__);
         throw new Exception('Die Mengenrabatt-Menge ist ungültig!');
     }
     // search for pricedetails with the same "min_discount_quantity"
     $same_min_discount_quantity_count = 0;
     $all_pricedetails = $orderdetails->get_pricedetails();
     foreach ($all_pricedetails as $pricedetails) {
         if ($pricedetails->get_min_discount_quantity() == $values['min_discount_quantity']) {
             $same_min_discount_quantity_count++;
         }
     }
     if ($is_new) {
         // first pricedetails, but "min_discount_quantity" != 1 ?
         if (count($all_pricedetails) == 0 && $values['min_discount_quantity'] != 1) {
             throw new Exception('Die Mengenrabatt-Menge muss bei der ersten Preisangabe "1" sein!');
         }
         // is there already a pricedetails with the same "min_discount_quantity" ?
         if ($same_min_discount_quantity_count > 0) {
             throw new Exception('Es existiert bereits eine Preisangabe für die selbe Mengenrabatt-Menge!');
         }
     } elseif ($values['min_discount_quantity'] != $element->get_min_discount_quantity()) {
         // does the user try to change the "min_discount_quantity", but it is "1" ?
         if ($element->get_min_discount_quantity() == 1) {
             throw new Exception('Die Mengenrabatt-Menge beim Preis für ein Bauteil kann nicht verändert werden!');
         }
         // change the "min_discount_quantity" to a already existing value?
         if ($same_min_discount_quantity_count > 0) {
             throw new Exception('Es existiert bereits eine Preisangabe mit der selben Mengenrabatt-Menge!');
         }
     }
 }
예제 #3
0
 public function dist_order_details()
 {
     $delivery = $this->uri->segment(3);
     $data['title'] = "Order detail View";
     $data['content_view'] = "dist_orderdetail_v";
     $data['banner_text'] = "Order detail View";
     $data['link'] = "home";
     $data['quick_link'] = "moh_order_v";
     $data['detail_list'] = Orderdetails::get_order($delivery);
     $this->load->view("template", $data);
 }
예제 #4
0
         $new_attributes = array('name' => $new_name, 'description' => $new_description, 'instock' => $new_instock, 'mininstock' => $new_mininstock, 'id_category' => $new_category_id, 'id_storelocation' => $new_storelocation_id, 'visible' => $new_visible, 'comment' => $new_comment);
         // do not overwrite (remove!) the footprint or manufacturer if they are disabled (global or in the part's category)
         if (isset($_REQUEST['footprint_id'])) {
             $new_attributes['id_footprint'] = $new_footprint_id;
         }
         if (isset($_REQUEST['manufacturer_id'])) {
             $new_attributes['id_manufacturer'] = $new_manufacturer_id;
         }
         $part->set_attributes($new_attributes);
     } catch (Exception $e) {
         $messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red');
     }
     break;
 case 'orderdetails_add':
     try {
         $new_orderdetails = Orderdetails::add($database, $current_user, $log, $part_id, $new_supplier_id, $new_supplierpartnr, $new_obsolete);
     } catch (Exception $e) {
         $messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red');
     }
     break;
 case 'orderdetails_apply':
     try {
         if (!is_object($orderdetails)) {
             throw new Exception('Es ist keine Einkaufsinformation ausgewählt!');
         }
         $orderdetails->set_attributes(array('id_supplier' => $new_supplier_id, 'supplierpartnr' => $new_supplierpartnr, 'obsolete' => $new_obsolete));
     } catch (Exception $e) {
         $messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red');
     }
     break;
 case 'orderdetails_delete':
예제 #5
0
/**
 * @brief Import Parts (create Parts, and if neccessary, Categories, Footprints and so on)
 *
 * @note    This function uses database transactions. If an error occurs, all changes will be rolled back.
 *
 * @param Database  &$database          reference to the database object
 * @param User      &$current_user      reference to the user which is logged in
 * @param Log       &$log               reference to the Log-object
 * @param array     $data               The import data array from "extract_import_data_from_request()"
 * @param boolean   $only_check_data    If true, this function will only check if all values in "$data" are valid.
 *                                      In this case, no parts will be imported!
 *
 * @retval array    All new Part objects (only if "$only_check_data == false")
 *
 * @throws Exception    if there was an error (maybe the passed data is not valid)
 */
function import_parts(&$database, &$current_user, &$log, $data, $only_check_data = false)
{
    $parts = array();
    try {
        $transaction_id = $database->begin_transaction();
        // start transaction
        // Get the category, footprint, storelocation, ... which are named "Import", or create them.
        // We need this elements as parent for new elements, which will be created while import parts.
        $import_categories = Category::search($database, $current_user, $log, 'Import', true);
        if (count($import_categories) > 0) {
            $import_category = $import_categories[0];
            $import_category_created = false;
        } else {
            $import_category = Category::add($database, $current_user, $log, 'Import', NULL);
            $import_category_created = true;
            // we can delete it later if we didn't need it
        }
        $import_storelocations = Storelocation::search($database, $current_user, $log, 'Import', true);
        if (count($import_storelocations) > 0) {
            $import_storelocation = $import_storelocations[0];
            $import_storelocation_created = false;
        } else {
            $import_storelocation = Storelocation::add($database, $current_user, $log, 'Import', NULL);
            $import_storelocation_created = true;
            // we can delete it later if we didn't need it
        }
        $import_footprints = Footprint::search($database, $current_user, $log, 'Import', true);
        if (count($import_footprints) > 0) {
            $import_footprint = $import_footprints[0];
            $import_footprint_created = false;
        } else {
            $import_footprint = Footprint::add($database, $current_user, $log, 'Import', NULL);
            $import_footprint_created = true;
            // we can delete it later if we didn't need it
        }
        $import_suppliers = Supplier::search($database, $current_user, $log, 'Import', true);
        if (count($import_suppliers) > 0) {
            $import_supplier = $import_suppliers[0];
            $import_supplier_created = false;
        } else {
            $import_supplier = Supplier::add($database, $current_user, $log, 'Import', NULL);
            $import_supplier_created = true;
            // we can delete it later if we didn't need it
        }
        $import_manufacturers = Manufacturer::search($database, $current_user, $log, 'Import', true);
        if (count($import_manufacturers) > 0) {
            $import_manufacturer = $import_manufacturers[0];
            $import_manufacturer_created = false;
        } else {
            $import_manufacturer = Manufacturer::add($database, $current_user, $log, 'Import', NULL);
            $import_manufacturer_created = true;
            // we can delete it later if we didn't need it
        }
        $import_category_used = false;
        $import_storelocation_used = false;
        $import_footprint_used = false;
        $import_supplier_used = false;
        $import_manufacturer_used = false;
        // start import
        $row_index = 0;
        foreach ($data as $row) {
            $name = $row['part_name'];
            $description = $row['part_description'];
            $instock = $row['part_instock'];
            $mininstock = $row['part_mininstock'];
            $comment = $row['part_comment'];
            $category_name = $row['part_category_name'];
            $footprint_name = $row['part_footprint_name'];
            $storelocation_name = $row['part_storelocation_name'];
            $manufacturer_name = $row['part_manufacturer_name'];
            $supplier_name = $row['part_supplier_name'];
            $supplierpartnr = $row['part_supplierpartnr'];
            $price = $row['part_price'];
            // search elements / create them if they don't exist already
            if (strlen($category_name) > 0) {
                $categories = Category::search($database, $current_user, $log, $category_name, true);
                if (count($categories) > 0) {
                    $category = $categories[0];
                } else {
                    $category = Category::add($database, $current_user, $log, $category_name, $import_category->get_id());
                    $import_category_used = true;
                }
            } else {
                throw new Exception('Jedes Bauteil muss eine Kategorie haben!');
            }
            if (strlen($storelocation_name) > 0) {
                $storelocations = Storelocation::search($database, $current_user, $log, $storelocation_name, true);
                if (count($storelocations) > 0) {
                    $storelocation = $storelocations[0];
                } else {
                    $storelocation = Storelocation::add($database, $current_user, $log, $storelocation_name, $import_storelocation->get_id());
                    $import_storelocation_used = true;
                }
            }
            if (strlen($manufacturer_name) > 0) {
                $manufacturers = Manufacturer::search($database, $current_user, $log, $manufacturer_name, true);
                if (count($manufacturers) > 0) {
                    $manufacturer = $manufacturers[0];
                } else {
                    $manufacturer = Manufacturer::add($database, $current_user, $log, $manufacturer_name, $import_manufacturer->get_id());
                    $import_manufacturer_used = true;
                }
            }
            if (strlen($footprint_name) > 0) {
                $footprints = Footprint::search($database, $current_user, $log, $footprint_name, true);
                if (count($footprints) > 0) {
                    $footprint = $footprints[0];
                } else {
                    $footprint = Footprint::add($database, $current_user, $log, $footprint_name, $import_footprint->get_id());
                    $import_footprint_used = true;
                }
            }
            if (strlen($supplier_name) > 0) {
                $suppliers = Supplier::search($database, $current_user, $log, $supplier_name, true);
                if (count($suppliers) > 0) {
                    $supplier = $suppliers[0];
                } else {
                    $supplier = Supplier::add($database, $current_user, $log, $supplier_name, $import_supplier->get_id());
                    $import_supplier_used = true;
                }
            } else {
                if (strlen($supplierpartnr) > 0 || $price > 0) {
                    throw new Exception('Ist eine Bestellnummer oder ein Preis angegeben, so muss auch ein Lieferant angegeben werden!');
                }
            }
            $new_part = Part::add($database, $current_user, $log, $name, $category->get_id(), $description, $instock, $mininstock, isset($storelocation) ? $storelocation->get_id() : NULL, isset($manufacturer) ? $manufacturer->get_id() : NULL, isset($footprint) ? $footprint->get_id() : NULL, $comment);
            if (isset($supplier)) {
                $new_orderdetails = Orderdetails::add($database, $current_user, $log, $new_part->get_id(), $supplier->get_id(), $supplierpartnr);
                if ($price > 0) {
                    $new_pricedetails = Pricedetails::add($database, $current_user, $log, $new_orderdetails->get_id(), $price);
                }
            }
            if (!$only_check_data) {
                $parts[] = $new_part;
            }
            $row_index++;
        }
        // delete all elements which were created in this function, but were not used
        if ($import_category_created && !$import_category_used) {
            $import_category->delete();
        }
        if ($import_storelocation_created && !$import_storelocation_used) {
            $import_storelocation->delete();
        }
        if ($import_footprint_created && !$import_footprint_used) {
            $import_footprint->delete();
        }
        if ($import_supplier_created && !$import_supplier_used) {
            $import_supplier->delete();
        }
        if ($import_manufacturer_created && !$import_manufacturer_used) {
            $import_manufacturer->delete();
        }
        if ($only_check_data) {
            $database->rollback();
        } else {
            $database->commit($transaction_id);
        }
        // commit transaction
    } catch (Exception $e) {
        $database->rollback();
        // rollback transaction
        throw new Exception((isset($row_index) ? 'Nr. ' . ($row_index + 1) . ': ' : '') . $e->getMessage());
    }
    return $parts;
}
예제 #6
0
    public function get_order_details_report()
    {
        $order_id = 0;
        $kemsa_id = NULL;
        $order_id = $this->uri->segment(3);
        $kemsa_id = $this->uri->segment(4);
        $detail_list = Orderdetails::get_order($order_id);
        $table_body = "";
        $total_fill_rate = 0;
        $order_value = 0;
        $tester = count($detail_list);
        if ($tester == 0) {
        } else {
            foreach ($detail_list as $rows) {
                //setting the values to display
                $received = $rows->quantityRecieved;
                $price = $rows->price;
                $ordered = $rows->quantityOrdered;
                $code = $rows->kemsa_code;
                $total = $price * $ordered;
                if ($ordered == 0) {
                    $ordered = 1;
                }
                $fill_rate = round($received / $ordered * 100, 0, PHP_ROUND_HALF_UP);
                $total_fill_rate = $total_fill_rate + $fill_rate;
                foreach ($rows->Code as $drug) {
                    $drug_name = $drug->Drug_Name;
                    $kemsa_code = $drug->Kemsa_Code;
                    $unit_size = $drug->Unit_Size;
                    foreach ($drug->Category as $cat) {
                        $cat_name = $cat;
                    }
                }
                switch ($fill_rate) {
                    case $fill_rate == 0:
                        $table_body .= "<tr style=' background-color: #FBBBB9;'>";
                        $table_body .= "<td>{$cat_name}</td>";
                        $table_body .= '<td>' . $drug_name . '</td><td>' . $kemsa_code . '</td>' . '<td>' . $unit_size . '</td>';
                        $table_body .= '<td>' . $price . '</td>';
                        $table_body .= '<td>' . $ordered . '</td>';
                        $table_body .= '<td>' . number_format($total, 2, '.', ',') . '</td>';
                        $table_body .= '<td>' . $received . '</td>';
                        $table_body .= '<td>' . $fill_rate . '% ' . '</td>';
                        $table_body .= '</tr>';
                        break;
                    case $fill_rate <= 60:
                        $table_body .= "<tr style=' background-color: #FAF8CC;'>";
                        $table_body .= "<td>{$cat_name}</td>";
                        $table_body .= '<td>' . $drug_name . '</td><td>' . $kemsa_code . '</td>' . '<td>' . $unit_size . '</td>';
                        $table_body .= '<td>' . $price . '</td>';
                        $table_body .= '<td>' . $ordered . '</td>';
                        $table_body .= '<td>' . number_format($total, 2, '.', ',') . '</td>';
                        $table_body .= '<td>' . $received . '</td>';
                        $table_body .= '<td>' . $fill_rate . '% ' . '</td>';
                        $table_body .= '</tr>';
                        break;
                    case $fill_rate == 100.01 || $fill_rate > 100.01:
                        $table_body .= "<tr style=' background-color: #FBBBB9;'>";
                        $table_body .= "<td>{$cat_name}</td>";
                        $table_body .= '<td>' . $drug_name . '</td><td>' . $kemsa_code . '</td>' . '<td>' . $unit_size . '</td>';
                        $table_body .= '<td>' . $price . '</td>';
                        $table_body .= '<td>' . $ordered . '</td>';
                        $table_body .= '<td>' . number_format($total, 2, '.', ',') . '</td>';
                        $table_body .= '<td>' . $received . '</td>';
                        $table_body .= '<td>' . $fill_rate . '% ' . '</td>';
                        $table_body .= '</tr>';
                        break;
                    case $fill_rate == 100:
                        $table_body .= "<tr style=' background-color: #C3FDB8;'>";
                        $table_body .= "<td>{$cat_name}</td>";
                        $table_body .= '<td>' . $drug_name . '</td><td>' . $kemsa_code . '</td>' . '<td>' . $unit_size . '</td>';
                        $table_body .= '<td>' . $price . '</td>';
                        $table_body .= '<td>' . $ordered . '</td>';
                        $table_body .= '<td>' . number_format($total, 2, '.', ',') . '</td>';
                        $table_body .= '<td>' . $received . '</td>';
                        $table_body .= '<td>' . $fill_rate . '% ' . '</td>';
                        $table_body .= '</tr>';
                        break;
                    default:
                        $table_body .= "<tr>";
                        $table_body .= "<td>{$cat_name}</td>";
                        $table_body .= '<td>' . $drug_name . '</td><td>' . $kemsa_code . '</td>' . '<td>' . $unit_size . '</td>';
                        $table_body .= '<td>' . $price . '</td>';
                        $table_body .= '<td>' . $ordered . '</td>';
                        $table_body .= '<td>' . number_format($total, 2, '.', ',') . '</td>';
                        $table_body .= '<td>' . $received . '</td>';
                        $table_body .= '<td>' . $fill_rate . '% ' . '</td>';
                        $table_body .= '</tr>';
                        break;
                }
            }
            $order_value = round($total_fill_rate / count($detail_list), 0, PHP_ROUND_HALF_UP);
        }
        $table_head = '<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><div > Fill Rate = (Quantity Received / Quantity Ordered ) * 100</div>
<caption ><p style="letter-spacing: 1px;font-weight: bold;text-shadow: 0 1px rgba(0, 0, 0, 0.1);font-size: 14px; " >Facility Order No ' . $order_id . ' | KEMSA Order No ' . $kemsa_id . '  |Order Fill Rate ' . $order_value . '%</p></caption><table class="data-table" style="margin-left: 0px">
<tr>
<td width="50px" style="background-color: #C3FDB8; "></td><td>Full Delivery 100%</td><td width="50px" style="background-color:#FFFFFF"></td><td>Ok Delivery 60%-less than 100%</td><td width="50px" style="background-color:#FAF8CC;"></td><td>Partial Delivery less than 60% </td><td width="50px" style="background-color:#FBBBB9;"></td><td>Problematic Delivery 0% or over 100%</td>
</tr></table>
<table class="data-table" width="100%">
<thead>
<tr>
<th><strong>Category</strong></th>
<th><strong>Description</strong></th>
<th><strong>KEMSA&nbsp;Code</strong></th>
<th><strong>Unit Size</strong></th>
<th><strong>Unit Cost Ksh</strong></th>
<th><strong>Quantity Ordered</strong></th>
<th><strong>Total Cost</strong></th>
<th><strong>Quantity Received</strong></th>
<th><strong>Fill rate</strong></th>
</tr>
</thead>
<tbody>';
        //echo $table_body;
        $table_foot = '</tbody></table>';
        $report_name = "Order-{$order_id}-detail-fill-rate";
        $title = "Order number {$order_id} fill rate";
        $html_data = $table_head . $table_body . $table_foot;
        $report_type = 'Download PDF';
        $this->generate_pdf($report_name, $title, $html_data, $report_type);
    }
예제 #7
0
    public function update_order()
    {
        $this->load->helper('file');
        $this->load->library('mpdf');
        $new_value = @$_POST['quantity'];
        $price = @$_POST['price'];
        $order_id = @$_POST['order_id'];
        $value = count($new_value);
        $code = @$_POST['f_order_id'];
        $s_quantity = @$_POST['actual_quantity'];
        $order_total = 0;
        $reject_order = @$_POST['reject_order_status'];
        $value == 0 ? redirect("order_approval/district_orders") : $blank_data;
        $user_id = $facility_c = $this->session->userdata('user_id');
        if ($reject_order == 1) {
            // do not update the order
        } else {
            for ($i = 0; $i < $value; $i++) {
                $myobj = Doctrine::getTable('Orderdetails')->find($order_id[$i]);
                $myobj->quantityOrdered = $new_value[$i];
                $myobj->s_quantity = $s_quantity[$i];
                $myobj->save();
                //$total=$total*($new_value[$i]*$price[$i]);
                //echo $new_value[$i];
            }
        }
        $from_ordertbl = Ordertbl::get_order($code, $user_id);
        $from_order_details = Orderdetails::get_order($code);
        $total = 0;
        //update the order based on how the district pham has rationalized it
        $checker = 1;
        $in = Doctrine_Manager::getInstance()->getCurrentConnection()->fetchAll("SELECT a.category_name, b.drug_name,b.total_units, b.kemsa_code, b.unit_size, b.unit_cost, \n\t\tc.quantityOrdered, c.price, c.orderNumber, c.quantityRecieved,\n\t\tc.o_balance, c.t_receipts, c.t_issues, c.adjust, c.losses, c.days, c.comment, c.c_stock,c.s_quantity\nFROM drug_category a, drug b, orderdetails c\nWHERE c.orderNumber ={$code}\nAND b.id = c.kemsa_code\nAND a.id = b.drug_category\nORDER BY a.id ASC , b.drug_name ASC ");
        $jay = count($in);
        //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      <div style='text-align:center; font-size: 14px;display: block;font-weight: bold;'>Order Report</div>\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><hr />   ";
        //get the facility name and MFL code
        foreach ($from_ordertbl as $order) {
            $o_date = $order->orderDate;
            $a_date = $order->approvalDate;
            $o_total = $order->orderTotal;
            $d_rights = $order->drawing_rights;
            $bal = $d_rights - $o_total;
            $creator = $order->orderby;
            $approver = $order->approveby;
            foreach ($order->Code as $f_name) {
                $fac_name = $f_name->facility_name;
            }
            $mfl = $order->facilityCode;
            $myobj = Doctrine::getTable('Facilities')->findOneByfacility_code($mfl);
            $diasto = $myobj->district;
            $myobj1 = Doctrine::getTable('Districts')->find($diasto);
            $disto_name = $myobj1->district;
            $county = $myobj1->county;
            $myobj2 = Doctrine::getTable('Counties')->find($county);
            $county_name = $myobj2->county;
            $myobj_order = Doctrine::getTable('User')->find($creator);
            $creator_name = $myobj_order->email;
            $creator_name1 = $myobj_order->fname;
            $creator_name2 = $myobj_order->lname;
            $creator_telephone = $myobj_order->telephone;
        }
        //create the table for displaying the order details
        $html_body = "<table class='data-table' width=100%>\n<tr>\n<td>MFL No: {$mfl}</td> \n<td >Health Facility Name:<br/> {$fac_name}</td>\n<td >Total OPD Visits & Revisits: </td>\n<td >Level:</td>\n<td>Dispensary</td>\n<td >Health Centre</td>\n</tr>\n<tr>\n<td>County: {$county_name}</td> \n<td > District: {$disto_name}</td>\n<td >In-patient Bed Days : </td>\n<td >Order Date:<br/> " . date('d M, Y', strtotime($o_date)) . " </td>\n<td>Order no.</td>\n<td >Reporting Period <br/>\nStart Date:  <br/>  End Date: " . date('d M, Y', strtotime($o_date)) . "\n</td>\n</tr>\n</table>";
        $html_body .= "<style>table.data-table {border: 1px solid #DDD;margin: 10px auto;border-spacing: 0px;}\ntable.data-table th {border: none;color: #036;text-align: center;background-color: \t#FFF380;border: 1px solid #DDD;border-top: none;max-width: 450px;}\ntable.data-table td, table th {padding: 4px;}\ntable.data-table td {border: none;border-left: 1px solid #DDD;border-right: 1px solid #DDD;height: 30px;margin: 0px;border-bottom: 1px solid #DDD;}\n</style>\n<table class='data-table'>\n\n\n<thead><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>\n<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>\n<th><b>Order Quantity (Packs)</b></th><th><b>Order Quantity (Actual Units)</b></th><th><b>Order cost(Ksh)</b></th><th><b>Comment</b></th></tr> </thead><tbody>";
        $html_body .= '<ol type="a">';
        for ($i = 0; $i < $jay; $i++) {
            if ($i == 0) {
                $html_body .= '<tr style="background-color:#C6DEFF;"> <td colspan="15" >
				 <li> ' . $in[$i]['category_name'] . ' </li> </td></tr>';
            } else {
                if ($in[$i]['category_name'] != $in[$i - 1]['category_name']) {
                    $html_body .= '<tr style="background-color:#C6DEFF;"> <td  colspan="15"> 
       	 	<li> ' . $in[$i]['category_name'] . ' </li> </td></tr>';
                }
            }
            $adj = $in[$i]['adjust'];
            $c_stock = $in[$i]['c_stock'];
            $o_t = $in[$i]['quantityOrdered'];
            $o_q = $in[$i]['price'];
            $o_bal = $in[$i]['o_balance'];
            $t_re = $in[$i]['t_receipts'];
            $t_issues = $in[$i]['t_issues'];
            $losses = $in[$i]['losses'];
            $total = $o_t * $in[$i]['total_units'];
            if ($o_bal == 0 && $t_re == 0 && $t_issues > 0) {
                $adj = $t_issues;
            }
            $c_stock = $o_bal + $t_re + $adj - $losses - $t_issues;
            if ($c_stock < 0) {
                $adj = $c_stock * -1;
            }
            $c_stock = $o_bal + $t_re + $adj - $losses - $t_issues;
            $html_body .= "<tr>";
            $html_body .= "<td>" . $in[$i]['kemsa_code'] . "</td>";
            $html_body .= "<td>" . $in[$i]['drug_name'] . "</td>";
            $html_body .= "<td>" . $in[$i]['unit_size'] . "</td>";
            $ot = number_format($o_t * $o_q, 2, '.', ',');
            $order_total = $order_total + $o_t * $o_q;
            $html_body .= "<td>{$o_q}</td>";
            $html_body .= "<td>" . $o_bal . "</td>";
            $html_body .= "<td>" . $t_re . "</td>";
            $html_body .= "<td>" . $t_issues . "</td>";
            $html_body .= "<td>" . $adj . "</td>";
            $html_body .= "<td>" . $losses . "</td>";
            $html_body .= "<td>" . $c_stock . "</td>";
            $html_body .= "<td>" . $in[$i]['days'] . "</td>";
            $html_body .= "<td>{$o_t}</td>";
            $html_body .= "<td>{$total}</td>";
            $html_body .= "<td>{$ot}</td>";
            $html_body .= "<td>" . $in[$i]['comment'] . "</td></tr>";
        }
        $myobj_approve = Doctrine::getTable('User')->find($approver);
        $approve_name = $myobj_approve->email;
        $approve_name1 = $myobj_approve->fname;
        $approve_name2 = $myobj_approve->lname;
        $approve_telephone = $myobj_approve->telephone;
        $bal = $d_rights - $order_total;
        $html_body .= '</tbody></table></ol>';
        $html_body1 = '<table class="data-table" width="100%" style="background-color: 	#FFF380;">
		  <tr style="background-color: 	#FFFFFF;" > <td colspan="4" ><div style="float: left" > Total Order Value:</div><div style="float: right" >KSH ' . number_format($order_total, 2, '.', ',') . '</div> </td></tr>
		   <tr style="background-color: 	#FFFFFF;"  > <td colspan="4" ><div style="float: left" > Drawing Rights Available Balance:</div><div style="float: right" >KSH		' . number_format($bal, 2, '.', ',') . '</div> </td></tr>
		   <tr><td>FACILITY TEL NO:</td><td colspan="3">FACILITY EMAIL:</td>
		   </tr>
		   <tr><td >Prepared by (Name/Designation) ' . $creator_name1 . ' ' . $creator_name2 . '
		   <br/>
		   <br/>Email: ' . $creator_name . '</td><td>Tel: ' . $creator_telephone . '</td><td>Date: ' . date('d M, Y', strtotime($o_date)) . '</td><td>Signature</td>
		   </tr>
		   <tr><td>Checked by (Name/DPF/DPHN)
		   <br/>
		   <br/>Email</td><td>Tel</td><td>Date</td><td>Signature</td>
		   </tr>
		   <tr><td>Authorised by (Name/DMoH) ' . $approve_name1 . ' ' . $approve_name2 . '
		   <br/>
		   <br/>Email: ' . $approve_name . '</td><td>Tel: ' . $approve_telephone . '</td><td>Date: ' . date('d M, Y', strtotime($a_date)) . '</td><td>Signature</td>
		   
		   </tr>
		   </table>';
        $myobj = Doctrine::getTable('Ordertbl')->find($code);
        $myobj->orderTotal = $order_total;
        $myobj->save();
        //now ganerate an order pdf from the generated report
        $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->AddPage();
        $this->mpdf->WriteHTML($html_body1);
        if ($reject_order == 1) {
            $status = 'rejected';
        } else {
            $status = 'approved';
        }
        $report_name = $status . '_facility_order_no_' . $code . '_date_' . date('d-m-y');
        //$this->mpdf->Output('$report_name','I');
        //exit;
        if (!write_file('./pdf/' . $report_name . '.pdf', $this->mpdf->Output('$report_name', 'S'))) {
            $this->session->set_flashdata('system_error_message', 'An error occured');
            redirect("order_approval/district_orders");
        } else {
            $subject = $reject_order == 1 ? 'Rejected Order Report For ' . $fac_name : 'Approved Order Report For ' . $fac_name;
            $attach_file = './pdf/' . $report_name . '.pdf';
            $message = $html_title . $html_body . $html_body1;
            $message_1 = $reject_order == 0 ? '<br>Please find the approved Order for  ' . $fac_name . '
		<br>
		<br>' : '<br>Please note the order for  ' . $fac_name . ' Has been rejected by ' . $approve_name1 . ' ' . $approve_name2 . '.
		<br>
		Find the attached order, correct it
		<br>';
            $response = $this->send_order_approval_email($message_1 . $message, $subject, $attach_file, $mfl, $reject_order);
            if ($response) {
                delete_files('./pdf/' . $report_name . '.pdf');
            }
        }
        if ($reject_order == 1) {
            $myobj = Doctrine::getTable('Ordertbl')->find($code);
            $myobj->orderStatus = "rejected";
            $myobj->save();
            $this->send_order_approval_sms($mfl, $reject_order);
            $this->session->set_flashdata('system_success_message', "Order No {$code} has been rejected and the facility personel have been notified");
        } else {
            $this->send_order_approval_sms($mfl, $reject_order);
            $this->session->set_flashdata('system_success_message', "Order No {$code} has been approved");
        }
        redirect("order_approval/district_orders");
    }
예제 #8
0
 public function new_update()
 {
     $id = $this->uri->segment(3);
     $data['title'] = "Update Deliveries";
     $data['content_view'] = "new_update";
     $data['banner_text'] = "Update Order Delivery";
     $data['quick_link'] = "new_update";
     $data['ord'] = Ordertbl::get_details($id);
     $data['order_details'] = Orderdetails::get_order_details($id);
     $data['drugs'] = Drug::getAll();
     $this->load->view("template", $data);
 }