function queryCurrentBacklog($cap_double = null) { $querySO = querySourcingOpenOrders(); $total = $querySO['sourcing'] + $querySO['open']; if (is_null($cap_double)) { $kpi_prod_config = load_config('kpi-settings'); $cap_double = $kpi_prod_config['kpi-production-daily-capacity']; } $cap_single = $cap_double / 2; $backlog = ($total - $cap_double) / $cap_single; return $backlog < 1 ? 0 : round($backlog); }
$query .= " SELECT op.print_count, SUM(op.products_quantity) total FROM"; $query .= " orders_products op"; $query .= " WHERE op.status IN ('2', '3', '4')"; $query .= " GROUP BY op.print_count"; $query .= " UNION ALL"; $query .= " SELECT do.print_count, SUM(do.quantity) AS total FROM"; $query .= " depot_orders do"; $query .= " WHERE do.status IN ('2', '3', '4')"; $query .= " GROUP BY do.print_count"; $dbq = tep_db_query($query); $sourcing = 0; $open = 0; while($res = tep_db_fetch_array($dbq)) { $sourcing += ($res['print_count']==0) ? $res['total'] : 0; $open += ($res['print_count']>0) ? $res['total'] : 0; } */ $querySO = querySourcingOpenOrders(); $open = $querySO['open']; $sourcing = $querySO['sourcing']; $ready = $querySO['open-ready']; $pullrack = $querySO['open-pullrack']; $workshop = $querySO['open-workshop']; $ampol = $querySO['open-ampol']; $lab = $querySO['open-lab']; $data = array('sourcing' => $sourcing, 'open' => $open, 'ready' => $ready, 'pullrack' => $pullrack, 'workshop' => $workshop, 'ampol' => $ampol, 'lab' => $lab); tep_db_perform('production_target', $data, 'update', "date_id='{$date_id}'"); $logger->write("SUCCESS update prod. log with date_id = {$date_id} [sourcing={$sourcing}, open={$open}, ready={$ready}, workshop={$workshop}, lab={$lab}]"); } else { $logger->write("update NOT NEEDED, no log created yet for date_id = {$date_id}"); } $logger->close();