Exemplo n.º 1
0
 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);
     }
 }
Exemplo n.º 2
0
 function edit($proc_id)
 {
     $app = get_app();
     $proc = Process::find_by_id($proc_id);
     $part = Part::find_by_id($proc->part_id);
     $post = $app->request()->post();
     $proc_has_same_priority = Process::find('all', array('conditions' => array(' part_id = ? AND priority = ? AND priority != ?', $part->id, $post['priority'], $proc->priority)));
     if (!empty($proc_has_same_priority)) {
         $results['errors'] = array('有相同序号的一条工序已经存在!');
         $results['is_success'] = false;
     } else {
         if (has_perm(1, 4)) {
             $proc->priority = $post['priority'];
             $proc->name = $post['name'];
             $proc->content = $post['content'];
         }
         if (has_perm(7, 2)) {
             $proc->takt_time = $post['takt_time'];
             $proc->preparation_time = $post['preparation_time'];
         }
         if (has_perm(2, 4)) {
             $proc->production_date = $post['production_date'];
             $proc->planned_completion_date = $post['planned_completion_date'];
         }
         if (has_perm(3, 4)) {
             $proc->price = $post['price'];
         }
         if (has_perm(1, 4) || has_perm(2, 4)) {
             $proc->count = $post['count'];
             // 外协
             if (isset($post['is_outsourcing'])) {
                 $proc->is_outsourcing = 1;
             } else {
                 $proc->is_outsourcing = 0;
             }
         }
         if (has_perm(1, 4) || has_perm(2, 4) || has_perm(3, 4) || has_perm(7, 2)) {
             $proc->remark = $post['remark'];
         }
         if (!$proc->is_valid()) {
             foreach ($proc->errors as $error) {
                 $errors[] = $error;
             }
             $results['errors'] = $errors;
             $results['is_success'] = false;
         } else {
             $proc->save();
             $results['newNode'] = $post;
             $results['newNode']['takt_time'] = $proc->takt_time ? $proc->takt_time : '';
             $results['newNode']['preparation_time'] = $proc->preparation_time ? $proc->preparation_time : '';
             $results['newNode']['count'] = $proc->count;
             $results['newNode']['price'] = $proc->price ? $proc->price : '';
             $results['newNode']['content'] = $proc->content ? $proc->content : '';
             //
             $results['newNode']['production_date'] = $proc->production_date ? date('Y-m-d', strtotime($proc->production_date)) : '';
             $results['newNode']['planned_completion_date'] = $proc->planned_completion_date ? date('Y-m-d', strtotime($proc->planned_completion_date)) : '';
             $results['newNode']['is_outsourcing'] = $proc->is_outsourcing;
             $results['newNode']['name_orig'] = $proc->name;
             $results['newNode']['name'] = get_proc_name($proc->name);
             $results['newNode']['name_with_count'] = $proc->priority . '# ' . get_proc_name($proc->name) . ' (' . count($proc->works) . ')';
             $results['newNode']['id'] = $proc->id;
             $results['newNode']['isParent'] = count($proc->works) ? true : false;
             $results['newNode']['type'] = 'proc';
             $results['newNode']['moveFirst'] = false;
             $results['newNode']['icon'] = get_path('/webroot/css/img/diy/4.png', true);
             $results['newNode']['font'] = array('color' => $proc->is_done ? 'green' : 'black');
             $results['newNode']['is_outsourcing'] = $proc->is_outsourcing;
             $results['is_success'] = true;
             Process::update_count($proc);
             Part::update_count($proc->part);
             Production::update_count($proc->part->production);
         }
     }
     echo json_encode($results);
 }