I got this simple foreach loop and can't figure out where is the problem with counter.
I get results like this. I am trying to make counter enlarged for one if it meets the conditions.
$building = 5;
$todaysdate = date("Y-m-d");
$tomorrows_date = date("Y-m-d", strtotime($todaysdate . "+1 days"));
$ends_date = "2018-04-30";
$counter = 0;
$query = "SELECT * FROM objekt WHERE vrsta_objekta = '2' ORDER BY sifra ASC"; // results give me numbers from 30 to 110.
$querydone = $db->query($query);
while($row = $querydone->fetch_assoc()) {
$every_id[$row['sifra']] = $row;
}
$firstday = new DateTime($tomorrows_date);
$lastday = new DateTime($ends_date);
for($q = $firstday; $q <= $lastday; $q->modify('+1 day')){
$result_day = $q->format("Y-m-d");
$i = 0; // counter for every value from mysql
foreach ($every_id as $key => $value) {
$counter = ${$i++} = $value['sifra'];
if($building >= $i) {
$valuesResult = "('$result_day','$counter')" . "<br />";
} else {
break;
}
echo $valuesResult;
}
}
Where am I wrong?
$building = 5;
$todaysdate = date("Y-m-d");
$tomorrows_date = date("Y-m-d", strtotime($todaysdate . "+1 days"));
$ends_date = "2018-04-30";
$counter = 0;
$query = "SELECT * FROM objekt WHERE vrsta_objekta = '2' ORDER BY sifra ASC LIMIT 80"; // results give me numbers from 30 to 110.
$querydone = $db->query($query);
while($row = $querydone->fetch_assoc()) {
$every_id = $row['sifra'];
}
$firstday = new DateTime($tomorrows_date);
$lastday = new DateTime($ends_date);
for($q = $firstday; $q <= $lastday; $q->modify('+1 day')){
$result_day = $q->format("Y-m-d");
$i = 0; // counter for every value from mysql
foreach ($every_id as $key => $value) {
$counter = $i++;
if($building >= $i) {
$valuesResult = "('$result_day','$counter')" . "<br />";
} else {
break;
}
echo $valuesResult;
}
}
Related
Hello im using codeigniter and this controller file for cronjob but somehow public function fiveminutes work and gives response(ok) but public function daily doesn’t work and no responses or errors it should give “ok daily” response can someone help please ?? i couldn’t solve this
Hope someone fan help me because its realy important for me and my users
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Cronjob extends Guess_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model(['m_admin', 'm_cronjob', 'm_leaderboard']);
}
public function fiveminutes()
{
if (time() >= $this->data['settings']['leaderboard_date']) {
$topClaimer = $this->m_leaderboard->getTopClaimer($this->data['settings']['admin_username']);
$topReferral = $this->m_leaderboard->getTopReferral($this->data['settings']['admin_username']);
$topFaucet = $this->m_leaderboard->getTopFaucet($this->data['settings']['admin_username']);
$topShortlink = $this->m_leaderboard->getTopShortlink($this->data['settings']['admin_username']);
$topOfferwall = $this->m_leaderboard->getTopOfferwall($this->data['settings']['admin_username']);
$activityRewards = explode('|', $this->data['settings']['activity_contest_reward']);
$referralRewards = explode('|', $this->data['settings']['referral_contest_reward']);
$faucetRewards = explode('|', $this->data['settings']['faucet_contest_reward']);
$shortlinkRewards = explode('|', $this->data['settings']['shortlink_contest_reward']);
$offerwallRewards = explode('|', $this->data['settings']['offerwall_contest_reward']);
$nextTime = (date("Y-m-d", strtotime('Sunday')) == date("Y-m-d", time())) ? strtotime('Sunday') + 7 * 86400 : strtotime('Sunday');
$this->m_cronjob->updateLeaderboardDate($nextTime);
$this->m_cronjob->resetLeaderboard();
$this->cache->delete('leaderboard_info');
if (!empty($this->data['settings']['activity_contest_reward'])) {
for ($i = 0; $i < min(count($activityRewards), count($topClaimer)); ++$i) {
$this->m_core->addNotification($topClaimer[$i]['id'], currency($activityRewards[$i], $this->data['settings']['currency_rate']) . " from Activity Contest was credited to your balance.", 1);
$this->m_cronjob->updateUserBalance($topClaimer[$i]['id'], trim($activityRewards[$i]));
$this->m_core->addOtherLog($topClaimer[$i]['id'], 'Activity contest #' . ($i + 1), trim($activityRewards[$i]));
}
}
if (!empty($this->data['settings']['referral_contest_reward'])) {
for ($i = 0; $i < min(count($referralRewards), count($topReferral)); ++$i) {
$this->m_core->addNotification($topReferral[$i]['id'], currency($referralRewards[$i], $this->data['settings']['currency_rate']) . " from Referral Contest was credited to your balance.", 1);
$this->m_cronjob->updateUserBalance($topReferral[$i]['id'], trim($referralRewards[$i]));
$this->m_core->addOtherLog($topReferral[$i]['id'], 'Referral contest #' . ($i + 1), trim($referralRewards[$i]));
}
}
if (!empty($this->data['settings']['faucet_contest_reward'])) {
for ($i = 0; $i < min(count($faucetRewards), count($topFaucet)); ++$i) {
$this->m_core->addNotification($topFaucet[$i]['id'], currency($faucetRewards[$i], $this->data['settings']['currency_rate']) . " from Faucet Contest was credited to your balance.", 1);
$this->m_cronjob->updateUserBalance($topFaucet[$i]['id'], trim($faucetRewards[$i]));
$this->m_core->addOtherLog($topFaucet[$i]['id'], 'Faucet contest #' . ($i + 1), trim($faucetRewards[$i]));
}
}
if (!empty($this->data['settings']['shortlink_contest_reward'])) {
for ($i = 0; $i < min(count($shortlinkRewards), count($topShortlink)); ++$i) {
$this->m_core->addNotification($topShortlink[$i]['id'], currency($shortlinkRewards[$i], $this->data['settings']['currency_rate']) . " from Shortlink Contest was credited to your balance.", 1);
$this->m_cronjob->updateUserBalance($topShortlink[$i]['id'], trim($shortlinkRewards[$i]));
$this->m_core->addOtherLog($topShortlink[$i]['id'], 'Shortlink contest #' . ($i + 1), trim($shortlinkRewards[$i]));
}
}
if (!empty($this->data['settings']['offerwall_contest_reward'])) {
for ($i = 0; $i < min(count($offerwallRewards), count($topOfferwall)); ++$i) {
$this->m_core->addNotification($topOfferwall[$i]['id'], currency($offerwallRewards[$i], $this->data['settings']['currency_rate']) . " from Offerwall Contest was credited to your balance.", 1);
$this->m_cronjob->updateUserBalance($topOfferwall[$i]['id'], trim($offerwallRewards[$i]));
$this->m_core->addOtherLog($topOfferwall[$i]['id'], 'Offerwall contest #' . ($i + 1), trim($offerwallRewards[$i]));
}
}
echo 'ok 1';
}
if ($this->data['settings']['lottery_duration'] > 0) {
if (time() >= $this->data['settings']['lottery_date']) {
$lotteries = $this->m_cronjob->getAllLottery();
if (count($lotteries) > 0) {
$luckyNumber = rand(0, count($lotteries) - 1);
$reward = count($lotteries) * $this->data['settings']['lottery_reward'] + $this->data['settings']['lottery_base_reward'];
$this->m_cronjob->updateUserBalance($lotteries[$luckyNumber]['user_id'], $reward);
$this->m_cronjob->insertLotteryHistory($lotteries[$luckyNumber]['user_id'], $lotteries[$luckyNumber]['number'], $reward);
$user = $this->m_core->get_user_from_id($lotteries[$luckyNumber]['user_id']);
$this->m_core->addNotification($user['id'], currency($reward, $this->data['settings']['currency_rate']) . " from Lottery was credited to your balance.", 1);
$this->m_core->addOtherLog($user['id'], 'Lottery', $reward);
}
$this->m_cronjob->updateLotteryDate(time() + 86400 * $this->data['settings']['lottery_duration']);
$this->m_cronjob->resetLottery();
echo 'ok 2';
}
}
$offerHistory = $this->m_cronjob->getAvailableOffers();
foreach ($offerHistory as $history) {
$this->m_cronjob->updateUserBalance($history['user_id'], $history['amount']);
$this->m_cronjob->updateOfferwallHistoryStatus($history['id']);
$user = $this->m_core->get_user_from_id($history['user_id']);
$this->m_core->addExp($user['id'], $this->data['settings']['offerwall_exp_reward']);
$user['exp'] += $this->data['settings']['offerwall_exp_reward'];
if ($user['exp'] >= ($user['level'] + 1) * 100) {
$this->m_core->levelUp($user['id']);
}
}
echo 'ok 3';
$currencies = $this->m_cronjob->getCurrencyName();
$currencyName = [];
foreach ($currencies as $currency) {
array_push($currencyName, $currency['currency_name']);
}
if (!in_array("bitcoin", $currencyName)) {
array_push($currencyName, 'bitcoin');
}
$query = urlencode(implode(',', $currencyName));
$apiUrl = 'https://api.coingecko.com/api/v3/simple/price?ids=' . $query . '&vs_currencies=usd';
$result = #json_decode(get_data($apiUrl), TRUE);
foreach ($result as $name => $price) {
$this->m_cronjob->updatePrice($name, $price['usd']);
}
if (isset($result['bitcoin']) && isset($result['bitcoin']['usd'])) {
$this->m_cronjob->updateBtcPrice($result['bitcoin']['usd']);
}
echo 'ok 4';
}
public function daily()
{
$yesterday = strtotime('yesterday midnight');
$today = strtotime('today midnight');
$date = date("Y-m-d", strtotime('yesterday midnight'));
$todayData = [
'date' => date("Y-m-d", $today)
];
$yesterdayData = [
'date' => $date
];
if ($this->m_cronjob->isYesterdayExist($date)) {
$this->db->insert('faucet_stats', $yesterdayData);
}
if ($this->m_cronjob->checkYesterdayLog($date)) {
$yesterdayData['active_users'] = $this->m_cronjob->countActiveUsers($yesterday, $today);
$yesterdayData['new_users'] = $this->m_cronjob->countNewUsers($yesterday, $today);
$faucetStat = $this->m_cronjob->faucetStat($yesterday, $today);
$yesterdayData['faucet_count'] = $faucetStat['cnt'];
$yesterdayData['faucet_amount'] = $faucetStat['amount'];
$shortlinkStat = $this->m_cronjob->shortlinkStat($yesterday, $today);
$yesterdayData['shortlink_count'] = $shortlinkStat['cnt'];
$yesterdayData['shortlink_amount'] = $shortlinkStat['amount'];
$offerwallStat = $this->m_cronjob->offerwallStat($yesterday, $today);
$yesterdayData['offerwall_count'] = $offerwallStat['cnt'];
$yesterdayData['offerwall_amount'] = $offerwallStat['amount'];
$offerwallStat = $this->m_cronjob->ptcStat($yesterday, $today);
$yesterdayData['ptc_count'] = $offerwallStat['cnt'];
$yesterdayData['ptc_amount'] = $offerwallStat['amount'];
$diceStat = $this->m_cronjob->diceStat($yesterday, $today);
$yesterdayData['dice_count'] = $diceStat['cnt'];
$yesterdayData['dice_amount'] = $diceStat['amount'];
$depositStat = $this->m_cronjob->depositStat($yesterday, $today);
$yesterdayData['deposit_count'] = $depositStat['cnt'];
$yesterdayData['deposit_amount'] = $depositStat['amount'];
$depositStat = $this->m_cronjob->withdrawStat($yesterday, $today);
$yesterdayData['withdraw_count'] = $depositStat['cnt'];
$yesterdayData['withdraw_amount'] = $depositStat['amount'];
$coinflipStat = $this->m_cronjob->coinflipStat($yesterday, $today);
$yesterdayData['coinflip_count'] = $coinflipStat['cnt'];
$yesterdayData['coinflip_amount'] = $coinflipStat['amount'];
$achievementStat = $this->m_cronjob->achievementStat($yesterday, $today);
$yesterdayData['achievement_count'] = $achievementStat['cnt'];
$yesterdayData['achievement_amount'] = $achievementStat['amount'];
$wheelStat = $this->m_cronjob->wheelStat($yesterday, $today);
$yesterdayData['wheel_count'] = $wheelStat['cnt'];
$yesterdayData['wheel_amount'] = $wheelStat['amount'];
$this->db->set('active_users', $yesterdayData['active_users']);
$this->db->set('new_users', $yesterdayData['new_users']);
$this->db->set('faucet_count', $yesterdayData['faucet_count']);
$this->db->set('faucet_amount', $yesterdayData['faucet_amount']);
$this->db->set('shortlink_count', $yesterdayData['shortlink_count']);
$this->db->set('shortlink_amount', $yesterdayData['shortlink_amount']);
$this->db->set('ptc_count', $yesterdayData['ptc_count']);
$this->db->set('ptc_amount', $yesterdayData['ptc_amount']);
$this->db->set('offerwall_count', $yesterdayData['offerwall_count']);
$this->db->set('offerwall_amount', $yesterdayData['offerwall_amount']);
$this->db->set('dice_count', $yesterdayData['dice_count']);
$this->db->set('dice_amount', $yesterdayData['dice_amount']);
$this->db->set('coinflip_count', $yesterdayData['coinflip_count']);
$this->db->set('coinflip_amount', $yesterdayData['coinflip_amount']);
$this->db->set('achievement_count', $yesterdayData['achievement_count']);
$this->db->set('achievement_amount', $yesterdayData['achievement_amount']);
$this->db->set('deposit_amount', $yesterdayData['deposit_amount']);
$this->db->set('deposit_count', $yesterdayData['deposit_count']);
$this->db->set('deposit_amount', $yesterdayData['deposit_amount']);
$this->db->set('withdraw_amount', $yesterdayData['withdraw_amount']);
$this->db->set('wheel_amount', $yesterdayData['wheel_amount']);
$this->db->set('wheel_count', $yesterdayData['wheel_count']);
$this->db->set('is_done', 1);
$this->db->where('date', $date);
$this->db->update('faucet_stats');
$this->db->insert('faucet_stats', $todayData);
$this->m_cronjob->clearHistory();
$this->db->set('wheel_cnt', 0);
$this->db->set('today_faucet', 0);
$this->db->update('users');
echo 'ok daily';
}
}
}
Most likely this function
if($this->m_cronjob->checkYesterdayLog($date))
results to false. I recommend that you should test this first.
if($this->m_cronjob->checkYesterdayLog($date)){
echo 'okay daily';
}else{
echo 'not okay, daily';
}
You can also check if the cronjob actually calls the daily function.
I would appreciate some guidance on the following issue. I am by no means an expert in php. The code below takes almost 10 seconds to execute! Is there anything I am doing that is wrong or bad practice?
$data = [];
$today = date("Y/m/d");
$ThisYear = Date('Y'); //get current Year
$ThisMonth = Date('m'); //get current month
$Tday = '01'; //first day of month
$Tmonth = '09'; //September
if (8 < $ThisMonth && $ThisMonth < 13) {
$AcYear = $ThisYear; }
else {
$AcYear = $ThisYear - 1; // sets start of academic year to be last year
}
$AcFullYear = $AcYear.'/'.$Tmonth.'/'.$Tday;
//find rank in all school
$students_rank = [];
$school_id = Student::model()->findByAttributes(['user_master_id' => Yii::app()->user->id])->school_master_id;
$criteria1 = new CDbCriteria;
$criteria1->with = array('user');
$criteria1->condition = "t.school_master_id=:school_master AND user.status ='1'";
$criteria1->params = array(':school_master' => $school_id);
$school_students_details = Student::model()->findAll($criteria1);
foreach ($school_students_details as $key => $value) {
$student_name = StudentDetails::model()->findByAttributes(['user_master_id' => $value->user_master_id]); //student details with year group
$criteria2 = new CDbCriteria;
$criteria2->with = array('homeworkMaster');
$criteria2->condition = "t.student_id=:student_id AND homeworkMaster.question_type_id<>:question_type_id";
$criteria2->params = array(':student_id' => $value->user_master_id, ':question_type_id' => 6);
$HW_assignment_track = HomeworkAssignmentTrack::model()->findAll($criteria2);
$total_HW = count((array)$HW_assignment_track);
$student_score = 0;
$student_rank = 0;
$student_total_score = 0;
$total_HW_marks = 0;
$under_deadline_HW = 0;
$criteria3 = new CDbCriteria();
$criteria3->condition = "student_id =:student_id AND status=:status AND created_at >= '$AcFullYear' AND created_at <= '$today'";
$criteria3->params = [':student_id' => $value->user_master_id, ':status' => 2];
$student_completed_HW = HomeworkStudentAnswere::model()->findAll($criteria3);
$i = 1;
foreach ($student_completed_HW as $s_c_h_K => $s_c_h_V) {
if ($s_c_h_V->homework->homework_type == 2) {
$total_HW -= 1;
} elseif ($s_c_h_V->homework->homework_type == 1) {
$HW_questions = HomeworkQuestion::model()->findAllByAttributes(['homework_master_id' => $s_c_h_V->homework_id, 'status' => 1]);
foreach ($HW_questions as $qKey => $qVal) {
if ($qVal->question_type_id ==3) {
$total_HW_marks += 2;
} else {
$total_HW_marks += $qVal->marks;
}
}
$assignment = HomeworkAssignmentTrack::model()->findByAttributes(['id' => $s_c_h_V->assignment_track_id]);
$homeworks_within_validate = Assignment::model()->findByPk($assignment->assignment_id);
if ($homeworks_within_validate->valid_date === '0' && $homeworks_within_validate->deadline >= date('Y-m-d')) {
$total_HW -= 1;
}
if ($homeworks_within_validate->valid_date === '1' || (($homeworks_within_validate->valid_date === '0') && ($homeworks_within_validate->deadline >= date('Y-m-d', strtotime($s_c_h_V->created_at))) && ($homeworks_within_validate->deadline < date('Y-m-d')))) {
if ($s_c_h_V->review_status === '2') {
$student_total_score += $s_c_h_V->score;
}
}
$homework_submit = HomeworkCompleteNotification::model()->findByAttributes(['homework_id' => $s_c_h_V->homework_id, 'assignment_track_id' => $s_c_h_V->assignment_track_id, 'student_id' => $value->user_master_id]);
if (($homeworks_within_validate->valid_date === '0') && ($homeworks_within_validate->deadline >= date('Y-m-d', strtotime($homework_submit->created_at))) && ($s_c_h_V->review_status === '2')) {
$under_deadline_HW += 10;
}
if ($total_HW_marks !=0) {
$student_score += round(($student_total_score / $total_HW_marks) * 100);
} else {
$student_score = 0;
}
}
$i += 1;
}
//add revision scores to rank score
$criteria4 = new CDbCriteria();
$criteria4->condition = "user_id =:user_id AND date_created >= '$AcFullYear' AND date_created <= '$today'";
$criteria4->params = [':user_id' => $value->user_master_id];
$revision_score = RevisionScores::model()->findAll($criteria4);
$sum = 0;
foreach($revision_score as $item) {
$sum += $item['score'];
} //end of adding revision scores
$students_rank[$key]['student_id'] = $value->user_master_id;
$students_rank[$key]['year_group'] = $student_name->year_group_id; //added year group to model array
if ($student_score > 0) {
$student_rank += round($student_score / $total_HW, 0) + $under_deadline_HW;
$students_rank[$key]['rank'] = $student_rank + $sum;
} else {
$students_rank[$key]['rank'] = $sum;
}
}
$model = $this->multid_sort($students_rank, 'rank');
$rank_score = round(array_column($model, 'rank', 'student_id')[Yii::app()->user->id],0);
$year_rank =[];
$current_st = StudentDetails::model()->findByAttributes(['user_master_id' => Yii::app()->user->id]);
$current_st_year = $current_st->year_group_id;
$rank_list = [];
foreach ($model as $key => $value) {
$rank_list[] = $value['student_id'];
if ($value['year_group'] == $current_st_year) {
$year_rank[] = $value['student_id'];
}
}
$user = Yii::app()->user->id;
$sch_position = array_search($user,$rank_list);
$yr_position = array_search($user,$year_rank);
$final_rank = $sch_position + 1;
$yr_rank = $yr_position + 1;
$sch_rank = $final_rank;
$ends = array('th','st','nd','rd','th','th','th','th','th','th');
if (($sch_rank %100) >= 11 && ($sch_rank%100) <= 13) {
$sc_abbreviation = 'th';
$yr_abbreviation = 'th';
} else {
$sc_abbreviation = $ends[$sch_rank % 10];
$yr_abbreviation = $ends[$yr_rank % 10];
}
$models = UserMaster::model()->findByPk(Yii::app()->user->id);
$year_name = $models->studentDetails->yearGroup->name;
$data['type'] = 'success';
$data['score'] = '<div>Ranking Score: '.$rank_score.'</div>';
$data['yr_rank'] = '<div><i class="fa fa-trophy rank-i"></i><span class="rank-number">' .$yr_rank. '</span><sup class="script-top" id="year_rank_abb">' .$yr_abbreviation. '</sup></div><div id="year_name">In ' .$year_name. '</div>';
$data['school_rank'] = '<div><i class="fa fa-trophy rank-i"></i><span class="rank-number">' .$sch_rank. '</span><sup class="script-top" id="year_rank_abb">' .$sc_abbreviation. '</sup></div><div id="year_name">In School</div>';
$data['rank_revise'] ='<div>'.$rank_score.'</div>';
$data['yr_rank_revise'] = '<span>'.$yr_rank.'</span><sup class="superscript" style="left:0">'.$yr_abbreviation.'</sup>';
$data['sch_rank_revise'] = '<span>'.$sch_rank.'</span><sup class="superscript" style="left:0">'.$sc_abbreviation.'</sup>';
$_SESSION['rank'] = $rank_score;
$_SESSION['accuracy'] = $rank_score;
echo json_encode($data);
exit;
The above is used in an Yii application. It runs perfectly fine on localhost, but on live site, takes over 10 seconds to execute.
Your help and guidance is appreciated.
Thank
<?php
include ("../pos/db_config/db_config.php");
include ("../pos/functions/select.php");
$i = 0;
$sql = topsalep($idCompany);
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
$end_sale_date = $row["end_sale_date"];
$name = $row["name"];
$tot_s = $row["tot_price"];
$qc = $row["sales_item_qty"];
$proResult[$i][0] = $name;
$proResult[$i][1] = $end_sale_date;
$proResult[$i][2] = $tot_s;
$proResult[$i][3] = $qc;
$i++;
}
//$name = $proResult[0][0];
//echo "$name";
for ($i = 0; $i < $result->num_rows; $i++) {
$count = 0;
$name = $proResult[$i][0];
$date = $proResult[$i][1];
$price = $proResult[$i][2];
$qct = $proResult[$i][3];
$totalPrice = 0;
for ($j = 0; $j < $result->num_rows; $j++) {
if ($proResult[$j][1] == $date && $proResult[$j][0] == $name) {
$x = $proResult[$j][2];
$count++;
$totalPrice+=$x;
}
}
$name = $proResult[$i][0];
$date = $proResult[$i][1];
$price = $proResult[$i][2];
for ($k = 0; $k < $count; $k++){
if($proResult[$k][1] == $date && $proResult[$k][0] == $name)
{
}
}
echo "Name : $name <br>";
echo "End Date : $date : Count $count : total = $totalPrice <br><br>";
?>
In this code I showed Last 5 days product vise total value. A one day can happen same sale id there different quantity of products. Then finally I calculated the one product wise total sale value. But problem is duplicate it.
In my join query I used distinct But I want show my PHP code when duplicated values only show one value.
enter image description here
enter image description here
how to fetch value from post method and explode in foreach loop.
public function generate_all_payslip() {
$data['title'] = "Generate All Payslip";
$this->payroll_model->_table_name = "tbl_department"; //table name
$this->payroll_model->_order_by = "department_id";
$all_dept_info = $this->payroll_model->get();
// get all department info and designation info
$dataalldep = array();
foreach ($all_dept_info as $v_dept_info) {
$dataalldep['all_department_info'][] = $this->payroll_model->get_add_department_by_id($v_dept_info->department_id);
}
foreach ($dataalldep['all_department_info'] as $keyemp=>$valemparray) {
$datae = array();
foreach($valemparray as $k=>$v) {
$datae['flag'] = 1;
$datae['designations_id'] = $v->designations_id;
$this->input->post('gapsbtn', TRUE);
$dataee['payment_date'] = $this->input->post('payment_date', TRUE);
$datepaymentmades = explode("-",$dataee['payment_date']);
$currentyears = $datepaymentmades[0];
$currentmonths = $datepaymentmades[1];
$currentyear = $currentyears ;
$currentmonth = $currentmonths ;
$datae['payment_date'] = $currentyear."-".$currentmonth;
$datae['employee_info'] = $this->payroll_model->get_emp_salary_list($emp = NULL, $datae['designations_id']);
$basicwagessalaey = $datae['employee_info'][0]->basic_salary;
$gross = $datae['employee_info'][0]->house_rent_allowance + $datae['employee_info'][0]->medical_allowance + $datae['employee_info'][0]->special_allowance + $datae['employee_info'][0]->fuel_allowance + $datae['employee_info'][0]->phone_bill_allowance + $datae['employee_info'][0]->other_allowance;
$deduction = $datae['employee_info'][0]->tax_deduction + $datae['employee_info'][0]->provident_fund + $datae['employee_info'][0]->other_deduction;
$net_extra = $gross - $deduction;
$workingdayscurrentmonth = $this->countDays($currentyear,$currentmonth, array(0));
$perdaysaaryperuser = $basicwagessalaey/30;
### full day ###
$queryfullday = $this->db->query("SELECT count(attendance_id) AS present_days FROM `tbl_attendance` WHERE attendance_status='1' AND month(date) = $currentmonth and year(date) = $currentyear AND employee_id='".$data['employee_info'][0]->employee_id."'");
$attendancecountarray = $queryfullday->result_array();
$attendancecounting = $attendancecountarray[0]['present_days'];
//$attendancecounting = 24;
$data['attendancecounting'] = $attendancecountarray[0]['present_days'];
if ($attendancecounting == $workingdayscurrentmonth) {
$data['totalmonthwagesfullday'] = ($perdaysaaryperuser*30)+$perdaysaaryperuser;
} else {
if ($workingdayscurrentmonth == 27) {
$data['totalmonthwagesfullday'] = ($perdaysaaryperuser*$attendancecounting)+($perdaysaaryperuser*3);
}
if ($workingdayscurrentmonth == 26) {
$data['totalmonthwagesfullday'] = ($perdaysaaryperuser*$attendancecounting)+($perdaysaaryperuser*4);
}
if ($workingdayscurrentmonth == 25) {
$data['totalmonthwagesfullday'] = ($perdaysaaryperuser*$attendancecounting)+($perdaysaaryperuser*5);
}
if ($workingdayscurrentmonth == 24) {
$data['totalmonthwagesfullday'] = ($perdaysaaryperuser*$attendancecounting)+($perdaysaaryperuser*6);
}
}
### half day ###
$queryhalfday = $this->db->query("SELECT count(attendance_id) AS present_days FROM `tbl_attendance` WHERE attendance_status='2' AND month(date) = $currentmonth and year(date) = $currentyear AND employee_id='".$data['employee_info'][0]->employee_id."'");
$attendancecountarray_half = $queryhalfday->result_array();
$attendancecounting_half = $attendancecountarray_half[0]['present_days'];
//$attendancecounting_half = 1;
$data['attendancecounting_half'] = $attendancecountarray_half[0]['present_days'];
$data['totalmonthwages_half'] = ($perdaysaaryperuser/2)*$attendancecounting_half;
### leave day ###
$queryleave = $this->db->query("SELECT count(attendance_id) AS present_days FROM `tbl_attendance` WHERE attendance_status='3' AND month(date) = $currentmonth and year(date) = $currentyear AND employee_id='".$data['employee_info'][0]->employee_id."'");
$attendancecountarray_leave = $queryleave->result_array();
$attendancecounting_leave = $attendancecountarray_leave[0]['present_days'];
//$attendancecounting_leave = 2;
$data['attendancecounting_leave'] = $attendancecountarray_leave[0]['present_days'];
$data['totalmonthwages_leave'] = $perdaysaaryperuser*$attendancecounting_leave;
### absent day ###
$queryabsent = $this->db->query("SELECT count(attendance_id) AS present_days FROM `tbl_attendance` WHERE attendance_status='0' AND month(date) = $currentmonth and year(date) = $currentyear AND employee_id='".$data['employee_info'][0]->employee_id."'");
$attendancecountarray_absent = $queryabsent->result_array();
$attendancecounting_absent = $attendancecountarray_absent[0]['present_days'];
//$attendancecounting_absent = 1;
$data['attendancecounting_absent'] = $attendancecountarray_absent[0]['present_days'];
$data['totalmonthwages_absent'] = $perdaysaaryperuser*$attendancecounting_absent;
######################
$querylastsalary = $this->db->query("SELECT * FROM `tbl_salary_payment` WHERE employee_id='".$data['employee_info'][0]->employee_id."' Order BY salary_payment_id desc LIMIT 1");
$lastsalary = $querylastsalary->result_array();
$paymentamountlastmonth = $lastsalary[0]['payment_amount'];
$data['totalmonthwage'] = ($data['totalmonthwagesfullday']+$data['totalmonthwages_half']+$net_extra)-($data['totalmonthwages_absent']);
if ($paymentamountlastmonth < 0) {
$data['totalmonthwages'] = $data['totalmonthwage']+$paymentamountlastmonth;
} else {
$data['totalmonthwages'] = $data['totalmonthwage'];
}
########## insert into tbl_salary_payment ##########
if ($datae['employee_info'][0]->employee_id !="") {
$dbinsert = array();
$dbinsert['employee_id'] = $datae['employee_info'][0]->employee_id;
$dbinsert['basic_salary'] = $datae['employee_info'][0]->basic_salary;
$dbinsert['house_rent_allowance'] = $datae['employee_info'][0]->house_rent_allowance;
$dbinsert['medical_allowance'] = $datae['employee_info'][0]->medical_allowance;
$dbinsert['special_allowance'] = $datae['employee_info'][0]->special_allowance;
$dbinsert['fuel_allowance'] = $datae['employee_info'][0]->fuel_allowance;
$dbinsert['phone_bill_allowance'] = $datae['employee_info'][0]->phone_bill_allowance;
$dbinsert['other_allowance'] = $datae['employee_info'][0]->other_allowance;
$dbinsert['tax_deduction'] = $datae['employee_info'][0]->tax_deduction;
$dbinsert['provident_fund'] = $datae['employee_info'][0]->provident_fund;
$dbinsert['other_deduction'] = $datae['employee_info'][0]->other_deduction;
$dbinsert['payment_for_month'] = $datae['payment_date'];
$dbinsert['payment_type'] = 'Cash Payment';
$dbinsert['payment_date'] = date('Y-m-d H:i:s');
$dbinsert['payment_amount'] = round($totalmonthwages);
$dbinsert['present'] = $attendancecounting;
$dbinsert['halfday'] = $attendancecounting_half;
$dbinsert['leave'] = $attendancecounting_leave;
$dbinsert['absent'] = $attendancecounting_absent;
$insertedid = $this->payroll_model->insertpayrolldata($dbinsert);
####### insert into tbl_salary_payslip ###
$dbinsertpayslip = array();
$dbinsertpayslip['payslip_number'] = date('Ymd');
$dbinsertpayslip['salary_payment_id'] = $insertedid;
$this->payroll_model->insertpayslipdata($dbinsertpayslip);
}
}
}
$data['subview'] = $this->load->view('admin/payroll/generate_all_payslip', $data, TRUE);
$this->load->view('admin/_layout_main', $data);
}
error with this code only
$this->input->post('gapsbtn', TRUE);
$dataee['payment_date'] = $this->input->post('payment_date', TRUE);
$datepaymentmades = explode("-",$dataee['payment_date']);
$currentyears = $datepaymentmades[0];
$currentmonths = $datepaymentmades[1];
$currentyear = $currentyears ;
$currentmonth = $currentmonths ;
if I use
$currentyear = date('Y');
$currentmonth = date('m');
its work fine.but i want use date that i have selected not current system date
how do i correct this code. currently i see this error
This page isn’t workingexample.com is currently unable to handle this request.HTTP ERROR 500
Is there any specific resason to use below mentioned line?
$datepaymentmades = explode("-",$dataee['payment_date']);
Or you let us know what you want to do with this.
If you want month, date and year than please check below.
$paymentDate = strtotime($dataee['payment_date']);
$month = date("m",strtotime($paymentDate));
$year = date("Y",strtotime($paymentDate));
$day = date("d",strtotime($paymentDate));
I am wondering how to the change date from this
Db -> holiday -> holidayDate (type date) = 2015-01-01, 2015-01-03, 2015-02-19, 2015-03-21, 2015-04-03, 2015-05-01, 2015-05-14, 2015-05-16, 2015-06-02, 2015-07-17, 2015-07-18, 2015-08-17, 2015-09-24, 2015-10-14, 2015-12-25
Here is the code
$sql = "select * from holiday order by holidayDate ";
//echo $sql;
$ambil_data = mysql_query($sql);
if ($data = mysql_fetch_array($ambil_data))
{
$tglLibur2 = $data['holidayDate'];
}
else
{
echo mysql_error();
}
function selisihHari($tglAwal, $tglAkhir)
{
$tglLibur = array("'".$tglLibur2."'"); <= i just want to get this array from db
$pecah1 = explode("-", $tglAwal);
$date1 = $pecah1[2];
$month1 = $pecah1[1];
$year1 = $pecah1[0];
$pecah2 = explode("-", $tglAkhir);
$date2 = $pecah2[2];
$month2 = $pecah2[1];
$year2 = $pecah2[0];
$jd1 = GregorianToJD($month1, $date1, $year1);
$jd2 = GregorianToJD($month2, $date2, $year2);
$selisih = ($jd2 - $jd1);
$libur1 = 0;
$libur2 = 0;
$libur3 = 0;
for($i=1; $i<=$selisih; $i++)
{
$tanggal = mktime(0, 0, 0, $month1, $date1+$i, $year1);
$tglstr = date("Y-m-d", $tanggal);
if (in_array($tglstr, $tglLibur))
{
$libur1++;
}
if ((date("N", $tanggal) == 7))
{
$libur2++;
}
if ((date("N", $tanggal) == 6))
{
$libur3++;
}
}
return $selisih-$libur1-$libur2-$libur3;
}
into this
$tglLibur = array("2015-01-01","2015-01-03","2015-02-19",
"2015-03-21","2015-04-03","2015-05-01","2015-05-14","2015-05-16",
"2015-06-02","2015-07-17","2015-07-18","2015-08-17","2015-09-24",
"2015-10-14","2015-12-25");
First of all your function selisihHari doesn't have access to the variable tglLibur2 you're using inside it. So I'm thinking you didn't post your full code here. But what you're looking for can be done with the following code:
$tglLibur = array()
foreach($tglLibur2 as $date){
$tglLibur[] = $date;
}
But what you're doing in your fetch code doesn't make sense. You keep overwriting the same variable. To change that do the following:
$tglLibur2 = array();
if ($data = mysql_fetch_array($ambil_data))
{
$tglLibur2[] = $data['holidayDate'];
}
This should give you the array you're looking for. That way you can get rid of your function all together.
Assuming that you aren't looping through each row and that $data['holidayDate'] is a string of dates, comma delimited, just change:
$tglLibur2 = $data['holidayDate'];
to
$tglLibur[] = explode(', ', $data['holidayDate']);