public IQueryable <production_order_need_supplier_master_model> FindAll() { var result = _context.production_order_items .Where(t => _context.Fn_check_finish_approval_to_next_step(_context.production_orders.Where(d => d.id == t.id_production_order).Select(t => t.id_approval).SingleOrDefault())) .Select(d => new production_order_need_supplier_master_model() { sys_item_specification_name = _context.sys_item_specifications.Where(t => t.id == d.id_specification).Select(d => d.name).SingleOrDefault(), sys_unit_name = _context.sys_units.Where(t => t.id == d.id_unit).Select(d => d.name).SingleOrDefault(), sys_unit_main_name = _context.sys_units.Where(t => t.id == d.id_unit_main).Select(d => d.name).SingleOrDefault(), sys_item_name = _context.sys_items.Where(t => t.id == d.id_item).Select(d => d.name).SingleOrDefault(), customer_name = _context.sys_customers.Where(t => t.id == _context.production_orders.Where(t => t.id == d.id_production_order).Select(d => d.id_customer).SingleOrDefault()) .Select(t => t.name).SingleOrDefault(), production_order_name = _context.production_orders.Where(t => t.id == d.id_production_order).Select(d => d.name).SingleOrDefault(), id_customer = _context.production_orders.Where(t => t.id == d.id_production_order).Select(d => d.id_customer).SingleOrDefault(), id_business_sale_order = _context.production_orders.Where(t => t.id == d.id_production_order).Select(d => d.id_business_sale_order).SingleOrDefault(), business_sale_order_name = _context.business_sale_orders .Where(t => t.id == _context.production_orders.Where(t => t.id == d.id_production_order).Select(d => d.id_business_sale_order) .SingleOrDefault()).Select(d => d.name).SingleOrDefault(), db = d, }); return(result); }
public IQueryable <production_order_set_up_scheduleModel> FindAllItemIndex() { var result = _context.production_order_items .Where(d => d.status_bom == 2) .Where(t => _context.Fn_check_finish_approval_to_next_step(_context.production_orders.Where(d => d.id == t.id_production_order).Select(t => t.id_approval).SingleOrDefault())) .Select(d => new production_order_set_up_scheduleModel() { sys_item_specification_name = _context.sys_item_specifications.Where(t => t.id == d.id_specification).Select(d => d.name).SingleOrDefault(), sys_unit_name = _context.sys_units.Where(t => t.id == d.id_unit).Select(d => d.name).SingleOrDefault(), sys_unit_main_name = _context.sys_units.Where(t => t.id == d.id_unit_main).Select(d => d.name).SingleOrDefault(), sys_item_name = _context.sys_items.Where(t => t.id == d.id_item).Select(d => d.name).SingleOrDefault(), production_order_name = _context.production_orders.Where(t => t.id == d.id_production_order).Select(d => d.name).SingleOrDefault(), id_approval = _context.production_orders.Where(s => s.id.Equals(d.id_production_order)).Select(s => s.id_approval).SingleOrDefault(), id_customer = _context.production_orders.Where(s => s.id.Equals(d.id_production_order)).Select(s => s.id_customer).SingleOrDefault(), sys_customer_name = _context.sys_customers.Where(a => a.id.Equals(_context.production_orders.Where(s => s.id.Equals(d.id_production_order)).Select(s => s.id_customer).SingleOrDefault())).Select(a => a.name).SingleOrDefault(), db = d, }); return(result); }
public void calculate(string id_workstation) { if (id_workstation != "") { var workstation_model = _context.sys_workstations.Where(w => w.id == id_workstation).SingleOrDefault(); var item_workstation = _context.sys_factory_line_item_capacitys .Where(s => s.id_sys_factory == workstation_model.id_sys_factory) .Where(s => s.id_sys_factory_line == workstation_model.id_sys_factory_line) .Select(w => w.id_item).ToList(); var list_approvals = _context.sys_approvals.Select(a => a.id_record).ToList(); var list_item = _context.production_order_item_schedules .Where(t => _context.Fn_check_finish_approval_to_next_step(_context.production_orders.Where(d => d.id == t.id_production_order).Select(t => t.id_approval).SingleOrDefault())) .Where(d => item_workstation.Contains(d.id_item)) .Where(d => list_approvals.Contains(d.id_production_order)) .OrderBy(d => d.index_pos) .Select(d => new production_order_set_up_item_model() { sys_phase_name = _context.sys_phases.Where(t => t.id == d.id_phase).Select(d => d.name).SingleOrDefault(), sys_item_specification_name = _context.sys_item_specifications.Where(t => t.id == d.id_specification).Select(d => d.name).SingleOrDefault(), sys_unit_name = _context.sys_units.Where(t => t.id == d.id_unit).Select(d => d.name).SingleOrDefault(), sys_unit_main_name = _context.sys_units.Where(t => t.id == d.id_unit_main).Select(d => d.name).SingleOrDefault(), sys_item_name = _context.sys_items.Where(t => t.id == d.id_item).Select(d => d.name).SingleOrDefault(), factory_name = _context.sys_factorys.Where(t => t.id == d.id_sys_factory).Select(d => d.name).SingleOrDefault(), factory_line_name = _context.sys_factory_lines.Where(t => t.status_del == 1).Where(t => t.id == d.id_sys_factory_line).Select(d => d.name).SingleOrDefault(), db = d, }).ToList();; for (int i = 0; i < list_item?.Count; i++) { var production_process_db = new production_process_db() { id_production_order_item_schedule = list_item[i].db.id, status_process = 1, create_by = list_item[i].db.create_by, id_production_order = list_item[i].db.id_production_order, conversion_factor = list_item[i].db.conversion_factor, id_item = list_item[i].db.id_item, working_date = (DateTime)list_item[i].db.working_date, id_specification = list_item[i].db.id_specification, id_unit = list_item[i].db.id_unit, id_unit_main = list_item[i].db.id_unit_main, note = list_item[i].db.note, quantity = list_item[i].db.quantity, quantity_unit_main = list_item[i].db.quantity_unit_main, id_factory = list_item[i].db.id_sys_factory, id_factory_line = list_item[i].db.id_sys_factory_line, id_business_sale_order = _context.business_sale_order_items.Where(b => b.id_item == list_item[i].db.id_item).Select(b => b.id_business_sale_order).FirstOrDefault(), create_date = _context.production_orders.Where(b => b.id == list_item[i].db.id_production_order).Select(b => b.create_date).FirstOrDefault(), id_production_order_item = list_item[i].db.id_production_order_item, }; var duplicateRecord = _context.production_processes .Where(p => p.id_production_order == production_process_db.id_production_order) .Where(p => p.id_item == production_process_db.id_item) .Where(p => p.quantity == production_process_db.quantity) .Where(p => p.working_date == production_process_db.working_date) .Where(p => p.id_factory == production_process_db.id_factory) .Where(p => p.id_factory_line == production_process_db.id_factory_line); if (duplicateRecord.Count() == 0) { _context.production_processes.Add(production_process_db); } } ; _context.SaveChanges(); } }