Example #1
0
def make_second_copy(request, invoice):
    user = request.user

    invoice = Invoice.objects.get(pk=invoice)
    aux = Invoice.objects.filter(status=1, organization=invoice.organization, due_date__gt=datetime.now()).count()
    if aux <= 0:
        inv = Invoice()
        inv.organization = invoice.organization
        inv.due_date = datetime.now() + timedelta(days=7)
        inv.expiry_date = invoice.expiry_date
        inv.ammount = invoice.ammount
        inv.discount = invoice.discount
        inv.status = 1
        inv.plan = invoice.plan
        inv.save()

        invoice.status = 3
        invoice.save()

        data = BradescoBilletData.objects.all()[0]
        billet_url = gera_boleto_bradesco(request.user.id, inv, days=data.default_second_copy_days, second_copy=True)
        inv.billet_url = billet_url
        inv.save()
        aux = True
        message = 'Second copy details saved successfully'
    else:
        message = 'Second copy not generated: there are billets that still requiring payment.'
        aux = False

    return render_to_response('organization/second_copy.html', locals(), context_instance=RequestContext(request))
Example #2
0
def make_second_copy(request, invoice):
    user = request.user

    invoice = Invoice.objects.get(pk=invoice)
    aux = Invoice.objects.filter(status=1,
                                 organization=invoice.organization,
                                 due_date__gt=datetime.now()).count()
    if aux <= 0:
        inv = Invoice()
        inv.organization = invoice.organization
        inv.due_date = datetime.now() + timedelta(days=7)
        inv.expiry_date = invoice.expiry_date
        inv.ammount = invoice.ammount
        inv.discount = invoice.discount
        inv.status = 1
        inv.plan = invoice.plan
        inv.save()

        invoice.status = 3
        invoice.save()

        data = BradescoBilletData.objects.all()[0]
        billet_url = gera_boleto_bradesco(request.user.id,
                                          inv,
                                          days=data.default_second_copy_days,
                                          second_copy=True)
        inv.billet_url = billet_url
        inv.save()
        aux = True
        message = 'Second copy details saved successfully'
    else:
        message = 'Second copy not generated: there are billets that still requiring payment.'
        aux = False

    return render_to_response('organization/second_copy.html',
                              locals(),
                              context_instance=RequestContext(request))
    def run(self, **kwargs):
        logger = self.get_logger(**kwargs)
        logger.info("CheckAndCharge Started.")

        orgs = Organization.objects.filter(
            organization__isnull=True, active=True)
        # for p in Invoice.objects.all():
        #    p.expiry_date = p.expiry_date
        #    p.save()

        '''
        INVOICE_STATUS_CHOICES = (
            (1, _('Emitido')),
            (2, _('Pago')),
            (3, _('Excluido')),
        )
        INVOICE_TYPES = (
            (1, _('Inscription')),
            (2, _('Monthly fee')),
        )
        '''
        for org in orgs:
            last_invoice = org.current_invoice

            # correcao temporaria para evitar problemas no desenvolvimento
            try:
                len(last_invoice.status)
            except:
                last_invoice = Invoice.objects.filter(
                    organization=org).order_by('-date')[0]

            if last_invoice.status == 1:  # check if the last invoice isn't paid
                check = last_invoice.due_date > datetime.now()  # check if the invoice is not due
            elif last_invoice.status == 2:
                # check if this company last paid invoice is going to expire in
                # ten days
                check = last_invoice.expiry_date < datetime.today() + timedelta(days=10)
            else:
                check = True

            if check:  # no need to do anything with this organization
                continue
            else:  # send an email to the person responsible for the organization with a new billet to pay
                person = ProfessionalResponsible.objects.get(
                    organization=org).person
                user = person.user

                # create the new invoice
                inv = Invoice()
                inv.organization = org

                # prefered plan
                pplan = org.prefered_plan

                # verifica se ha um invoice passado para extrair um plano, caso nao,
                # atribui um plano de um mes para a quantia de funcionarios
                # cadastrados
                staff_count = org.person_set.all().count()
                if pplan is not None:
                    inv.plan = pplan
                elif last_invoice.plan is not None:
                    inv.plan = last_invoice.plan
                else:
                    inv.plan = None

                # define a data de vencimento(pagamento) do boleto
                dday = org.default_payment_day
                inv.due_date = last_invoice.expiry_date.replace(day=dday)

                # define a data de vencimento(acesso ao sistema) do boleto
                pplan = org.prefered_plan
                inv.expiry_date = inv.due_date + \
                    relativedelta(months=pplan.duration)
                inv.save()

                org.current_invoice = inv
                org.save()
                url_boleto = gera_boleto_bradesco(user.id, inv)

                email = user.email
                if email is not None and len(email) > 0:
                    bcc_list = ['*****@*****.**', user.email]
                else:
                    bcc_list = ['*****@*****.**']
                msg = EmailMessage()
                msg.subject = 'Teste: Cobrança de mensalidade'
                #temp = request.META
                # if request is None:
                msg.body = render_to_string(
                    'async_tasks/email_cobranca_mensalidade.html', locals())
                # else:
                #    from celery.schedules import discard_all
                #    discard_all()
                #    return render_to_response('async_tasks/email_cobranca_mensalidade.html', locals())
                # msg.from = 'GestoPSI <*****@*****.**>'
                msg.to = ['*****@*****.**', ]
                msg.bcc = bcc_list
                msg.content_subtype = "html"  # Main content is now text/html
                msg.send()

        logger.info("CheckAndCharge Finished.\n\n")
Example #4
0
    def run(self, **kwargs):
        logger = self.get_logger(**kwargs)
        logger.info("CheckAndCharge Started.")

        orgs = Organization.objects.filter(organization__isnull=True,
                                           active=True)
        #for p in Invoice.objects.all():
        #    p.expiry_date = p.expiry_date
        #    p.save()
        '''
        INVOICE_STATUS_CHOICES = (
            (1, _('Emitido')),
            (2, _('Pago')),
            (3, _('Excluido')),
        )
        INVOICE_TYPES = (
            (1, _('Inscription')),
            (2, _('Monthly fee')),
        )
        '''
        for org in orgs:
            last_invoice = org.current_invoice

            #correcao temporaria para evitar problemas no desenvolvimento
            try:
                len(last_invoice.status)
            except:
                last_invoice = Invoice.objects.filter(
                    organization=org).order_by('-date')[0]

            if last_invoice.status == 1:  #check if the last invoice isn't paid
                check = last_invoice.due_date > datetime.now(
                )  #check if the invoice is not due
            elif last_invoice.status == 2:
                #check if this company last paid invoice is going to expire in ten days
                check = last_invoice.expiry_date < datetime.today(
                ) + timedelta(days=10)
            else:
                check = True

            if check:  #no need to do anything with this organization
                continue
            else:  #send an email to the person responsible for the organization with a new billet to pay
                person = ProfessionalResponsible.objects.get(
                    organization=org).person
                user = person.user

                #create the new invoice
                inv = Invoice()
                inv.organization = org

                #prefered plan
                pplan = org.prefered_plan

                #verifica se ha um invoice passado para extrair um plano, caso nao,
                #atribui um plano de um mes para a quantia de funcionarios cadastrados
                staff_count = org.person_set.all().count()
                if pplan is not None:
                    inv.plan = pplan
                elif last_invoice.plan is not None:
                    inv.plan = last_invoice.plan
                else:
                    inv.plan = None

                #define a data de vencimento(pagamento) do boleto
                dday = org.default_payment_day
                inv.due_date = last_invoice.expiry_date.replace(day=dday)

                #define a data de vencimento(acesso ao sistema) do boleto
                pplan = org.prefered_plan
                inv.expiry_date = inv.due_date + relativedelta(
                    months=pplan.duration)
                inv.save()

                org.current_invoice = inv
                org.save()
                url_boleto = gera_boleto_bradesco(user.id, inv)

                email = user.email
                if email is not None and len(email) > 0:
                    bcc_list = ['*****@*****.**', user.email]
                else:
                    bcc_list = ['*****@*****.**']
                msg = EmailMessage()
                msg.subject = 'Teste: Cobrança de mensalidade'
                #temp = request.META
                #if request is None:
                msg.body = render_to_string(
                    'async_tasks/email_cobranca_mensalidade.html', locals())
                #else:
                #    from celery.schedules import discard_all
                #    discard_all()
                #    return render_to_response('async_tasks/email_cobranca_mensalidade.html', locals())
                #msg.from = 'GestoPSI <*****@*****.**>'
                msg.to = [
                    '*****@*****.**',
                ]
                msg.bcc = bcc_list
                msg.content_subtype = "html"  # Main content is now text/html
                msg.send()

        logger.info("CheckAndCharge Finished.\n\n")