我已经为此挣扎了好几天,但都没有成功:(我有一份生产订单清单,上面有需要一定时间才能完成的订单。
然后我有一个单独的表格,上面有每周的可用时间,例如w52/2018-340h。
我需要循环通过订单行和每周可用小时数,并计算每个订单行的就绪日期。
在代码中,带大写字母的注解是我正在努力解决的问题。可能还有其他事情也完全错了。
$year = date("Y");
$week = date("W");
//outer loop query - loops through production order rows (every row has
production time hours needed for the row)
$db->setQuery("
SELECT a.*
FROM work_orders AS a
ORDER
BY a.id ASC
");
$results_work_order = $db->loadObjectList();
//inner loop query (loops through weeks database table where weekly
available production hours are retrieved)
$db->setQuery("SELECT a.work_hours_per_week FROM work_schedule AS a
WHERE a.year >= " .$year ." AND a.week >= " . $week ." ORDER BY a.year,
a.week ASC");
$results_work_hours = $db->loadObjectList();
foreach ($results_work_order as $result_work_order) {
foreach ($results_work_hours as $result_work_hours) {
//gets the amount of hours needed to complete the order
$work_order_hours_left = $result_work_order->work_order_hours_left;
//gets weekly available hours starting from current week
$weekly_hours = $result_work_hours->work_hours_per_week;
//if weekly available hour are greater than hours needed for current order row...
if($weekly_hours > $work_order_hours_left) {
//gets ready weekday: divides current row hours with weekly hours and rounds (e.g. 150 / 330 = 0.45), 0.45 * 7 = 3.15, rounded up = 4 = Thursday
$ready_weekday = roundup(($work_order_hours_left / $weekly_hours) * 7), 0)
//HOW TO GET DATE FOR THE WEEK/YEAR's THURSDAY (CALCULATED READY DATE)
$calculated_ready_date=???
//updates the production order row's calculated ready date
$db->setQuery("UPDATE work_orders SET calc_ready_date = " . $db->Quote($calculated_ready_date) . "
WHERE id = " . $db->Quote($result_outer->id));
$db->query();
//SHOULD CONTINUE TO NEXT OUTER LOOP AND KEEP THE HOURS LEFT FROM THIS WEEK TO NEXT PRODUCTION ORDER ROW
//NEXT INNER LOOP SHOULD CONTINUE WHERE IT LAST LEFT OFF
} else {
//weekly available hours are smaller than hours needed for current production order row
//SHOULD GET THE WEEKLY HOURS FROM PREVIOUS WEEK AND ADD HOURS FROM CURRENT WEEK, THEN CHECK IF THESE ARE ENOUGH TO FINISH CURRENT PRODCUTION ORDER
//GETS THE READY DATE SIMILAR WAY AS IF THE CODE BEFORE "ELSE" ??? HOW???
}
}
}
我将非常感谢任何帮助引导我走上正确的道路。
谢谢!劳拉
1条答案
按热度按时间b0zn9rqh1#
从周数和年数中获取日期
在这种情况下,你得到的是那周的第一天。你可以把数字1改成7,这样就可以得到一周的最后一天。
您可以使用break结束内部循环或继续进行下一项。