コード例 #1
0
def inst_payment(id, contract_id, inst_id):

    try:
        con = postgres_connetion(host_postgres, db_name_postgres,
                                 db_user_postgres, db_password_postgres)
        cur = con.cursor()
        inst_record = search_one_instalment({'extern_id': f"{inst_id}"}, cur)
        print('inst_record')
        remaining_amount = request.args.get('remaining_amount')
        payment = False

        if remaining_amount == '0.0':

            flash(" L'échéance Selectionnée Est  Déja Payé")
            return redirect(
                url_for('payment.show_all_payments',
                        id=id,
                        contract_id=contract_id))

        if request.method == 'POST':

            if request.form['submit'] == 'Payer':
                extern_id = "pay" + time_number()
                keys = "client_id,contract_id,inst_id,extern_id"
                values = [id, contract_id, inst_id, extern_id]
                f = request.form
                for key in f.keys():
                    if key != 'submit' and request.form[key] != '':
                        keys = keys + ',' + key
                        values.append(str(request.form[key]))
                update_dict = {
                    'remaining_amount': round(request.form['amount'], 2)
                }

                values = tuple(values)

                add_payment(values, keys, con, cur)
                update_payment(update_dict, id, inst_id, con, cur)
                payment = True
    except Exception as error:
        print(error)
        abort(422)
    finally:
        if con is not None:
            cur.close()
            con.close()
    if payment == True:

        return redirect(
            url_for('payment.show_all_payments',
                    id=id,
                    contract_id=contract_id))
    else:
        return render_template('paiement.html',
                               id=id,
                               contract_id=contract_id,
                               inst_id=inst_id,
                               remaining_amount=remaining_amount,
                               inst_record=inst_record)
コード例 #2
0
def subscription():

    con=None
    if request.method=='POST':
        if request.form['submit']=="S'abonner":
            
            try :
                register_user=False
                id="usr"+time_number()
                name= request.form.get('name')
                last_name=request.form.get('last_name')
                email=request.form.get('email')
                tel=request.form.get('phone')
                user_name=request.form.get('user_name')
                password=request.form.get('password')
                user_type=request.form.get('user_type')

                user=User(
                    name=name,
                    last_name=last_name,
                    email=email,
                    tel=tel,
                    id=id,
                    user_name=user_name,
                    password=password,
                    user_type=user_type)
            except Exception as error:
                print(error)
                abort(400)

            try:
                con=postgres_connetion(
                    host_postgres,
                    db_name_postgres,
                    db_user_postgres,
                    db_password_postgres)
                cur=con.cursor()
                create_user(user,con,cur)
                register_user=True
                
            except (Exception, psycopg2.Error) as error:
                print(error)
                if  isinstance(error,UniqueViolation):
                    flash('Les informations choisies existent déjà')
                else:
                    abort(422)
            finally:
                if con is not None:
                    cur.close()
                    con.close()
            if register_user==True:
                flash('Utilisateur répertorié avec succès')
    return render_template("user/subscription_user.html")
コード例 #3
0
def add_one_sinister(id,contract_id):
 
    if request.method=='POST':
        try:
            description=request.form['description']
            opposing_insurer=request.form['opposing_insurer']
            amount=request.form['amount']
            sinister_date=request.form['sinister_date']
            if amount and amount !='':
                extern_id="sin"+time_number()
                sinister=Sinister(
                    sinister_date=sinister_date,
                    description=description,
                    opposing_insurer=opposing_insurer,
                    amount=float(amount))

        except Exception as error:
            print(error)
            abort(400)
        try:
            con=postgres_connetion(
                host_postgres,
                db_name_postgres,
                db_user_postgres,
                db_password_postgres)
            cur=con.cursor()
            con_id=get_contract_id(contract_id,con,cur)
            cl_id=get_client_by_extern_id(id,con,cur)
            add_sinister(sinister,extern_id,id,contract_id,cl_id,con_id,con,cur)
            
            flash('Listed Successfully !')
        except Exception as error:
            print(error)
        
        finally :
            if con is not None:
                cur.close()
                con.close()
      
        return redirect(url_for("client.display_client",id=id,contract_id=contract_id))
        
    return render_template("sinister/create_sinister.html",id=id,contract_id=contract_id)
コード例 #4
0
def client_subscription():
    abort(404)
    if request.method == 'POST':

        print(request.form)
        con = None
        nb_inst = None
        try:
            register = False
            contract_id = "ctr" + time_number()
            id_address = 'adr' + time_number()
            name = request.form['first_name']
            last_name = request.form['last_name']
            email = request.form['email']

            client_type = request.form['client_type']

            tel = request.form['full_number']
            line1 = request.form['line1']
            line2 = request.form['line2']
            city = request.form['city']
            postal_code = request.form['postal_code']
            country = request.form['country']
            state = request.form['state']
            price = request.form.get('price')
            contract_type = request.form.get('contract_type')
            start_date = request.form.get('start_date')

            end_date = request.form.get('end_date')

            id = name[0] + last_name[0:2] + time_number()

            payment_amount = request.form.get('payment_amount')
            payment_mode = request.form.get('payment_mode')
            nb_bank_check = request.form.get('nb_bank_check')
            transaction_number = request.form.get('transaction_number')
            card_number = request.form.get('card_number')
            payor_last_name = request.form.get('payor_last_name')
            payor_name = request.form.get('payor_name')
            nb_inst = request.form.get('nb_inst')

            if country == '':
                country = default_country_name
            if request.form.get('nb_inst') != '0':
                nb_inst = int(request.form.get('nb_inst'))
            address = Address(id=id_address,
                              line1=line1,
                              line2=line2,
                              city=city,
                              postal_code=postal_code,
                              state=state,
                              country=country)
            if price == '':
                contract = None
            else:
                contract = Contract(id=contract_id,
                                    price=float(price),
                                    contract_type=contract_type,
                                    start_date=start_date,
                                    end_date=end_date)
            client = Client(id=id,
                            name=name,
                            last_name=last_name,
                            email=email,
                            tel=tel,
                            client_type=client_type,
                            address=address)

        except Exception as error:
            print(error)
            abort(400)
        try:
            con = postgres_connetion(host_postgres, db_name_postgres,
                                     db_user_postgres, db_password_postgres)
            cur = con.cursor()
            if client_type == 'Client Potentiel':
                insert_client_info(client, con, cur)
                client_id = get_client_id(email, con, cur)
                print(client_id)
                session.client_sub_id = client_id
                insert_address_info(address, client_id, id, con, cur)
                register = True
                contract_id = 'ClientPotentiel'

            else:
                due_date = datetime.datetime.now().date()
                insts = []

                if nb_inst != '0':

                    insert_client_info(client, con, cur)
                    client_id = get_client_id(email, con, cur)
                    print(client_id)
                    session.client_sub_id = client_id
                    insert_address_info(address, client_id, id, con, cur)
                    insert_contract_info(contract, client_id, con, cur)
                    ctr_id = get_contract_id(contract_id, con, cur)
                    inst_amount = round(float(price) / nb_inst, 2)

                    for i in range(nb_inst):

                        inst = Instalment(amount=inst_amount,
                                          due_date=str(due_date))
                        due_date = due_date + datetime.timedelta(days=30)
                        insts.append((inst, "inst" + f"{i}" + time_number()))

                    insert_one_client_instalments(insts, client_id, ctr_id, id,
                                                  contract_id, con, cur)

                else:
                    insert_client_info(client, con, cur)
                    client_id = get_client_id(email, con, cur)
                    session.client_sub_id = client_id
                    insert_address_info(address, client_id, id, con, cur)
                    insert_contract_info(contract, client_id, con, cur)
                    ctr_id = get_contract_id(contract_id, con, cur)

                    keys = "client_id,contract_id,extern_id,extern_client_id,extern_contract_id"
                    values = [
                        client_id, ctr_id, 'pay' + time_number(), id,
                        contract_id
                    ]
                    if payment_amount:
                        keys = keys + "," + 'payment_amount'
                        values.append(payment_amount)
                    if payment_mode:
                        keys = keys + "," + 'payment_mode'
                        values.append(payment_mode)
                    if nb_bank_check:
                        keys = keys + "," + 'nb_bank_check'
                        values.append(nb_bank_check)
                    if transaction_number:
                        keys = keys + "," + 'transaction_number'
                        values.append(transaction_number)
                    if card_number:
                        keys = keys + "," + 'card_number'
                        values.append(card_number)

                    if payor_last_name:
                        keys = keys + "," + 'payor_last_name'
                        values.append(payor_last_name)
                    if payor_name:
                        keys = keys + "," + 'payor_name'
                        values.append(payor_name)
                    values = tuple(values)
                    if keys != 'client_id,contract_id,payment_mode':
                        insert_client_info_payment(keys, values, con, cur)
                    else:
                        flash('Paiement Non Enregistré')
                register = True
                flash('Subscription Successfully Made')
        except (Exception, psycopg2.Error) as error:
            print(error)
            print('hello7')
            register = False
            if isinstance(error, UniqueViolation):
                flash('Chosen Information Already Existe')
            else:
                abort(422)
        finally:
            if con is not None:
                cur.close()
                con.close()
        if register == True:
            return redirect(
                url_for("client.display_client",
                        id=id,
                        contract_id=contract_id))

    return render_template("client/souscription_client.html",
                           now=str(datetime.datetime.now().date()))
コード例 #5
0
def company_subscription():
    print(request.form)

    if request.method == 'POST':

        con = None
        nb_inst = None
        try:
            register = False
            contract_id = 's' + "ctr" + time_number() + 's'
            id_address = 's' + 'adr' + time_number() + 's'
            company_name = request.form['company_name']
            company_email = request.form['company_email']
            client_type = request.form['client_type']
            company_tel = request.form['full_number']

            line1 = request.form['line1']
            line2 = request.form['line2']
            city = request.form['city']
            postal_code = request.form['postal_code']
            country = request.form['country']
            state = request.form['state']

            company_registration_nb = request.form['company_registration_nb']
            price = request.form.get('price')
            contract_type = request.form.get('contract_type')
            start_date = request.form.get('start_date')

            end_date = request.form.get('end_date')
            id = 's' + company_name[0:3] + time_number()
            payment_amount = request.form.get('payment_amount')
            payment_mode = request.form.get('payment_mode')
            nb_bank_check = request.form.get('nb_bank_check')
            transaction_number = request.form.get('transaction_number')
            card_number = request.form.get('card_number')
            payor_last_name = request.form.get('payor_last_name')
            payor_name = request.form.get('payor_name')
            nb_inst = request.form.get('nb_inst')

            if country == '':
                country = default_country_name
            if request.form.get('nb_inst') != '0':
                nb_inst = int(request.form.get('nb_inst'))

            address = Address(id=id_address,
                              line1=line1,
                              line2=line2,
                              city=city,
                              postal_code=postal_code,
                              state=state,
                              country=country)
            if price == '':
                contract = None
            else:
                contract = Contract(id=contract_id,
                                    price=float(price),
                                    contract_type=contract_type,
                                    start_date=start_date,
                                    end_date=end_date)
            company = Company(id=id,
                              company_name=company_name,
                              company_email=company_email,
                              company_tel=company_tel,
                              company_registration_nb=company_registration_nb,
                              company_type=client_type,
                              address=address)

        except Exception as error:
            print(error)
            abort(400)
        try:
            con = postgres_connetion(host_postgres, db_name_postgres,
                                     db_user_postgres, db_password_postgres)
            cur = con.cursor()

            if client_type == 'Client Potentiel':
                insert_company_info(company, con, cur)
                company_id = get_company_id(company_email, con, cur)
                print(company_id)
                session.company_sub_id = company_id
                insert_address_info_company(address, company_id, id, con, cur)
                register = True
                contract_id = 'ClientPotentiel'
            else:
                due_date = datetime.datetime.now().date()
                insts = []

                if nb_inst != '0':

                    insert_company_info(company, con, cur)
                    company_id = get_company_id(company_email, con, cur)
                    print(company_id)
                    session.company_sub_id = company_id
                    insert_address_info_company(address, company_id, id, con,
                                                cur)
                    insert_contract_info_company(contract, company_id, con,
                                                 cur)
                    ctr_id = get_contract_id(contract_id, con, cur)
                    inst_amount = round(float(price) / nb_inst, 2)

                    for i in range(nb_inst):

                        inst = Instalment(amount=inst_amount,
                                          due_date=str(due_date))
                        due_date = due_date + datetime.timedelta(days=30)
                        insts.append((inst, "inst" + f"{i}" + time_number()))

                    insert_one_company_instalments(insts, company_id, ctr_id,
                                                   id, contract_id, con, cur)

                else:
                    insert_company_info(company, con, cur)
                    print(company_email)
                    company_id = get_company_id(company_email, con, cur)
                    print(company_id)

                    session.company_sub_id = company_id
                    insert_address_info_company(address, company_id, id, con,
                                                cur)

                    insert_contract_info_company(contract, company_id, con,
                                                 cur)
                    ctr_id = get_contract_id(contract_id, con, cur)

                    keys = "company_id,contract_id,extern_id,extern_client_id,extern_contract_id"
                    values = [
                        company_id, ctr_id, 'pay' + time_number(), id,
                        contract_id
                    ]
                    if payment_amount:
                        keys = keys + "," + 'payment_amount'
                        values.append(payment_amount)
                    if payment_mode:
                        keys = keys + "," + 'payment_mode'
                        values.append(payment_mode)
                    if nb_bank_check:
                        keys = keys + "," + 'nb_bank_check'
                        values.append(nb_bank_check)
                    if transaction_number:
                        keys = keys + "," + 'transaction_number'
                        values.append(transaction_number)
                    if card_number:
                        keys = keys + "," + 'card_number'
                        values.append(card_number)
                    if payor_last_name:
                        keys = keys + "," + 'payor_last_name'
                        values.append(payor_last_name)
                    if payor_name:
                        keys = keys + "," + 'payor_name'
                        values.append(payor_name)
                    values = tuple(values)

                    if keys != 'company_id,contract_id,payment_mode':
                        print('hello5')
                        insert_client_info_payment(keys, values, con, cur)
                        print('gejkjnwdkjcnwkcjnwkjnwkxjc')
                    else:
                        flash('Paiement Non Enregistré')
                register = True
                flash('Subscription Successfully Made')
            try:
                with current_app.app_context():
                    template = render_template("mail_confirmation.html")
                    mail = Mail()

                    msg = Message("Hello",
                                  sender="*****@*****.**",
                                  recipients=[company_email])
                    msg.html = template
                    mail.send(msg)
            except (Exception, smtplib.SMTPResponseException) as error:
                print(error)
                abort(422)

                flash('confirmation non envoyé svp vérifiez votre mail')
        except (Exception, psycopg2.Error) as error:
            print(error)
            register = False
            if isinstance(error, UniqueViolation):
                flash('Chosen Information Already Existe')
            else:
                abort(422)
        finally:
            if con is not None:
                cur.close()
                con.close()
        if register == True:

            return redirect(
                url_for("client.display_company",
                        id=id,
                        contract_id=contract_id))

    return render_template("company/souscription_company.html",
                           now=str(datetime.datetime.now().date()))
コード例 #6
0
def update_sinister_(id,sinister_id):
    
    con=postgres_connetion(
        host_postgres,
        db_name_postgres,
        db_user_postgres,
        db_password_postgres)
    cur=con.cursor()
    sinister=sinister_to_update(id,sinister_id,con,cur)


    if request.method=='POST':
        print(request.form)
        try:
            update_dict={}
            modification={}
            description=request.form['description']
            opposing_insurer=request.form['opposing_insurer']
            amount=request.form['amount']
            status=request.form['status']
            sinister_date=request.form['sinister_date']

            if sinister_date:
                update_dict['sinister_date']=sinister_date

            if description:
                update_dict['description']=description
            if opposing_insurer:
                update_dict['opposing_insurer']=opposing_insurer
            if amount and amount!='':
                update_dict['amount']=float(amount)
            if status and status!='':
                
                update_dict['status']=status 
                if status=="Valide" or status=="Invalide":
                    update_dict['closing_date']=str(datetime.datetime.now().date())
            if update_dict=={}:
                flash('No Modification Is Made')
                return redirect(url_for("client.display_company",id=session['client_id'],contrcat_id=session['contract_id']))
        except Exception as error:
            print(error)
            abort(400)
        try:
            con=postgres_connetion(
                host_postgres,
                db_name_postgres,
                db_user_postgres,
                db_password_postgres)
            cur=con.cursor()
            
            cl_id=get_company_by_extern_id(id,con,cur)
            con_id=get_contract_id(session['contract_id'],con,cur)



            if sinister.status=='Valide' or sinister.status=='Invalide' :
                flash("Can't Update Sinister Already Close")
            else:
                count=count_modification(sinister_id,con,cur)
                if count<=5:

                    count=count_modification(sinister_id,con,cur)
                    update_one_sinister(update_dict,id,sinister_id,con,cur)
                    
                    modification['updated_id']=sinister_id
                    modification['updates_values']=json.dumps(update_dict)
                    modification['updated_by']=session['user']
                    
                    modification['extern_id']='mdf'+time_number()
                    add_modification(modification,con,cur)
                else:
                    flash('Nombre maximale  de modification est dépassé')
                    return redirect(url_for("client.display_company",id=session['client_id'],contract_id=session['contract_id']))
                
                    

                if 'status' in update_dict.keys():
                    if update_dict['status']=='Valide':
                        if 'amount' in update_dict.keys():
                            sinister.amount=update_dict['amount']
                        extern_id="ind"+time_number()
                        create_indemnity_(sinister,extern_id,cl_id,con_id,id,session['contract_id'],con,cur)
                
                flash('Updated Sucessfully !')
        except Exception as error:
            print(error)
            abort(422)
        finally :
            if con is not None:
                cur.close()
                con.close()
        return redirect(url_for("client.display_company",id=session['client_id'],contract_id=session['contract_id']))

    return render_template("sinister/modify_sinister.html",id=id,sinister_id=sinister_id,sinister=sinister)
コード例 #7
0
def add_contract_(id):
    if request.method == 'POST':
        try:
            price = request.form['price']
            contract_type = request.form['contract_type']
            start_date = request.form['start_date']
            end_date = request.form['end_date']
            nb_inst = int(request.form['nb_inst'])

            payment_amount = request.form.get('payment_amount')
            payment_mode = request.form.get('payment_mode')
            nb_bank_check = request.form.get('nb_bank_check')
            transaction_number = request.form.get('transaction_number')
            card_number = request.form.get('card_number')
            payor_last_name = request.form.get('payor_last_name')
            payor_name = request.form.get('payor_name')

            contract_id = "ctr" + time_number()
            contract = Contract(id=contract_id,
                                price=price,
                                contract_type=contract_type,
                                start_date=start_date,
                                end_date=end_date)

        except Exception as error:
            print(error)
            abort(400)

        try:
            con = postgres_connetion(host_postgres, db_name_postgres,
                                     db_user_postgres, db_password_postgres)
            cur = con.cursor()

            company_id = get_company_by_extern_id(id, con, cur)
            insert_contract_info_company(contract, company_id, con, cur)
            con_id = get_contract_id(contract_id, con, cur)
            due_date = datetime.datetime.now().date()

            insts = []
            if nb_inst != 0:
                inst_amount = round(float(price) / nb_inst, 2)
                inst_amount_0 = float(price) - (inst_amount *
                                                nb_inst) + inst_amount
                inst = Instalment(amount=round(inst_amount_0, 2),
                                  due_date=str(due_date))
                due_date = due_date + datetime.timedelta(days=30)
                insts.append((inst, "inst" + "0" + time_number()))
                for i in range(1, nb_inst):
                    print(i)
                    inst = Instalment(amount=inst_amount,
                                      due_date=str(due_date))
                    due_date = add_months(due_date, 1)
                    insts.append((inst, "inst" + f"{i}" + time_number()))

                insert_one_company_instalments(insts, company_id, con_id, id,
                                               contract_id, con, cur)

            else:
                extern_id = 'pay' + time_number()

                keys = "extern_contract_id,extern_client_id,extern_id,company_id,contract_id"
                values = [contract_id, id, extern_id, company_id, con_id]

                if payment_mode:
                    keys = keys + "," + 'payment_mode'
                    values.append(payment_mode)
                if payment_amount:
                    keys = keys + "," + 'payment_amount'
                    values.append(payment_amount)
                if nb_bank_check:
                    keys = keys + "," + 'nb_bank_check'
                    values.append(nb_bank_check)
                if transaction_number:
                    keys = keys + "," + 'transaction_number'
                    values.append(transaction_number)
                if card_number:
                    keys = keys + "," + 'card_number'
                    values.append(card_number)

                if payor_last_name:
                    keys = keys + "," + 'payor_last_name'
                    values.append(payor_last_name)
                if payor_name:
                    keys = keys + "," + 'payor_name'
                    values.append(payor_name)
                values = tuple(values)
                if keys != 'company_id,contract_id,payment_mode':
                    add_payment(keys, values, con, cur)
            update_company_info({'company_type': 'Client'}, id, con, cur)
            flash('Listed Successfully ')
        except Exception as error:
            print(error)
            abort(422)
        finally:
            if con is not None:
                cur.close()
                con.close()
        return redirect(
            url_for("client.display_company", id=id, contract_id=contract_id))

    return render_template("contract/add_contract.html",
                           id=id,
                           now=str(datetime.datetime.now().date()))