function myIncomeOf6Months($supcode) { //to get total supply for perticular supplier in LAST 6 months $dbmain = new DBmain(); $formateddate = date("Y-m-d"); $resarr = array(); $curyear = substr($formateddate, 0, 4); $curmonth = substr($formateddate, 5, 7); $lstrunningmonth = substr($formateddate, 5, 7); for ($i = 1; $i < 7; $i++) { $lstrunningmonth = $curmonth - $i; $m = $curmonth - $i; if ($lstrunningmonth == "0") { $curyear = $curyear - 1; $m = 12 + ($curmonth - $i); } if ($lstrunningmonth < 0) { $m = 12 + ($curmonth - $i); } if (strlen($m) == 1) { $m = "0" . $m; } $startday = $curyear . "-" . $m . "-01"; $enddate = $curyear . "-" . $m . "-31"; $condition = " WHERE supplier_code='" . $supcode . "' AND date BETWEEN '" . $startday . "' AND '" . $enddate . "'"; $res = $dbmain->selectData("daily_supply", array("approved_kgs"), $condition); $total = 0; if (count($res) > 0) { foreach ($res as $r) { $total = $total + $r['approved_kgs']; } $resarr[$i - 1] = $total * DBupdates::teaRateofMonth($startday); } else { $resarr[$i - 1] = 0; } } return $resarr; }