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 edit($part_id) { $app = get_app(); $part = Part::find_by_id($part_id); //GET if ($app->request()->isGet()) { $app->render('Parts/edit.php', compact('part')); } //POST if ($app->request()->isPost()) { $post = $app->request()->post(); // 施工员/调度员 if (has_perm(1, 4) || has_perm(2, 4)) { $part->num = $post['num']; $part->name = $post['name']; $part->graphic_num = $post['graphic_num']; $part->roughcast = $post['roughcast']; $part->count = $post['count']; //$rtn = Part::modify_count( $post['count'] , $part ); //if( $rtn ) $app->flashNow('warning','该零件下属工序已包含现场工时,生产件数无法更新!'); } // 施工员 if (has_perm(1, 4)) { $part->stuff = $post['stuff']; } // 调度员 if (has_perm(2, 4)) { $part->planned_completion_date = $post['planned_completion_date']; $part->production_date = $post['production_date']; $part->return_date = $post['return_date']; $part->roughcast_count = $post['roughcast_count']; } // 文员/调度员 if (has_perm(3, 4) || has_perm(2, 4)) { if (!empty($post['mr_time'])) { $post['mr_date'] = $post['mr_date'] . ' ' . $post['mr_time']; } $part->mr_date = $post['mr_date']; } // 文员 if (has_perm(3, 4)) { $part->feeding_price = $post['feeding_price']; } // 施工员/调度员/文员 if (has_perm(1, 4) || has_perm(2, 4) || has_perm(3, 4)) { $part->remark = $post['remark']; } // 工时定额员@人力资源部 if (has_perm(7, 2) && $post['price']) { $part->price = (double) $post['price']; } // if (!$part->is_valid()) { $app->flashNow('errors', $part->errors); $results['is_success'] = false; } else { $part->save(); $app->flashNow('success', '修改零部件信息添加成功!'); $results['is_success'] = true; $results['newNode'] = array('id' => $part->id, 'name' => $part->num . ' ' . $part->name . ' (' . count($part->processes) . ')', 'isParent' => count($part->processes) > 0 ? true : false, 'type' => 'part', 'icon' => $part->return_date ? get_path('/webroot/css/img/diy/3_return.jpg', true) : get_path('/webroot/css/img/diy/3.png', true), 'moveFirst' => false); Part::update_count($part); } $app->view->setData(array('part' => $part)); $results['html'] = $app->view->fetch('Parts/edit.php'); echo json_encode($results); } }
function reset_done($proc_id) { if (!has_perm(2, 4)) { exit; } $proc = Process::find_by_id($proc_id); if ($proc) { $proc->count_done = 0; $proc->is_done = false; $proc->completion_date = ''; $proc->save(); // 更新上一级节点 Part::update_count($proc->part); Production::update_count($proc->part->production); // echo 'success'; } }