Beispiel #1
0
def pouch_insert():
    flash('')
    if request.method == 'POST':
        if request.form['codepouch'].strip() == '':
            message = 'Code is empty'
        else:
            message = PouchController.criticacodepouch(
                request.form['codepouch'].strip().upper())
            if message.strip() == '':
                result = CompanyModel.findcodesyndcomp(
                    request.form['codesynd'], request.form['codecomp'])
                if result == None:
                    codesynd = request.form['codesynd']
                    codecomp = request.form['codecomp']
                    message = f"Don't have Company {codecomp} with this Syndicate {codesynd}"
                else:
                    message = utils.date_valid(request.form['dtarrived'])
                    if message == None:
                        message = utils.criticaint(request.form['quant'],
                                                   'Quant')
                        if message.strip() == '':
                            message = utils.criticaint(request.form['value'],
                                                       'Value')
                            if message.strip() == '':
                                message = PouchModel.insert(
                                    request.form['codepouch'].upper(),
                                    request.form['dtarrived'],
                                    request.form['codecard'],
                                    request.form['codesynd'],
                                    request.form['codecomp'],
                                    request.form['quant'],
                                    request.form['value'])
                                if message.strip() == '':
                                    pouchs = PouchModel.finddtarrived(
                                        request.form['dtarrived'])
                                    return render_template('Pouch/menu.html',
                                                           pouchs=pouchs)
        flash(message)
    cards: CardModel.Card = CardModel.findall()
    synds: SyndicateModel.Syndicate = SyndicateModel.findall()
    comps: CompanyModel.Company = CompanyModel.findall()
    return render_template('Pouch/insert.html',
                           cards=cards,
                           synds=synds,
                           comps=comps)
Beispiel #2
0
def dataanalysis():
    flash('')
    if request.method == 'POST':
        field = request.form['searchfield']

        optiondate = request.form['optiondate']
        if optiondate == 'monthyear':
            dtarrived = field[-4:] + '-' + field[:2] + '-01'
        else:
            dtarrived = field + '-01-01'

        message = utils.date_valid(dtarrived)

        if message == None:
            option = request.form['option']

            message = getparameters(optiondate, option,
                                    request.form['searchfield'])
        flash(message)
    return render_template('DataAnalysis/search.html')
Beispiel #3
0
def pouch_edit(id: int):
    flash('')
    pouch = PouchModel.findone(id)
    if request.method == 'POST':
        message = utils.date_valid(request.form['dtarrived'])
        if message.strip() == '':
            message = utils.criticaint(request.form['quant'], 'Quant')
            if message.strip() == '':
                message = utils.criticaint(request.form['value'], 'Value')
                if message.strip() == '':
                    dtarrived = request.form['dtarrived']
                    message = PouchModel.edit(pouch, request.form['dtarrived'],
                                              request.form['quant'],
                                              request.form['value'])
                    if message.strip() == '':
                        pouchs = PouchModel.finddtarrived(dtarrived)
                        return render_template('Pouch/menu.html',
                                               pouchs=pouchs)
        flash(message)
    return render_template('Pouch/edit.html', pouch=pouch)
Beispiel #4
0
def criticasearch(field: str) -> str:
    if field.strip() == '':
        return 'Data Arrived is empty'
    if not date_valid(field):
        return 'Date invalid'
Beispiel #5
0
def report():
    if request.method == 'POST':
        field = request.form['searchfield']
        dtarrived = field[6:] + '-' + field[3:5] + '-' + field[:2]

        message = utils.date_valid(dtarrived)

        if message == None:
            message, pouchs = PouchController.search(
                request.form['searchfield'])
            data = pouchs

            if message == None:
                searchfield = request.form['searchfield']

                filepdf = FPDF('P', 'mm', 'A4')  # Portrait

                filepdf.add_page()
                filepdf.set_font('Arial', '', 10)
                filepdf.cell(190, 4, 'Página ' + str(filepdf.page_no()), 0, 1,
                             'R')
                filepdf.set_font('Arial', 'B', 16)
                filepdf.cell(
                    190, 4, 'Date Arrived Report - ' +
                    searchfield + '          ' + datetime.strftime(
                        datetime.today().now(), '%d/%m/%Y %H:%M'), 0, 1, 'C')
                filepdf.set_font('Courier', '', 10)
                filepdf.cell(190, 4, ' ', 0, 1, 'R')
                # 60 = weight 20 = height by cell 0 = border 1 = break line L = align
                subtitle = '   Date    Pouch      Card       Syndicate       ' \
                           'Company        Quant  Value'
                filepdf.set_font('Courier', '', 10)
                filepdf.cell(190, 4, subtitle, 0, 1, 'L')
                contline = 2
                for reg in data:
                    dtarrive = reg.dtarrived[:2] + '/' + reg.dtarrived[5:7] + '/' \
                               + reg.dtarrived[0:4]
                    codepouch = reg.codepouch
                    codecard = reg.codecard
                    codesynd = reg.codesynd
                    codecomp = reg.codecomp
                    quant = reg.quant
                    value = reg.value

                    if contline > 59:
                        filepdf.add_page()
                        filepdf.set_font('Arial', '', 10)
                        filepdf.cell(190, 4, 'Page ' + str(filepdf.page_no()),
                                     0, 1, 'R')
                        subtitle = '   Date    Pouch      Card       Syndicate       Company        ' \
                                   'Quant  Value'
                        filepdf.set_font('Courier', '', 10)
                        filepdf.cell(190, 4, subtitle, 0, 1, 'L')
                        contline = 2

                    contline += 1

                    filepdf.cell(
                        210, 4, f'{dtarrive:} {codepouch:<10} {codecard:<10} '
                        f'{codesynd:<15} {codecomp:<15} {quant:>4} '
                        f'{value:>6.2f}', 0, 1, 'L')
                try:
                    dtarrived = searchfield[6:] + '-' + searchfield[
                        3:5] + '-' + searchfield[:2]
                    filepdf.output(f'ReportPouch_{dtarrived}.pdf',
                                   'F')  # D - Web   F- Local
                    message = 'Generated Report'
                except Exception:
                    message = 'The file pdf is open'
        flash(message)
    return render_template('Report/search.html')