PHP 嵌套根据每周可用小时数获取生产订单准备日期



我已经为此挣扎了好几天,但没有成功:(我有一个生产订单清单,其中包含需要一定小时才能完成的订单。

然后我有一个单独的表格,其中包含每周可用时间,例如 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???
       }
    }
}

我将非常感谢任何帮助引导我走上正确的轨道。

谢谢!劳 拉

从周数和年份获取日期

$calculated_ready_date = date( "l, M jS, Y", strtotime($year."W".sprintf("%02u", $week)."1") ); 

在这种情况下,您将获得该周的第一天。 您可以更改数字 1 tot 7 tot 获取一周的最后一天。

您可以使用中断结束内部循环或继续下一项。

相关内容

  • 没有找到相关文章

最新更新