Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- date_default_timezone_set("Europe/Sofia");
- $today = "07/08/2014";
- $invoices = array("11/05/2013 | Sopharma | Paracetamol | 20.54 lv",
- "11/05/2013 | Sopharma | Analgin | 57.45 lv",
- "02/12/2011 | Actavis | Aulin | 120.54 lv",
- "13/05/2009 | Sopharma | Tamiflu | 221.54 ",
- "23/01/2014 | Actavis | Paracetamol | 7.54 ",
- "11/05/2013 | Actavis | Paracetamol | 17.54 ");
- /*$today = $_GET['today'];
- $invoices = $_GET['invoices'];*/
- $invoices = array_filter($invoices, function($val) {
- $tempInspectTime = $GLOBALS['today'];
- $inspectorVisit = new DateTime(str_replace('/', '-', $tempInspectTime));
- $regex = "/(\s*\d{2}\/\d{2}\/\d{4})\s*/";
- preg_match($regex, $val, $getDate);
- $invoiceDate = new DateTime(str_replace('/', '-', $getDate[1]));
- $interval = $inspectorVisit->diff($invoiceDate);
- if($interval->days > 1825) {
- return false;
- }
- $helpCompareInspectorDate = date("Y-m-d", strtotime($GLOBALS['today']));
- $helpCompareInvoiceDate = date("Y-m-d", strtotime($getDate[1]));
- if($helpCompareInspectorDate < $helpCompareInvoiceDate) {
- return false;
- }
- return true;
- });
- function byDate($a, $b) {
- $regex = "/(\s*\d{2}\/\d{2}\/\d{4})\s*/";
- preg_match($regex, $a, $first);
- preg_match($regex, $b, $second);
- $temp1 = date("d-m-Y", strtotime(str_replace('/', '-',$first[1])));
- $temp2 = date("d-m-Y", strtotime(str_replace('/', '-',$second[1])));
- $date1 = date("Y-d-m", strtotime($temp1));
- $date2 = date("Y-d-m", strtotime($temp2));
- return strcmp($date1, $date2);
- }
- usort($invoices, 'byDate');
- $map = array();
- for($i = 0; $i < count($invoices) ;$i++) {
- $reg = "/^(\s*\d{2}\/\d{2}\/\d{4})\s*\|\s*(.*?)\s*\|\s*(.*?)\s*\|\s*([\d\.]+)\s*([\w\.]+)?$/";
- preg_match($reg, $invoices[$i], $info);
- $date = $info[1];
- $company = $info[2];
- $drug = $info[3];
- $cost = $info[4];
- $currency = "";
- if(!empty($info[5])) {
- $currency = $info[5];
- } else {
- $currency = "";
- }
- if(!array_key_exists($date, $map)) {
- $map[$date] = array();
- }
- if(!array_key_exists($company, $map[$date])) {
- $map[$date][$company] = array();
- $map[$date][$company]["drugs"] = array();
- $map[$date][$company]["total"] = 0;
- $map[$date][$company]["curr"] = "";
- }
- $map[$date][$company]["drugs"][] = $drug;
- $map[$date][$company]["total"] += $cost;
- $map[$date][$company]["curr"] = $currency;
- }
- foreach ($map as $key => &$value) {
- ksort($map[$key]);
- foreach ($value as &$company) {
- asort($company["drugs"]);
- }
- }
- $table = "<ul>";
- foreach ($map as $key => &$value) {
- $table .= "<li><p>" . htmlspecialchars($key) . "</p><ul>";
- foreach ($value as $key1 => $value1) {
- $table .= "<li><p>" . htmlspecialchars($key1) . "</p><ul>";
- $table .= "<li><p>" . implode(',', $value1["drugs"]) . "-" . $value1["total"] . $value1["curr"] .
- "</p></li>";
- }
- $table .= "</ul></li></ul>";
- }
- $table .= "</ul>";
- echo $table;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement