def serial(t_id): """ to generate a new ticket and print it """ form = forms.Touch_name(session.get('lang')) task = data.Task.query.filter_by(id=t_id).first() if task is None: flash('Error: wrong entry, something went wrong', 'danger') return redirect(url_for("core.root")) # if it is registered ticket, will display the form and valuate it if not form.validate_on_submit() and data.Touch_store.query.first().n: ts = data.Touch_store.query.filter_by(id=0).first() tnumber = False if data.Printer.query.first().value == 2: tnumber = True return render_template("touch.html", title=ts.title, tnumber=tnumber, ts=ts, done=False, bgcolor=ts.bgcolor, page_title="Touch Screen - Enter name ", alias=data.Aliases.query.first(), a=4, dire='multimedia/', form=form) nm = form.name.data n = True if data.Touch_store.query.first().n else False # FIX: limit the tickets to the range of waitting tickets, prevent overflow. # Assigning the first office in the list o_id = task.least_tickets_office().id next_number = data.Serial.query.filter_by(office_id=o_id)\ .order_by(data.Serial.number.desc())\ .first().number + 1 if data.Serial.query.filter_by(number=next_number, office_id=o_id).first() is None: if n: # registered db.session.add(data.Serial(next_number, o_id, t_id, nm, True)) db.session.commit() else: # printed db.session.add(data.Serial(next_number, o_id, t_id, None, False)) db.session.commit() # adding printer support q = data.Printer.query.first() ppt = data.Task.query.filter_by(id=t_id).first() oot = data.Office.query.filter_by(id=o_id).first() tnum = data.Serial.query.filter_by(office_id=o_id, p=False).count() cuticket = data.Serial.query.filter_by(office_id=o_id, p=False).first() tnum -= 1 langu = data.Printer.query.first().langu # to solve Linux printer permissions if os.name == 'nt': # NOTE: To list all windows printers if execute('wmic printer get sharename', parser='\n', encoding='utf-16')[1:]: if langu == 'ar': print_ticket_windows_ar( q.product, oot.prefix + '.' + str(next_number), oot.prefix + str(oot.name), tnum, ppt.name, oot.prefix + '.' + str(cuticket.number), ip=current_app.config['LOCALADDR']) else: print_ticket_windows( q.product, oot.prefix + '.' + str(next_number), oot.prefix + str(oot.name), tnum, ppt.name, oot.prefix + '.' + str(cuticket.number), l=langu, ip=current_app.config['LOCALADDR']) p = True else: p = None else: # To Fix 1: Fail safe drivers. [FIXED] try: p = assign(int(q.vendor), int(q.product), int(q.in_ep), int(q.out_ep)) except Exception: p = None if p is None: flash('Error: you must have available printer, to use printed', 'danger') flash("Notice: make sure that printer is properly connected", 'info') if os.name == 'nt': flash( "Notice: Make sure to make the printer shared on the local network", 'info') elif platform == "linux" or platform == "linux2": flash( "Notice: Make sure to execute the command `sudo gpasswd -a $(users) lp` and reboot the system", 'info') return redirect(url_for('cust_app.ticket')) if os.name != 'nt': if langu == 'ar': printit_ar( p, oot.prefix + '.' + str(next_number), oot.prefix + str(oot.name), tnum, u'' + ppt.name, oot.prefix + '.' + str(cuticket.number)) else: printit( p, oot.prefix + '.' + str(next_number), oot.prefix + str(oot.name), tnum, u'' + ppt.name, oot.prefix + '.' + str(cuticket.number), lang=langu) else: flash('Error: wrong entry, something went wrong', 'danger') return redirect(url_for('core.root')) # FIX: limit the tickets to the range of waitting tickets, prevent overflow. limited_tickets = data.Serial.query.filter_by(p=False)\ .order_by(data.Serial.timestamp)\ .limit(11) for a in range(data.Waiting.query.count(), 11): for b in limited_tickets.all(): if data.Waiting.query.filter_by(office_id=b.office_id, number=b.number, task_id=b.task_id ).first() is None: db.session.add(data.Waiting(b.number, b.office_id, b.task_id, nm, n)) db.session.commit() return redirect(url_for("core.touch", a=1))
def create_new_ticket(cls, task, office=None, name_or_number=None): '''Create a new registered or printed ticket. Parameters ---------- task: Task instance task to link the ticket to. office: Office instance office to link the ticket to, default is None. name_or_number: str ticket's name or number value. Returns ------- Serial, exception a new ticket printed or registered ticket. ''' from app.printer import assign, printit, printit_ar, print_ticket_cli, print_ticket_cli_ar windows = os.name == 'nt' touch_screen_stings = Touch_store.get() ticket_settings = Printer.get() settings = Settings.get() printed = not touch_screen_stings.n next_number = cls.query.order_by(cls.number.desc()).first().number + 1 office = office or task.least_tickets_office() ticket, exception = None, None if printed: tickets = Serial.all_office_tickets(office.id, desc=False) current_ticket = getattr(tickets.first(), 'number', None) common_arguments = (f'{office.prefix}.{next_number}', f'{office.prefix}{office.name}', tickets.count(), task.name, f'{office.prefix}.{current_ticket}') try: if windows or settings.lp_printing: (print_ticket_cli_ar if ticket_settings.langu == 'ar' else print_ticket_cli)(ticket_settings.name, *common_arguments, language=ticket_settings.langu, windows=windows, unix=not windows) else: printer = assign(ticket_settings.vendor, ticket_settings.product, ticket_settings.in_ep, ticket_settings.out_ep) (printit_ar if ticket_settings.langu == 'ar' else printit)( printer, *common_arguments, lang=ticket_settings.langu, scale=ticket_settings.scale) except Exception as e: exception = e if not exception: ticket = Serial(number=next_number, office_id=office.id, task_id=task.id, name=name_or_number, n=not printed) db.session.add(ticket) db.session.commit() return ticket, exception
def serial(t_id, office_id=None): ''' generate a new ticket and print it. ''' windows = os.name == 'nt' form = forms.Touch_name(session.get('lang')) task = data.Task.get(t_id) office = data.Office.get(office_id) touch_screen_stings = data.Touch_store.get() ticket_settings = data.Printer.get() settings = data.Settings.get() printed = not touch_screen_stings.n numeric_ticket_form = ticket_settings.value == 2 name_or_number = form.name.data or None if not task: flash('Error: wrong entry, something went wrong', 'danger') return redirect(url_for('core.root')) # NOTE: if it is registered ticket, will display the form if not form.validate_on_submit() and not printed: return render_template('touch.html', title=touch_screen_stings.title, tnumber=numeric_ticket_form, ts=touch_screen_stings, bgcolor=touch_screen_stings.bgcolor, a=4, done=False, page_title='Touch Screen - Enter name ', form=form, dire='multimedia/', alias=data.Aliases.query.first(), office_id=office_id) # NOTE: Incrementing the ticket number from the last generated ticket globally next_number = data.Serial.query.order_by(data.Serial.number.desc())\ .first().number + 1 office = office or task.least_tickets_office() if printed: current_ticket = getattr( data.Serial.all_office_tickets(office.id).first(), 'number', None) common_arguments = (f'{office.prefix}.{next_number}', f'{office.prefix}{office.name}', data.Serial.all_office_tickets(office.id).count(), task.name, f'{office.prefix}.{current_ticket}') try: if windows or settings.lp_printing: (print_ticket_cli_ar if ticket_settings.langu == 'ar' else print_ticket_cli)(ticket_settings.name, *common_arguments, language=ticket_settings.langu, windows=windows, unix=not windows) else: printer = assign(ticket_settings.vendor, ticket_settings.product, ticket_settings.in_ep, ticket_settings.out_ep) (printit_ar if ticket_settings.langu == 'ar' else printit)( printer, *common_arguments, lang=ticket_settings.langu, scale=ticket_settings.scale) except Exception as exception: flash('Error: you must have available printer, to use printed', 'danger') flash('Notice: make sure that printer is properly connected', 'info') if windows: flash( 'Notice: Make sure to make the printer shared on the local network', 'info') elif 'linux' in platform: flash( 'Notice: Make sure to execute the command `sudo gpasswd -a $(users) lp` and ' 'reboot the system', 'info') log_error(exception) return redirect(url_for('core.root')) db.session.add( data.Serial(number=next_number, office_id=office.id, task_id=task.id, name=name_or_number, n=not printed)) db.session.commit() return redirect(url_for('core.touch', a=1, office_id=office_id))
def serial(t_id): """ to generate a new ticket and print it """ ex_functions.mse() form = forms.Touch_name(session.get('lang')) tsk = data.Task.query.filter_by(id=t_id).first() if tsk is None: flash('Error: wrong entry, something went wrong', "danger") return redirect(url_for("core.root")) # if it is registered ticket, will display the form and valuate it if not form.validate_on_submit() and data.Touch_store.query.first().n: ts = data.Touch_store.query.filter_by(id=0).first() tnumber = False if data.Printer.query.first().value == 2: tnumber = True return render_template("touch.html", title=ts.title, tnumber=tnumber, ts=ts, done=False, bgcolor=ts.bgcolor, ptitle="Touch Screen - Enter name ", alias=data.Aliases.query.first(), a=4, dire='multimedia/', form=form) nm = form.name.data n = True if data.Touch_store.query.first().n else False # Assigning the first office in the list o_id = data.Task.query.filter_by(id=t_id).first().offices[0].id ln = data.Serial.query.filter_by( office_id=o_id).order_by(data.Serial .timestamp.desc( )).first().number sr = data.Serial.query.filter_by(number=ln + 1, office_id=o_id, task_id=t_id).first() if sr is None: if n: # registered db.session.add(data.Serial(ln + 1, o_id, t_id, nm, True)) else: # printed db.session.add(data.Serial(ln + 1, o_id, t_id, None, False)) # adding printer support q = data.Printer.query.first() ppt = data.Task.query.filter_by(id=t_id).first() oot = data.Office.query.filter_by(id=o_id).first() tnum = data.Serial.query.filter_by(office_id=o_id, p=False).count() cuticket = data.Serial.query.filter_by( office_id=o_id, p=False).first() tnum -= 1 langu = data.Printer.query.first().langu # to solve Linux printer permissions if os.name == 'nt': # to solve windows shared printers import win_printer from pythoncom import CoInitialize as coli coli() chk = win_printer.check_win_p() chl = len(win_printer.listpp()) if chl >= 1 and chk is True: if langu == 'ar': win_printer.printwin_ar( q.product, oot.prefix + '.' + str(ln + 1), oot.prefix + str(oot.name), tnum, ppt.name, oot.prefix + '.' + str(cuticket.number), ip=current_app.config['LOCALADDR']) else: win_printer.printwin( q.product, oot.prefix + '.' + str(ln + 1), oot.prefix + str(oot.name), tnum, ppt.name, oot.prefix + '.' + str(cuticket.number), l=langu, ip=current_app.config['LOCALADDR']) # FIX Issue printer on windows p = True else: p = None else: # To Fix 1: Fail safe drivers. [FIXED] try: p = ppp.assign(int(q.vendor), int(q.product), int(q.in_ep), int(q.out_ep)) except Exception: p = None if p is None: flash('Error: you must have available printer, to use printed', 'danger') flash("Notice: make sure that printer is properly connected", "info") if os.name == 'nt': flash( "Notice: Make sure to make the printer shared on the local network", "info") elif platform == "linux" or platform == "linux2": flash( "Notice: Make sure to execute the command `sudo gpasswd -a $(users) lp` and reboot the system", "info") return redirect(url_for('cust_app.ticket')) if os.name != 'nt': if langu == 'ar': ppp.printit_ar( p, oot.prefix + '.' + str(ln + 1), oot.prefix + str(oot.name), tnum, u'' + ppt.name, oot.prefix + '.' + str(cuticket.number)) else: ppp.printit( p, oot.prefix + '.' + str(ln + 1), oot.prefix + str(oot.name), tnum, u'' + ppt.name, oot.prefix + '.' + str(cuticket.number), lang=langu) db.session.commit() else: flash('Error: wrong entry, something went wrong', 'danger') return redirect(url_for('core.root')) for a in range(data.Waiting.query.count(), 11): for b in data.Serial.query.filter_by( p=False).order_by(data.Serial.timestamp): if data.Waiting.query.filter_by(office_id=b.office_id, number=b.number, task_id=b.task_id ).first() is None: db.session.add(data.Waiting(b.number, b.office_id, b.task_id, nm, n)) db.session.commit() return redirect(url_for("core.touch", a=1))