Esempio n. 1
0
def task_a(o_id):
    """ to add a task """
    form = forms.Task_a(session.get('lang'))
    office = data.Office.get(o_id)

    if office is None:
        flash('Error: wrong entry, something went wrong', 'danger')
        return redirect(url_for("core.root"))

    if is_operator() and data.Operators.get(current_user.id) is None:
        flash('Error: operators are not allowed to access the page ', 'danger')
        return redirect(url_for('core.root'))

    if is_operator() and o_id != data.Operators.get(current_user.id).office_id:
        flash('Error: operators are not allowed to access the page ', 'danger')
        return redirect(url_for('core.root'))

    if form.validate_on_submit():
        if data.Task.query.filter_by(name=form.name.data).first() is not None:
            flash('Error: name is used by another one, choose another name',
                  'danger')
            return redirect(url_for("manage_app.task_a", o_id=o_id))

        task = data.Task(form.name.data)
        db.session.add(task)
        db.session.commit()

        if office.id not in ids(task.offices):
            task.offices.append(office)
            db.session.commit()

        initial_ticket = data.Serial.query.filter_by(task_id=task.id,
                                                     office_id=o_id,
                                                     number=100)\
                                          .first()

        if not initial_ticket:
            db.session.add(
                data.Serial(office_id=task.offices[0].id,
                            task_id=task.id,
                            p=True))
            db.session.commit()

        flash("Notice: New task been added.", 'info')
        return redirect(url_for("manage_app.offices", o_id=o_id))
    return render_template(
        "task_add.html",
        form=form,
        offices=data.Office.query,
        serial=data.Serial.query.filter(data.Serial.number != 100),
        tasks=data.Task.query,
        operators=data.Operators.query,
        navbar="#snb1",
        common=False,
        dropdown="#dropdown-lvl" + str(o_id),
        hash="#t3" + str(o_id),
        page_title="Add new task")
Esempio n. 2
0
def common_task_a():
    """ to add a common task """
    if data.Office.query.count() <= 1:
        flash("Error: not enough offices exist to add a common task", 'danger')
        return redirect(url_for("manage_app.all_offices"))

    form = forms.Task_a(session.get('lang'), True)

    if form.validate_on_submit():
        task = data.Task(form.name.data)

        if data.Task.query.filter_by(name=form.name.data).first() is not None:
            flash("Error: name is used by another one, choose another name",
                  'danger')
            return redirect(url_for("manage_app.common_task_a"))

        offices_validation = [
            form[f'check{o.id}'].data for o in data.Office.query.all()
        ]
        if len(offices_validation) > 0 and not any(offices_validation):
            flash('Error: one office must be selected at least', 'danger')
            return redirect(url_for('manage_app.common_task_a'))

        db.session.add(task)
        db.session.commit()

        for office in data.Office.query.all():
            if form['check%i' % office.id].data and office not in task.offices:
                task.offices.append(office)

        for office in task.offices:
            initial_ticket = data.Serial.query\
                                 .filter_by(office_id=office.id, number=100)\
                                 .first()

            if not initial_ticket:
                db.session.add(
                    data.Serial(office_id=office.id, task_id=task.id, p=True))

        db.session.commit()
        flash("Notice: a common task has been added.", 'info')
        return redirect(url_for("manage_app.all_offices"))
    return render_template(
        "task_add.html",
        form=form,
        offices=data.Office.query,
        serial=data.Serial.query.filter(data.Serial.number != 100),
        tasks=data.Task.query,
        operators=data.Operators.query,
        navbar="#snb1",
        common=True,
        page_title="Add a common task",
        hash="#da6")
Esempio n. 3
0
File: manage.py Progetto: KsAmJ/FQM
def common_task_a():
    ''' to add a common task '''
    form = TaskForm(common=True)

    if form.validate_on_submit():
        task = data.Task(form.name.data, form.hidden.data)

        if data.Task.query.filter_by(name=form.name.data).first() is not None:
            flash('Error: name is used by another one, choose another name',
                  'danger')
            return redirect(url_for('manage_app.common_task_a'))

        offices_validation = [
            form[f'check{o.id}'].data for o in data.Office.query.all()
        ]
        if len(offices_validation) > 0 and not any(offices_validation):
            flash('Error: one office must be selected at least', 'danger')
            return redirect(url_for('manage_app.common_task_a'))

        db.session.add(task)
        db.session.commit()

        for office in data.Office.query.all():
            if form['check%i' % office.id].data and office not in task.offices:
                task.offices.append(office)

        for office in task.offices:
            initial_ticket = data.Serial.query\
                                 .filter_by(office_id=office.id, number=100)\
                                 .first()

            if not initial_ticket:
                db.session.add(
                    data.Serial(office_id=office.id, task_id=task.id, p=True))

        db.session.commit()
        flash('Notice: a common task has been added.', 'info')
        return redirect(url_for('manage_app.all_offices'))
    return render_template('task_add.html',
                           form=form,
                           offices=data.Office.query,
                           serial=data.Serial.all_clean(),
                           tasks=data.Task.query,
                           operators=data.Operators.query,
                           navbar='#snb1',
                           common=True,
                           page_title='Add a common task',
                           hash='#da6')
Esempio n. 4
0
File: manage.py Progetto: KsAmJ/FQM
def task_a(office):
    ''' to add a task '''
    form = TaskForm()

    if is_operator() and not is_office_operator(office.id):
        flash('Error: operators are not allowed to access the page ', 'danger')
        return redirect(url_for('core.root'))

    if form.validate_on_submit():
        if data.Task.query.filter_by(name=form.name.data).first() is not None:
            flash('Error: name is used by another one, choose another name',
                  'danger')
            return redirect(url_for('manage_app.task_a', o_id=office.id))

        task = data.Task(form.name.data, form.hidden.data)
        db.session.add(task)
        db.session.commit()

        if office.id not in ids(task.offices):
            task.offices.append(office)
            db.session.commit()

        initial_ticket = data.Serial.query.filter_by(task_id=task.id,
                                                     office_id=office.id,
                                                     number=100)\
                                          .first()

        if not initial_ticket:
            db.session.add(
                data.Serial(office_id=task.offices[0].id,
                            task_id=task.id,
                            p=True))
            db.session.commit()

        flash('Notice: New task been added.', 'info')
        return redirect(url_for('manage_app.offices', o_id=office.id))
    return render_template('task_add.html',
                           form=form,
                           offices=data.Office.query,
                           serial=data.Serial.all_clean(),
                           tasks=data.Task.query,
                           operators=data.Operators.query,
                           navbar='#snb1',
                           common=False,
                           dropdown='#dropdown-lvl' + str(office.id),
                           hash='#t3' + str(office.id),
                           page_title='Add new task')
Esempio n. 5
0
File: core.py Progetto: danfossi/FQM
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))
Esempio n. 6
0
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))
Esempio n. 7
0
def pull(o_id=None, ofc_id=None):
    ''' pull ticket for specific task and office or globally. '''
    def operators_not_allowed():
        flash('Error: operators are not allowed to access the page ', 'danger')
        return redirect(url_for('core.root'))

    strict_pulling = data.Settings.get().strict_pulling
    single_row = data.Settings.get().single_row
    task = data.Task.get(0 if single_row else o_id)
    office = data.Office.get(0 if single_row else ofc_id)
    global_pull = not bool(o_id and ofc_id)
    general_redirection = redirect(url_for('manage_app.all_offices')
                                   if global_pull or single_row else
                                   url_for('manage_app.task', ofc_id=ofc_id, o_id=o_id))

    if global_pull:
        if not single_row and is_operator():
            return operators_not_allowed()
    else:
        if not task:
            flash('Error: wrong entry, something went wrong', 'danger')
            return redirect(url_for('core.root'))

        if is_operator() and not (is_office_operator(ofc_id)
                                  if strict_pulling else
                                  is_common_task_operator(task.id)):
            return operators_not_allowed()

    next_tickets = data.Serial.query.filter(data.Serial.number != 100,
                                            data.Serial.p != True,
                                            data.Serial.on_hold == False)
    next_ticket = None

    if not global_pull:
        next_ticket = next_tickets.filter(data.Serial.task_id == task.id)

        if strict_pulling:
            next_ticket = next_ticket.filter(data.Serial.office_id == office.id)

    next_ticket = (next_tickets if global_pull else next_ticket)\
        .order_by(data.Serial.timestamp)\
        .first()

    if single_row:
        current_ticket = office.tickets\
                               .order_by(data.Serial.timestamp.desc())\
                               .first()
        next_ticket = data.Serial(number=getattr(current_ticket, 'number', 100) + 1,
                                  office_id=office.id,
                                  task_id=task.id)

        db.session.add(next_ticket)
        db.session.commit()

    if not next_ticket:
        flash('Error: no tickets left to pull from ..', 'danger')
        return general_redirection

    office = office or data.Office.get(next_ticket.office_id)
    task = task or data.Task.get(next_ticket.task_id)

    next_ticket.pull(office.id)
    flash('Notice: Ticket has been pulled ..', 'info')
    return general_redirection