function edit($work_id) { $app = get_app(); $work = Work::find_by_id($work_id); $staffs = Staff::find('all'); // 记录更新之前的生产数量和完工数量 // 只有当这连个值发生了变化才去调用 // update_count函数更新完工状态 $work_count = $work->count; $work_count_done = $work->count_done; // 分配件数改为可编辑状态 // 取得现场工时分配件数的上限 $request_count = $app->request()->post('count'); if (check_float($request_count)) { $request_count = round($request_count, get_float_num($request_count)); } $available_count = Process::get_available_count($work->process->id, get_float_num($request_count)); // POST if ($app->request()->isPost()) { $post = $app->request()->post(); // 修改work之前验证 if ($post['count'] == 0) { $results['errors'] = array('分配件数必须大于0, 请重新调整参数!'); $results['is_success'] = false; } else { if ($post['count_done'] > $post['count']) { $results['errors'] = array('完工件数大于生产件数, 请重新调整参数!'); $results['is_success'] = false; } else { if ($request_count > $available_count + $work_count) { $results['errors'] = array('您分配的生产数量超过了工序定义的最大值!'); $results['is_success'] = false; } else { if ($work->count_check == 0) { $results['errors'] = array('对不起,未交验的现场工时不能编辑!'); $results['is_success'] = false; } else { if (has_perm(2, 4)) { $work->count = $post['count']; $work->count_done = $post['count_done']; $work->count_valid = $post['count_valid']; $work->count_invalid = $post['count_invalid']; $work->count_concession = $post['count_concession']; $work->staff_id = $post['staff_id']; // 完工数量或生产数量发生变动才更新 // 对应现场工时的完工时间和完工状态 if ($post['count_done'] != $work_count_done || $post['count'] != $work_count) { if ($post['count_done'] == $work->count) { $work->is_done = 1; $work->completion_date = date('Y-m-d'); } if ($post['count_done'] < $work->count) { $work->is_done = 0; $work->completion_date = ''; } } } /*if( has_perm( 3,4 ) ){ $work->ticket = $post['ticket']; }*/ if (has_perm(2, 4) || has_perm(3, 4)) { if ($post['completion_date']) { $work->completion_date = date('Y-m-d', strtotime($post['completion_date'])); } $work->remark = $post['remark']; } $work->save(); $results['is_success'] = true; $results['newNode'] = array('id' => $work->id, 'name' => $work->staff->name, 'staff_id' => $work->staff->id, 'staff_name' => $work->staff->name, 'count' => $work->count, 'count_valid' => $work->count_valid, 'count_concession' => $work->count_concession, 'count_invalid' => $work->count_invalid, 'count_check' => $work->count_check, 'count_done' => $work->count_done, 'is_done' => $work->is_done, 'completion_date' => $work->completion_date ? date('Y-m-d', strtotime($work->completion_date)) : '', 'check_date' => $work->check_date ? date('Y-m-d', strtotime($work->check_date)) : '', 'remark' => $work->remark, 'font' => get_work_node_color($work), 'isParent' => false, 'type' => 'work', 'icon' => get_path('/webroot/css/img/diy/9.png', true)); // 完工数量或生产数量发生变动才更新 if ($post['count_done'] != $work_count_done || $post['count'] != $work_count) { Process::update_count($work->process); Part::update_count($work->process->part); Production::update_count($work->process->part->production); } // 如果当前现场工时的父级工序已经完工 // 自动更新下一道工序的投产日期 if ($work->process->is_done) { $proc = Process::find_next($work->process); // 当 next_proc 没有指定投产日期时,才自动更新投产日期 if ($proc && empty($proc->production_date)) { $proc->production_date = date('Y-m-d'); $proc->save(); } } } } } } echo json_encode($results); } }
function set_done($proc_id) { if (!has_perm(2, 4)) { exit; } $proc = Process::find_by_id($proc_id); if ($proc) { $proc->count_done = $proc->count; $proc->is_done = true; $proc->completion_date = date('Y-m-d H:i:s'); // 工序外协字段自动设置 $proc->is_outsourcing = true; $proc->save(); // 更新下一道工序的投产时间 $next_proc = Process::find_next($proc); if ($next_proc) { $next_proc->production_date = date('Y-m-d'); $next_proc->save(); } // 更新上一级节点 Part::update_count($proc->part); Production::update_count($proc->part->production); // echo 'success'; } }