コード例 #1
0
ファイル: tools.py プロジェクト: christiankirk/InternProject
    def make_invoices(self): #Function to make invoices with no arguments
        for invoice in self.policy.invoices:
            invoice.delete()

        billing_schedules = {'Annual': None, 'Semi-Annual': 3, 'Quarterly': 4, 'Monthly': 12} #Creating a dictionary that specifies the definitions of each word

        invoices = [] #Creating a list names invoices
        first_invoice = Invoice(self.policy.id, #Creating the first invoice from using Invoice() from models.py
                                self.policy.effective_date, #bill_date
                                self.policy.effective_date + relativedelta(months=1), #due date
                                self.policy.effective_date + relativedelta(months=1, days=14), #cancel date two weeks after
                                self.policy.annual_premium) #Amount due
        invoices.append(first_invoice) #Placing first invoice into the list named invoices

        if self.policy.billing_schedule == "Annual": #If the billing schedule is equal to Annual then pass
            pass
        elif self.policy.billing_schedule == "Two-Pay": #Else if the billing schedule is equto to Two-Pay
            first_invoice.amount_due = first_invoice.amount_due / billing_schedules.get(self.policy.billing_schedule) #Figuring out amount due from first invoice
            for i in range(1, billing_schedules.get(self.policy.billing_schedule)): #For every object in the range(starting at one,stopping at billing schedule)
                months_after_eff_date = i*6 #Multiplies by 6 to split 12 months into two payments
                bill_date = self.policy.effective_date + relativedelta(months=months_after_eff_date)
                invoice = Invoice(self.policy.id, #Create an invoice for this specification
                                  bill_date,
                                  bill_date + relativedelta(months=1),
                                  bill_date + relativedelta(months=1, days=14),
                                  self.policy.annual_premium / billing_schedules.get(self.policy.billing_schedule))
                invoices.append(invoice)
        elif self.policy.billing_schedule == "Quarterly": #Else if billing schedule is Quarterly
            first_invoice.amount_due = first_invoice.amount_due / billing_schedules.get(self.policy.billing_schedule)
            for i in range(1, billing_schedules.get(self.policy.billing_schedule)):
                months_after_eff_date = i*3 #Multiplies by 3 to split 12 months into 4 payments
                bill_date = self.policy.effective_date + relativedelta(months=months_after_eff_date)
                invoice = Invoice(self.policy.id,
                                  bill_date,
                                  bill_date + relativedelta(months=1),
                                  bill_date + relativedelta(months=1, days=14),
                                  self.policy.annual_premium / billing_schedules.get(self.policy.billing_schedule))
                invoices.append(invoice)
        elif self.policy.billing_schedule == "Monthly": #Else if billing schedule is Monthly
            first_invoice.amount_due = first_invoice.amount_due / billing_schedules.get(self.policy.billing_schedule)
            for i in range(1, billing_schedules.get(self.policy.billing_schedule)):
                months_after_eff_date = i*1 #Changing variable i to be multiplied by 1 so we have 12 monthly invoices
                bill_date = self.policy.effective_date + relativedelta(months=months_after_eff_date)
                invoice = Invoice(self.policy.id,
                                  bill_date,
                                  bill_date + relativedelta(months=1),
                                  bill_date + relativedelta(months=1, days=14),
                                  self.policy.annual_premium / billing_schedules.get(self.policy.billing_schedule))
                invoices.append(invoice)
        else:
            print "You have chosen a bad billing schedule." #If all the if and elif statements are False then print a bad billing schedule

        for invoice in invoices: #For every invoice add the invoice and commit to database
            db.session.add(invoice)
        db.session.commit()
コード例 #2
0
ファイル: tools.py プロジェクト: acq688/Project
    def make_invoices(self):
        for invoice in self.policy.invoices:
            invoice.delete()

        billing_schedules = {'Annual': None, 'Semi-Annual': 3, 'Quarterly': 4, 'Monthly': 12}

        invoices = []
        first_invoice = Invoice(self.policy.id,
                                self.policy.effective_date, #bill_date
                                self.policy.effective_date + relativedelta(months=1), #due
                                self.policy.effective_date + relativedelta(months=1, days=14), #cancel
                                self.policy.annual_premium)
        invoices.append(first_invoice)

        if self.policy.billing_schedule == "Annual":
            pass
        elif self.policy.billing_schedule == "Two-Pay":
            first_invoice.amount_due = first_invoice.amount_due / billing_schedules.get(self.policy.billing_schedule)
            for i in range(1, billing_schedules.get(self.policy.billing_schedule)):
                months_after_eff_date = i*6
                bill_date = self.policy.effective_date + relativedelta(months=months_after_eff_date)
                invoice = Invoice(self.policy.id,
                                  bill_date,
                                  bill_date + relativedelta(months=1),
                                  bill_date + relativedelta(months=1, days=14),
                                  self.policy.annual_premium / billing_schedules.get(self.policy.billing_schedule))
                invoices.append(invoice)
        elif self.policy.billing_schedule == "Quarterly":
            first_invoice.amount_due = first_invoice.amount_due / billing_schedules.get(self.policy.billing_schedule)
            for i in range(1, billing_schedules.get(self.policy.billing_schedule)):
                months_after_eff_date = i*3
                bill_date = self.policy.effective_date + relativedelta(months=months_after_eff_date)
                invoice = Invoice(self.policy.id,
                                  bill_date,
                                  bill_date + relativedelta(months=1),
                                  bill_date + relativedelta(months=1, days=14),
                                  self.policy.annual_premium / billing_schedules.get(self.policy.billing_schedule))
                invoices.append(invoice)
        elif self.policy.billing_schedule == "Monthly":
            pass
        else:
            print "You have chosen a bad billing schedule."

        for invoice in invoices:
            db.session.add(invoice)
        db.session.commit()
コード例 #3
0
    def make_invoices(self):
        """
        Creates invoices depending on policy's billing_schedule.
        """

        billing_schedules = {
            "Annual": 1,
            "Two-Pay": 2,
            "Quarterly": 4,
            "Monthly": 12
        }
        months_after_eff_date_dict = {
            "Annual": 12,
            "Two-Pay": 6,
            "Quarterly": 3,
            "Monthly": 1,
        }

        invoices = []
        first_invoice = Invoice(
            self.policy.id,
            self.policy.effective_date,  # bill_date
            self.policy.effective_date + relativedelta(months=1),  # due
            self.policy.effective_date +
            relativedelta(months=1, days=14),  # cancel
            self.policy.annual_premium,
        )
        invoices.append(first_invoice)

        if self.policy.billing_schedule in billing_schedules:
            invoices_quantity = billing_schedules.get(
                self.policy.billing_schedule)
            first_invoice.amount_due = first_invoice.amount_due / invoices_quantity
            months_between_invoices = months_after_eff_date_dict.get(
                self.policy.billing_schedule)
            for i in range(1, invoices_quantity):
                a = i * months_between_invoices
                bill_date = self.policy.effective_date + relativedelta(
                    months=a)
                invoice = Invoice(
                    self.policy.id,
                    bill_date,
                    bill_date + relativedelta(months=1),
                    bill_date + relativedelta(months=1, days=14),
                    self.policy.annual_premium /
                    billing_schedules.get(self.policy.billing_schedule),
                )
                invoices.append(invoice)
        else:
            print "You have chosen a bad billing schedule."

        for invoice in invoices:
            db.session.add(invoice)
        db.session.commit()
コード例 #4
0
def generate_monthly_invoices(policy_id):
    # query the database to get the policy with the id
    policy = Policy.query.filter_by(id=policy_id).one()

    # check if the policy has an initial invoice generated by PolicyAccounting
    if policy.invoices:

        # check if the policy is a Policy Three plan
        if policy.policy_number == "Policy Three":
            # delete any pre-generated invoice for the policy
            for invoice in policy.invoices:
                db.session.delete(invoice)

            # set the billing schedule to 12 i.e monthly
            billing_schedule = 12
            # create an empty list to store all invoices generated for the policy
            invoices = []
            # create an instance of invoice
            first_invoice = Invoice(
                policy.id,
                policy.effective_date,  # bill_date
                policy.effective_date + relativedelta(months=1),  # due
                policy.effective_date +
                relativedelta(months=1, days=14),  # cancel
                policy.annual_premium)

            invoices.append(first_invoice)

            first_invoice.amount_due = first_invoice.amount_due / billing_schedule
            for i in range(1, billing_schedule):
                months_after_eff_date = i * 1
                bill_date = policy.effective_date + relativedelta(
                    months=months_after_eff_date)
                # create an instance of invoice
                invoice = Invoice(policy.id, bill_date,
                                  bill_date + relativedelta(months=1),
                                  bill_date + relativedelta(months=1, days=14),
                                  policy.annual_premium / billing_schedule)
                # add the generated invoice to invoice list
                invoices.append(invoice)

            # save all the generated invoices to the database
            for invoice in invoices:
                db.session.add(invoice)
            db.session.commit()
            print "Invoices generated for Policy Three (Monthly Schedule)"
        else:
            print(
                "This not a Policy Three. Get the appropriate representation of Policy Three"
            )
    else:
        print("Policy not found")
コード例 #5
0
ファイル: utils.py プロジェクト: jxxi/OpsEngineerProject
    def make_invoices(self):
        billing_schedules = {
            'Annual': 1,
            'Two-Pay': 2,
            'Quarterly': 4,
            'Monthly': 12
        }

        invoices = []

        # Create an Invoice.
        first_invoice = Invoice(
            self.policy.id,
            self.policy.effective_date,  # bill_date
            self.policy.effective_date + relativedelta(months=1),  # due date
            self.policy.effective_date +
            relativedelta(months=1, days=14),  # cancellation date
            self.policy.annual_premium)

        # Add invoice to array.
        invoices.append(first_invoice)

        # Get number of payments from billing_schedules
        num_of_payments = billing_schedules.get(
            self.policy.billing_schedule) or None

        if not num_of_payments:
            print "You have chosen a bad billing schedule."

        # Calculate first invoice amount due by dividing total by number of payments
        first_invoice.amount_due = first_invoice.amount_due / num_of_payments

        for i in range(1, num_of_payments):
            # Calculate months after effective date
            months_after_eff_date = i * (12 / num_of_payments)

            # Add months to effective date to get bill date
            bill_date = self.policy.effective_date + relativedelta(
                months=months_after_eff_date)
            invoice = Invoice(
                self.policy.id, bill_date, bill_date + relativedelta(months=1),
                bill_date + relativedelta(months=1, days=14),
                self.policy.annual_premium /
                billing_schedules.get(self.policy.billing_schedule))
            invoices.append(invoice)

        # Add new invoices to db
        for invoice in invoices:
            db.session.add(invoice)
        db.session.commit()
コード例 #6
0
    def make_invoices(self):
        for invoice in self.policy.invoices:
            invoice.deleted = True

        billing_schedules = {
            'Annual': None,
            'Two-Pay': 2,
            'Quarterly': 4,
            'Monthly': 12
        }

        invoices = []
        first_invoice = Invoice(
            self.policy.id,
            self.policy.effective_date,  # bill_date
            self.policy.effective_date + relativedelta(months=1),  # due
            self.policy.effective_date +
            relativedelta(months=1, days=14),  # cancel
            self.policy.annual_premium)
        invoices.append(first_invoice)

        schedule = self.policy.billing_schedule
        if schedule == "Annual":
            pass
        elif schedule in billing_schedules:
            num_payments = billing_schedules.get(schedule)
            # desire full-dollar bill amounts, but not always divisible, so add remainder to first installment
            first_invoice.amount_due = first_invoice.amount_due / num_payments + first_invoice.amount_due % num_payments

            for i in range(1, billing_schedules.get(schedule)):
                months_after_eff_date = i * 12 / num_payments
                bill_date = self.policy.effective_date + relativedelta(
                    months=months_after_eff_date)

                invoice = Invoice(
                    self.policy.id, bill_date,
                    bill_date + relativedelta(months=1),
                    bill_date + relativedelta(months=1, days=14),
                    self.policy.annual_premium /
                    billing_schedules.get(schedule))
                invoices.append(invoice)
        else:
            print "You have chosen a bad billing schedule."

        for invoice in invoices:
            db.session.add(invoice)
        db.session.commit()
コード例 #7
0
    def make_invoices(self):
        for invoice in self.policy.invoices:
            invoice.deleted = True

        billing_schedules = {'Annual': None, 'Two-Pay': 2, 'Quarterly': 4, 'Monthly': 12}

        invoices = []
        first_invoice = Invoice(self.policy.id,
                                self.policy.effective_date,  # bill_date
                                self.policy.effective_date + relativedelta(months=1),  # due
                                self.policy.effective_date + relativedelta(months=1, days=14),  # cancel
                                self.policy.annual_premium)
        invoices.append(first_invoice)

        schedule = self.policy.billing_schedule
        if schedule == "Annual":
            pass
        elif schedule in billing_schedules:
            num_payments = billing_schedules.get(schedule)
            # desire full-dollar bill amounts, but not always divisible, so add remainder to first installment
            first_invoice.amount_due = first_invoice.amount_due / num_payments + first_invoice.amount_due % num_payments

            for i in range(1, billing_schedules.get(schedule)):
                months_after_eff_date = i*12/num_payments
                bill_date = self.policy.effective_date + relativedelta(months=months_after_eff_date)

                invoice = Invoice(self.policy.id,
                                  bill_date,
                                  bill_date + relativedelta(months=1),
                                  bill_date + relativedelta(months=1, days=14),
                                  self.policy.annual_premium / billing_schedules.get(schedule))
                invoices.append(invoice)
        else:
            print "You have chosen a bad billing schedule."

        for invoice in invoices:
            db.session.add(invoice)
        db.session.commit()
コード例 #8
0
ファイル: tools.py プロジェクト: donnell74/InternProject
    def make_invoices(self, end_date_cursor = None):
        """Produces next year's worth of invoices."""
        invoices = []
        if not end_date_cursor:
            if self.policy:
                end_date_cursor = self.policy.effective_date + relativedelta(days=365)
            else:
                end_date_cursor = datetime.now().date + relativedelta(days=365)

        for invoice in self.policy.invoices:
            if not invoice.deleted:
                db.session.delete(invoice)
            else:
                invoices.append(invoice)
        
        logger.log("New invoices are being made, invoices for this policy will be have a different invoice_id",
                   "Info",
                   self.policy.id);

        billing_schedules = {'Annual': None, 'Two-Pay': 2, 'Semi-Annual': 3, 'Quarterly': 4, 'Monthly': 12}
        billing_to_months = {'Annual': 12, 'Two-Pay': 6, 'Quarterly': 3, 'Monthly': 1}

        # create the first invoice
        first_invoice = Invoice(self.policy.id,
                                self.policy.effective_date, #bill_date
                                self.policy.effective_date + relativedelta(months=1), #due
                                self.policy.effective_date + relativedelta(months=1, days=14), #cancel
                                self.policy.annual_premium)
        invoices.append(first_invoice)

        # find the months in the billing period
        if billing_to_months.has_key(self.policy.billing_schedule):
            months_in_billing_period = billing_to_months.get(self.policy.billing_schedule)
        else:
            logger.log("Client tried using %s billing schedule" % (self.policy.billing_schedule), 
                       "Info",
                       self.policy.id)
            print "You have chosen a bad billing schedule."

        del billing_schedules["Annual"] # leave out annual from here to simplify
        if self.policy.billing_schedule in billing_schedules.keys(): 
            # find amount of months between end_date_cursor and self.policy.effective_date
            months_left = (end_date_cursor - self.policy.effective_date).days / 30

            invoices_needed = int(months_left / billing_to_months.get(self.policy.billing_schedule))
            first_invoice.amount_due = first_invoice.amount_due / invoices_needed
            
            # create the correct amount of invoices based on variables above
            for i in range(1, invoices_needed):
                months_after_eff_date = i * months_in_billing_period
                bill_date = self.policy.effective_date + relativedelta(months=months_after_eff_date)
                invoice = Invoice(self.policy.id,
                                  bill_date,
                                  bill_date + relativedelta(months=1),
                                  bill_date + relativedelta(months=1, days=14),
                                  self.policy.annual_premium / invoices_needed)
                invoices.append(invoice)

        for invoice in invoices:
            db.session.add(invoice)

        db.session.commit()
        self.policy.invoices = invoices
コード例 #9
0
    def change_billing_schedule(self, billing_schedule='Annual'):
        invoices_paid = 0 # Paid invoices tracker variable
        new_amount_due = 0 # Calculate the new amount due based on invoices that haven't been paid yet
        old_billing_date = None # Old billing date will determine how the payments are divided up

        invoices = Invoice.query.filter_by(policy_id=self.policy.id).all() # Grab all invoices for the policy

        for invoice in invoices: # For each invoice...
            if invoice.amount_due == 0: # If it has been paid...
                invoices_paid += 1 # Increment our paid invoices tracker variable
            else: # Otherwise...
                invoice.deleted = True # Mark the invoice as deleted...
                new_amount_due += invoice.amount_due # And add the invoice amount due to our new amount due
        
        print "Invoices paid:", invoices_paid
        print "New amount due:", new_amount_due
        
        for invoice in invoices: # Get the oldest billing date to determine how the new payments will be divided up
            if invoice.deleted: # If the invoice has been marked as deleted...
                old_billing_date = invoice.bill_date # Set the old billing date to the oldest deleted invoice
                break # Break out of the for loop as we want the oldest date and nothing more
        
        invoices = [] # Clear invoices as we don't need the old ones anymore
        print "Old billing date:", old_billing_date

        next_effective_date = self.policy.effective_date + relativedelta(years=1) # Get next year's effective date
        print "Next effective date:", next_effective_date, "\n"

        months_in_between = relativedelta(next_effective_date, old_billing_date).months # Get the months in-between the two dates

        # return months_in_between # This was my temporary return value for testing

        first_invoice = Invoice(self.policy.id, # Create an invoice based on the policy
                                old_billing_date, # bill_date
                                old_billing_date + relativedelta(months=1), # due_date
                                old_billing_date + relativedelta(months=1, days=14), # cancel_date
                                self.policy.annual_premium)

        if billing_schedule != 'Annual': # If the billing schedule isn't Annual, append the invoice.
            invoices.append(first_invoice) # Otherwise if it is, we want to check something first.

        if billing_schedule == 'Annual': # If it is Annual, and the new amount due isn't equal to 0, we need to subtract that from
            if new_amount_due != 0: # the first_invoice amount_due BEFORE we append it to the array
                first_invoice.amount_due -= new_amount_due
                invoices.append(first_invoice)
        elif billing_schedule == 'Two-Pay':
            billing_cycle = int(round(invoices_paid / 2.0)) # Get period between due dates
            print "Billing Cycle in months:", billing_cycle
            amount_due = new_amount_due / 2 # Divide based on billing_schedule
            print "Billing Cycle amount due:", amount_due

            # Set the invoice amount equal to itself divided by the billing schedule
            first_invoice.amount_due = amount_due

            for i in range(1, 2): # For each bill in the billing schedule...
                # Based on the billing schedule, get the next time the customer has to pay and set that as the billing date. 
                months_after_eff_date = i*billing_cycle
                # print "Months after effective date:", months_after_eff_date # Debugging purposes

                bill_date = old_billing_date + relativedelta(months=months_after_eff_date)
                # print "Bill Date:", bill_date # 

                invoice = Invoice(self.policy.id,
                                  bill_date,
                                  bill_date + relativedelta(months=1),
                                  bill_date + relativedelta(months=1, days=14),
                                  amount_due)

                invoices.append(invoice)
        elif billing_schedule == 'Quarterly':
            billing_cycle = int(round(months_in_between / 4.0))
            print "Billing Cycle in months:", billing_cycle
            amount_due = new_amount_due / 4
            print "Billing Cycle amount due:", amount_due, "\n"

            first_invoice.amount_due = amount_due

            for i in range(1, 4): 
                months_after_eff_date = i*billing_cycle
                # print "Months after effective date:", months_after_eff_date

                bill_date = old_billing_date + relativedelta(months=months_after_eff_date)
                # print "Bill Date:", bill_date

                invoice = Invoice(self.policy.id,
                                  bill_date,
                                  bill_date + relativedelta(months=1),
                                  bill_date + relativedelta(months=1, days=14),
                                  amount_due)

                invoices.append(invoice)
        elif billing_schedule == 'Monthly':
            amount_due = new_amount_due / months_in_between
            print "Billing Cycle amount due:", amount_due
        
            first_invoice.amount_due = amount_due

            for i in range(1, months_in_between): 
                months_after_eff_date = i
                # print "Months after effective date:", months_after_eff_date

                bill_date = old_billing_date + relativedelta(months=months_after_eff_date)
                # print "Bill Date:", bill_date

                invoice = Invoice(self.policy.id,
                                  bill_date,
                                  bill_date + relativedelta(months=1),
                                  bill_date + relativedelta(months=1, days=14),
                                  amount_due)

                invoices.append(invoice)
        else:
            print "You have chosen a bad billing schedule."

        print "\nInvoice Details below:"

        for invoice in invoices: # For every invoice created, add it to the database.
            db.session.add(invoice)
            print invoice.bill_date # Print information about each invoice to make sure dates and payments are correct
            print invoice.due_date
            print invoice.cancel_date
            print invoice.amount_due
            print "\n\n"
コード例 #10
0
ファイル: utils.py プロジェクト: gusreyes01/britecore
    def make_invoices(self, billing_schedule_change=False):
        """
        Create new invoices method,
        this function will be called when initializing
        a new PolicyAccounting instance.

        """

        for invoice in self.policy.invoices:
            if not billing_schedule_change:
                invoice.delete()

        billing_schedules = {
            'Annual': None,
            'Two-Pay': 2,
            'Quarterly': 4,
            'Monthly': 12
        }

        invoices = []
        first_invoice = Invoice(
            self.policy.id,
            self.policy.effective_date,  # bill_date
            self.policy.effective_date + relativedelta(months=1),  # due
            self.policy.effective_date +
            relativedelta(months=1, days=14),  # cancel
            self.policy.annual_premium)
        invoices.append(first_invoice)

        if self.policy.billing_schedule == "Annual":
            pass
        elif self.policy.billing_schedule == "Two-Pay":
            first_invoice.amount_due = first_invoice.amount_due / billing_schedules.get(
                self.policy.billing_schedule)
            for i in range(1,
                           billing_schedules.get(
                               self.policy.billing_schedule)):
                months_after_eff_date = i * 6
                bill_date = self.policy.effective_date + relativedelta(
                    months=months_after_eff_date)
                invoice = Invoice(
                    self.policy.id, bill_date,
                    bill_date + relativedelta(months=1),
                    bill_date + relativedelta(months=1, days=14),
                    self.policy.annual_premium /
                    billing_schedules.get(self.policy.billing_schedule))
                invoices.append(invoice)
        elif self.policy.billing_schedule == "Quarterly":
            first_invoice.amount_due = first_invoice.amount_due / billing_schedules.get(
                self.policy.billing_schedule)
            for i in range(1,
                           billing_schedules.get(
                               self.policy.billing_schedule)):
                months_after_eff_date = i * 3
                bill_date = self.policy.effective_date + relativedelta(
                    months=months_after_eff_date)
                invoice = Invoice(
                    self.policy.id, bill_date,
                    bill_date + relativedelta(months=1),
                    bill_date + relativedelta(months=1, days=14),
                    self.policy.annual_premium /
                    billing_schedules.get(self.policy.billing_schedule))
                invoices.append(invoice)
        elif self.policy.billing_schedule == "Monthly":
            first_invoice.amount_due = first_invoice.amount_due / billing_schedules.get(
                self.policy.billing_schedule)
            for i in range(1,
                           billing_schedules.get(
                               self.policy.billing_schedule)):
                months_after_eff_date = i * 1
                bill_date = self.policy.effective_date + relativedelta(
                    months=months_after_eff_date)
                invoice = Invoice(
                    self.policy.id, bill_date,
                    bill_date + relativedelta(months=1),
                    bill_date + relativedelta(months=1, days=14),
                    self.policy.annual_premium /
                    billing_schedules.get(self.policy.billing_schedule))
                invoices.append(invoice)
        else:
            print
            "You have chosen a bad billing schedule."

        for invoice in invoices:
            db.session.add(invoice)
        db.session.commit()
コード例 #11
0
    def make_invoices(self):
        """
        Deleting the policy invoices
        """
        for invoice in self.policy.invoices:
            if invoice.deleted == False:
                invoice.delete()
        #Creating a dictionary for the billing_schedules
        billing_schedules = {
            'Annual': None,
            'Semi-Annual': 3,
            'Quarterly': 4,
            'Monthly': 12,
            'Two-Pay': 2
        }
        """
        Creating the Policy's Invoice with it's effective dates
        """
        invoices = []
        first_invoice = Invoice(
            self.policy.id,
            self.policy.effective_date,  #bill_date
            self.policy.effective_date + relativedelta(months=1),  #due
            self.policy.effective_date +
            relativedelta(months=1, days=14),  #cancel
            self.policy.annual_premium)
        invoices.append(first_invoice)
        """
        Creating the remaining invoices for the different types of billing_schedule
        """

        if not billing_schedules.has_key(self.policy.billing_schedule):
            """
            Wrong schedule, No invoice will be created for it
            """
            print "You have chosen a bad billing schedule."
            return

        if self.policy.billing_schedule == "Annual":
            pass
        else:
            first_invoice.amount_due = first_invoice.amount_due / billing_schedules.get(
                self.policy.billing_schedule)
            for i in range(1,
                           billing_schedules.get(
                               self.policy.billing_schedule)):
                if self.policy.billing_schedule == "Two-Pay":
                    months_after_eff_date = i * 6
                elif self.policy.billing_schedule == "Quarterly":
                    months_after_eff_date = i * 3
                elif self.policy.billing_schedule == "Monthly":
                    months_after_eff_date = i
                bill_date = self.policy.effective_date + relativedelta(
                    months=months_after_eff_date)
                invoice = Invoice(
                    self.policy.id, bill_date,
                    bill_date + relativedelta(months=1),
                    bill_date + relativedelta(months=1, days=14),
                    self.policy.annual_premium /
                    billing_schedules.get(self.policy.billing_schedule))
                invoices.append(invoice)
        """
        Looping throught the Invoices and persisting each one
        """
        for invoice in invoices:
            db.session.add(invoice)
        db.session.commit()
コード例 #12
0
ファイル: utils.py プロジェクト: tersal/Accounting
    def make_invoices(self):
        """Create invoices for this policy.

        This function creates invoices for this policy according to the billing schedule and the total annual
        premium of the policy.

        The total annual premium of the policy is divided equally between the different the periods created
        according to the billing schedule.

        If there are invoices already created for this policy, the old invoices will be marked as deleted
        and not be accounted for any other operation on this policy, new invoices will be generated.

        The invoices are stored in the database and are related to the policy through the policy id.
        """

        if self.policy.status == "Canceled":
            print "Unable to create invoices since the policy is canceled"
            return

        invoices = []

        # If there are pending invoices, they will be marked as "deleted" since we assume that the user
        # made changes to the policy and rendered the previous invoices invalid.
        for invoice in self.policy.invoices:
            print "Deleting current invoices of this policy prior to the creation of new ones."
            invoice.deleted = True
            invoices.append(invoice)

        billing_schedules = {
            'Annual': None,
            'Two-Pay': 2,
            'Quarterly': 4,
            'Monthly': 12
        }

        # Create the first invoice based on the effective date.
        first_invoice = Invoice(
            self.policy.id,
            self.policy.effective_date,  #bill_date
            self.policy.effective_date + relativedelta(months=1),  #due
            self.policy.effective_date +
            relativedelta(months=1, days=14),  #cancel
            self.policy.annual_premium)
        invoices.append(first_invoice)

        if self.policy.billing_schedule == "Annual":
            # Since only one invoice is needed for this billing schedule and was already created previously,
            # nothing else is needed.
            pass
        elif self.policy.billing_schedule == "Two-Pay":
            first_invoice.amount_due = first_invoice.amount_due / billing_schedules.get(
                self.policy.billing_schedule)
            for i in range(1,
                           billing_schedules.get(
                               self.policy.billing_schedule)):
                # In a Two-Pay schedule only one invoices is needed after 6 months of the initial invoice.
                months_after_eff_date = i * 6
                bill_date = self.policy.effective_date + relativedelta(
                    months=months_after_eff_date)
                invoice = Invoice(
                    self.policy.id, bill_date,
                    bill_date + relativedelta(months=1),
                    bill_date + relativedelta(months=1, days=14),
                    self.policy.annual_premium /
                    billing_schedules.get(self.policy.billing_schedule))
                invoices.append(invoice)
        elif self.policy.billing_schedule == "Quarterly":
            first_invoice.amount_due = first_invoice.amount_due / billing_schedules.get(
                self.policy.billing_schedule)
            for i in range(1,
                           billing_schedules.get(
                               self.policy.billing_schedule)):
                # For the Quarterly schedule, an invoice is created for every three months period
                months_after_eff_date = i * 3
                bill_date = self.policy.effective_date + relativedelta(
                    months=months_after_eff_date)
                invoice = Invoice(
                    self.policy.id, bill_date,
                    bill_date + relativedelta(months=1),
                    bill_date + relativedelta(months=1, days=14),
                    self.policy.annual_premium /
                    billing_schedules.get(self.policy.billing_schedule))
                invoices.append(invoice)
        elif self.policy.billing_schedule == "Monthly":
            first_invoice.amount_due = first_invoice.amount_due / billing_schedules.get(
                self.policy.billing_schedule)
            for i in range(1,
                           billing_schedules.get(
                               self.policy.billing_schedule)):
                # In a monthly schedule, twelve invoices should be created.
                months_after_eff_date = i
                bill_date = self.policy.effective_date + relativedelta(
                    months=months_after_eff_date)
                invoice = Invoice(
                    self.policy.id, bill_date,
                    bill_date + relativedelta(months=1),
                    bill_date + relativedelta(months=1, days=14),
                    self.policy.annual_premium /
                    billing_schedules.get(self.policy.billing_schedule))
                invoices.append(invoice)
        else:
            print "You have chosen a bad billing schedule."

        for invoice in invoices:
            db.session.add(invoice)
        db.session.commit()
コード例 #13
0
    def make_invoices_remainder(self, date_cursor=None, amount=0):
        if not date_cursor:
            date_cursor = datetime.now().date()
        from dateutil import rrule
        from datetime import date

        month_list = list(
            rrule.rrule(rrule.MONTHLY,
                        dtstart=date_cursor,
                        until=date(date_cursor.year, 12, 31)))

        invoices = []
        first_invoice = Invoice(
            self.policy.id,
            date_cursor,  # bill_date
            date_cursor + relativedelta(months=1),  # due_date
            date_cursor + relativedelta(months=1, days=14),  # cancel_date
            amount)
        invoices.append(first_invoice)

        if self.policy.billing_schedule == "Annual":
            first_invoice.amount_due = amount
        elif self.policy.billing_schedule == "Two-Pay":
            first_invoice.amount_due = amount
        elif self.policy.billing_schedule == "Quarterly":
            quarters_left = 0
            months_in_quarter = 0

            if len(month_list) == 12:
                quarters_left = 4
                months_in_quarter = 3
            elif len(month_list) >= 10:
                quarters_left = 3
                months_in_quarter = len(month_list) / quarters_left
            elif len(month_list) >= 7:
                quarters_left = 2
                months_in_quarter = len(month_list) / quarters_left
            else:
                quarters_left = 1
                months_in_quarter = 1

            first_invoice.amount_due = first_invoice.amount_due / quarters_left
            for i in range(1, len(month_list)):
                months_after_eff_date = i * months_in_quarter
                bill_date = date_cursor + relativedelta(
                    months=months_after_eff_date)
                invoice = Invoice(self.policy.id, bill_date,
                                  bill_date + relativedelta(months=1),
                                  bill_date + relativedelta(months=1, days=14),
                                  amount / len(month_list))
                invoices.append(invoice)
        elif self.policy.billing_schedule == "Monthly":
            first_invoice.amount_due = first_invoice.amount_due / len(
                month_list)
            for i in range(1, len(month_list)):
                months_after_eff_date = i * 1
                bill_date = date_cursor + relativedelta(
                    months=months_after_eff_date)
                invoice = Invoice(self.policy.id, bill_date,
                                  bill_date + relativedelta(months=1),
                                  bill_date + relativedelta(months=1, days=14),
                                  amount / len(month_list))
                invoices.append(invoice)
        else:
            print "You have chosen a bad billing schedule."

        for invoice in invoices:
            db.session.add(invoice)
        db.session.commit()
コード例 #14
0
ファイル: utils.py プロジェクト: rafabispo93/BriteCodeTest
    def make_invoices(self):
        for invoice in self.policy.invoices:
            invoice.deleted = 1

        # Set the types of billing schedules that can be created
        billing_schedules = {
            'Annual': None,
            'Semi-Annual': 3,
            'Quarterly': 4,
            'Monthly': 12
        }

        invoices = []

        logging.info('making first invoice')
        # Creates the first invoice  that corresponds to the date of the policy's effectivation
        first_invoice = Invoice(
            self.policy.id,
            self.policy.effective_date,  #bill_date
            self.policy.effective_date + relativedelta(months=1),  #due
            self.policy.effective_date +
            relativedelta(months=1, days=14),  #cancel
            self.policy.annual_premium)
        invoices.append(first_invoice)

        # The annual billing schedule just have 1 invoice, the first invoice.
        if self.policy.billing_schedule == "Annual":
            logging.info('making annual invoice')
            pass
        # The two-pay billing schedule creates 2 invoices, the first invoice and the second 6 months ahead
        elif self.policy.billing_schedule == "Two-Pay":

            logging.info('making Two-Pay invoices')
            first_invoice.amount_due = first_invoice.amount_due / billing_schedules.get(
                self.policy.billing_schedule)
            for i in range(1,
                           billing_schedules.get(
                               self.policy.billing_schedule)):
                months_after_eff_date = i * 6
                bill_date = self.policy.effective_date + relativedelta(
                    months=months_after_eff_date)
                invoice = Invoice(
                    self.policy.id, bill_date,
                    bill_date + relativedelta(months=1),
                    bill_date + relativedelta(months=1, days=14),
                    self.policy.annual_premium /
                    billing_schedules.get(self.policy.billing_schedule))
                invoices.append(invoice)
        # The Quarterly billing schedule creates 4 invoices, the first invoice and 3 more separating every invoice by 3 months
        elif self.policy.billing_schedule == "Quarterly":

            logging.info('making Quarterly invoices')
            first_invoice.amount_due = first_invoice.amount_due / billing_schedules.get(
                self.policy.billing_schedule)
            for i in range(1,
                           billing_schedules.get(
                               self.policy.billing_schedule)):
                months_after_eff_date = i * 3
                bill_date = self.policy.effective_date + relativedelta(
                    months=months_after_eff_date)
                invoice = Invoice(
                    self.policy.id, bill_date,
                    bill_date + relativedelta(months=1),
                    bill_date + relativedelta(months=1, days=14),
                    self.policy.annual_premium /
                    billing_schedules.get(self.policy.billing_schedule))
                invoices.append(invoice)
        # The Monthly billing schedule creates 12 invoices, the first invoice and 11. One invoice per month.
        elif self.policy.billing_schedule == "Monthly":

            logging.info('making Monthly invoices')
            first_invoice.amount_due = first_invoice.amount_due / billing_schedules.get(
                self.policy.billing_schedule)

            for i in range(1,
                           billing_schedules.get(
                               self.policy.billing_schedule)):

                months_after_eff_date = i

                bill_date = self.policy.effective_date + relativedelta(
                    months=months_after_eff_date)
                invoice = Invoice(
                    self.policy.id, bill_date,
                    bill_date + relativedelta(months=1),
                    bill_date + relativedelta(months=1, days=14),
                    self.policy.annual_premium /
                    billing_schedules.get(self.policy.billing_schedule))

                invoices.append(invoice)
        else:
            logging.warning('You have chosen a bad billing schedule.')
            print "You have chosen a bad billing schedule."

        for invoice in invoices:
            db.session.add(invoice)
        db.session.commit()
コード例 #15
0
    def make_invoices(self):
        """
        Create invoices for the policy's Billing Schedule.
        Everytime this method is called, any existing invoices
        on this policy will be deleted.
        """

        for invoice in self.policy.invoices:
            invoice.deleted = True
            # invoice.delete()

        billing_schedules = {
            'Annual': None,
            'Semi-Annual': 3,
            'Quarterly': 4,
            'Monthly': 12
        }

        invoices = []
        # Create the initial invoice
        first_invoice = Invoice(
            self.policy.id,
            self.policy.effective_date,  #bill_date
            self.policy.effective_date + relativedelta(months=1),  #due
            self.policy.effective_date +
            relativedelta(months=1, days=14),  #cancel
            self.policy.annual_premium)
        invoices.append(first_invoice)

        # Since the billing schedule is annual, only the first invoice is required
        if self.policy.billing_schedule == "Annual":
            pass
        # Create invoices for semi-annual billing schedules
        elif self.policy.billing_schedule == "Two-Pay":
            first_invoice.amount_due = first_invoice.amount_due / billing_schedules.get(
                self.policy.billing_schedule)
            for i in range(1,
                           billing_schedules.get(
                               self.policy.billing_schedule)):
                months_after_eff_date = i * 6
                bill_date = self.policy.effective_date + relativedelta(
                    months=months_after_eff_date)
                invoice = Invoice(
                    self.policy.id,
                    bill_date,  # bill date
                    bill_date + relativedelta(months=1),  # due date
                    bill_date +
                    relativedelta(months=1, days=14),  # cancel date
                    self.policy.annual_premium / billing_schedules.get(
                        self.policy.billing_schedule))  # amount due
                invoices.append(invoice)
        # Create invoices for quarterly billing schedules
        elif self.policy.billing_schedule == "Quarterly":
            first_invoice.amount_due = first_invoice.amount_due / billing_schedules.get(
                self.policy.billing_schedule)
            for i in range(1,
                           billing_schedules.get(
                               self.policy.billing_schedule)):
                months_after_eff_date = i * 3
                bill_date = self.policy.effective_date + relativedelta(
                    months=months_after_eff_date)
                invoice = Invoice(
                    self.policy.id,
                    bill_date,  # bill date
                    bill_date + relativedelta(months=1),  # due date
                    bill_date +
                    relativedelta(months=1, days=14),  # cancel date
                    self.policy.annual_premium / billing_schedules.get(
                        self.policy.billing_schedule))  # amount due
                invoices.append(invoice)
        # Create invoices for monthly billing schedules
        elif self.policy.billing_schedule == "Monthly":
            first_invoice.amount_due = first_invoice.amount_due / billing_schedules.get(
                self.policy.billing_schedule)
            for i in range(1,
                           billing_schedules.get(
                               self.policy.billing_schedule)):
                months_after_eff_date = i
                bill_date = self.policy.effective_date + relativedelta(
                    months=months_after_eff_date)
                invoice = Invoice(
                    self.policy.id,
                    bill_date,  # bill date
                    bill_date + relativedelta(months=1),  # due date
                    bill_date +
                    relativedelta(months=1, days=14),  # cancel date
                    self.policy.annual_premium / billing_schedules.get(
                        self.policy.billing_schedule))  # amount due
                invoices.append(invoice)
        else:
            print "You have chosen a bad billing schedule."

        # Commit invoices to the database
        for invoice in invoices:
            db.session.add(invoice)
        db.session.commit()
コード例 #16
0
ファイル: utils.py プロジェクト: jgpub/bcproject
    def make_invoices_helper(self):
        """
        Generates invoices for the PolicyAccount object's policy.  Note that all invoices
        are generated and stored in the database at once, rather than doing so period-by-period.

        This helper method embodies all the functionality needed for the
        "makde_invoices" method but leaves out the database commit.  This is done
        so that other methods can use this functionality in its own database transaction
        (see change_billing_schedule).
        """

        # Check that no non-deleted invoices exist right now
        for invoice in self.policy.invoices:
            if not invoice.deleted:
                raise RuntimeError("Attempted to make invoices when non-deleted"\
                    "already exist.")

        invoices = []

        # There is always at least one invoice, so we create that up front, assuming that it is for
        # a yearly billing schedule.  self.policy.amount_due is liable to change later in this function
        # if a different billing schedule is employed.
        first_invoice = Invoice(
            self.policy.id,
            self.policy.effective_date,  #bill_date
            self.policy.effective_date + relativedelta(months=1),  #due
            self.policy.effective_date +
            relativedelta(months=1, days=14),  #cancel
            self.policy.annual_premium)
        invoices.append(first_invoice)

        # if the policy employs an annual billing scedule, there are no more invoices to create
        if self.policy.billing_schedule == "Annual":
            pass
        elif self.policy.billing_schedule in [
                "Two-Pay", "Semi-Annual", "Quarterly", "Monthly"
        ]:
            # Calculate billing periodicity (number of months between billing cycles)
            # and billing frequency (how many times per year) depending on the policy's
            # billing schedule.
            billing_periodicity = self.billing_schedules.get(
                self.policy.billing_schedule)
            billing_frequency = 12 / billing_periodicity

            # Adjust the first invoice's amount due appropriately.
            first_invoice.amount_due = first_invoice.amount_due / billing_periodicity
            # For each remaining billing cycle...
            for i in range(1, billing_periodicity):
                # calculate date of invoice
                months_after_eff_date = i * billing_frequency
                bill_date = self.policy.effective_date + relativedelta(
                    months=months_after_eff_date)

                # create the invoice!
                invoice = Invoice(
                    self.policy.id, bill_date,
                    bill_date + relativedelta(months=1),
                    bill_date + relativedelta(months=1, days=14),
                    self.policy.annual_premium / billing_periodicity)
                invoices.append(invoice)
        else:
            print "You have chosen a bad billing schedule."

        return invoices
コード例 #17
0
ファイル: tools.py プロジェクト: dhebrink/InternProject
    def make_invoices(self):
        """
        Populates self.policy.invoices based on the selected billing schedule.
        Should have 1 if Annual, 2 if 2-Pay, 4 if quarterly, and 12 if Monthly.
        """
        # Clear what may currently be in the list of invoices to make sure there are no duplicates.
        for invoice in self.policy.invoices:
            invoice.delete()

        billing_schedules = {'Annual': None, 'Semi-Annual': 3, 'Quarterly': 4, 'Monthly': 12}

        invoices = []
        # First record to declare the overall premium of the policy
        first_invoice = Invoice(self.policy.id,
                                self.policy.effective_date, #bill_date
                                self.policy.effective_date + relativedelta(months=1), #due
                                self.policy.effective_date + relativedelta(months=1, days=14), #cancel
                                self.policy.annual_premium)
        invoices.append(first_invoice)

        # If billing schedule is Annual, no other invoices are needed
        if self.policy.billing_schedule == "Annual":
            pass
        elif self.policy.billing_schedule == "Two-Pay":
            # Put value in a variable to save hash table look-ups
            frequency = billing_schedules.get(self.policy.billing_schedule)
            # Alter first invoice's amount to reflect a 6-month payment
            first_invoice.amount_due = first_invoice.amount_due / frequency
            for i in range(1, frequency):
                # number of months to add to the invoices' bill_date
                months_after_eff_date = i*6	# multiply by 6 for Two-Pay
                bill_date = self.policy.effective_date + relativedelta(months=months_after_eff_date)
                invoice = Invoice(self.policy.id,
                                  bill_date,    # bill date
                                  bill_date + relativedelta(months=1),   # due date
                                  bill_date + relativedelta(months=1, days=14),   # cancel date
                                  self.policy.annual_premium / frequency)    # amount due
                invoices.append(invoice)
        elif self.policy.billing_schedule == "Quarterly":
            # Put value into variable to save hash table look-ups
            frequency = billing_schedules.get(self.policy.billing_schedule)
            # Alter first invoice's amount due to reflect a 3-month payment
            first_invoice.amount_due = first_invoice.amount_due / frequency
            for i in range(1, frequency):
                # number of months to add to invoices' bill_date
                months_after_eff_date = i*3	# multiply by 3 for Quarterly
                bill_date = self.policy.effective_date + relativedelta(months=months_after_eff_date)
                invoice = Invoice(self.policy.id,
                                  bill_date,   # bill date
                                  bill_date + relativedelta(months=1),   # due date
                                  bill_date + relativedelta(months=1, days=14),   # cancel date
                                  self.policy.annual_premium / frequency)   # amount due
                invoices.append(invoice)
        elif self.policy.billing_schedule == "Monthly":
            # put value into variable to save hash table look-ups
            frequency = billing_schedules.get(self.policy.billing_schedule)
            # Alter the first invoice's amount due to reflect a monthly payment
            first_invoice.amount_due = first_invoice.amount_due / frequency
            for i in range(1, frequency):
                months_after_eff_date = i	# no multiple here for Monthly. "frequency" should be 1
                bill_date = self.policy.effective_date + relativedelta(months=months_after_eff_date)
                invoice = Invoice(self.policy.id,
                                bill_date,   # bill date
                                bill_date + relativedelta(months=1),  # due date
                                bill_date + relativedelta(months=1, days=14),   # cancel date
                                self.policy.annual_premium / frequency)   # amount due
                invoices.append(invoice)
        else:
            print "You have chosen a bad billing schedule."

        for invoice in invoices:
            db.session.add(invoice)
        db.session.commit()
コード例 #18
0
    def make_invoices(self):
        """Create invoices for a policy.

        Uses an integer representing the number
        of payments for the billing schedule and
        makes invoices.

        Returns:
            Adds invoices to the data base and prints message
            if billing schedule is invalid.
        """
        for invoice in self.policy.invoices:
            invoice.delete = 0  # modify to allow 0 to be a deleted invoice

        billing_schedules = {
            'Annual': None,
            'Semi-Annual': 2,
            'Quarterly': 4,
            'Monthly': 12
        }

        invoices = []
        first_invoice = Invoice(self.policy.id,
                                self.policy.effective_date,  # bill_date
                                self.policy.effective_date + \
                                relativedelta(months=1),  # due
                                self.policy.effective_date + \
                                relativedelta(months=1, days=14),  # cancel
                                self.policy.annual_premium)
        invoices.append(first_invoice)

        if self.policy.billing_schedule == "Annual":
            pass
        elif self.policy.billing_schedule == "Two-Pay":
            first_invoice.amount_due = first_invoice.amount_due / \
                billing_schedules.get(self.policy.billing_schedule)
            for i in range(1,
                           billing_schedules.get(
                               self.policy.billing_schedule)):
                months_after_eff_date = i * 6
                bill_date = self.policy.effective_date + \
                    relativedelta(months=months_after_eff_date)
                invoice = Invoice(
                    self.policy.id, bill_date,
                    bill_date + relativedelta(months=1),
                    bill_date + relativedelta(months=1, days=14),
                    self.policy.annual_premium /
                    billing_schedules.get(self.policy.billing_schedule))
                invoices.append(invoice)
        elif self.policy.billing_schedule == "Quarterly":
            first_invoice.amount_due = first_invoice.amount_due / \
                billing_schedules.get(self.policy.billing_schedule)
            for i in range(1,
                           billing_schedules.get(
                               self.policy.billing_schedule)):
                months_after_eff_date = i * 3
                bill_date = self.policy.effective_date + \
                    relativedelta(months=months_after_eff_date)
                invoice = Invoice(
                    self.policy.id, bill_date,
                    bill_date + relativedelta(months=1),
                    bill_date + relativedelta(months=1, days=14),
                    self.policy.annual_premium /
                    billing_schedules.get(self.policy.billing_schedule))
                invoices.append(invoice)
        elif self.policy.billing_schedule == "Monthly":
            first_invoice.amount_due = first_invoice.amount_due / \
                billing_schedules.get(self.policy.billing_schedule)
            for i in range(1,
                           billing_schedules.get(
                               self.policy.billing_schedule)):
                months_after_eff_date = i * 1
                bill_date = self.policy.effective_date + \
                    relativedelta(months=months_after_eff_date)
                invoice = Invoice(
                    self.policy.id, bill_date,
                    bill_date + relativedelta(months=1),
                    bill_date + relativedelta(months=1, days=14),
                    self.policy.annual_premium /
                    billing_schedules.get(self.policy.billing_schedule))
                invoices.append(invoice)
        else:
            print "You have chosen a bad billing schedule."

        for invoice in invoices:
            db.session.add(invoice)
        db.session.commit()
コード例 #19
0
    def make_invoices(self):
        # delete all invoices attached to the policy
        for invoice in self.policy.invoices:
            invoice.delete()

        # dictionary for billing schedules
        billing_schedules = {
            'Annual': None,
            'Two-Pay': 2,
            'Semi-Annual': 3,
            'Quarterly': 4,
            'Monthly': 12
        }

        # create an empty list to store all invoices generated for the policy
        invoices = []
        # create a initial invoice that holds the total annual amount to paid on the policy
        first_invoice = Invoice(
            self.policy.id,
            self.policy.effective_date,  #bill_date
            self.policy.effective_date + relativedelta(months=1),  #due
            self.policy.effective_date +
            relativedelta(months=1, days=14),  #cancel
            self.policy.annual_premium)
        # add the initial invoice to invoice list
        invoices.append(first_invoice)

        if self.policy.billing_schedule == "Annual":
            """
            if the policy billing schedule is Annual don't generate any additional invoice(s) for the policy
            """
            pass
        elif self.policy.billing_schedule == "Two-Pay":
            """
            if the policy billing schedule is Two-Pay generate 2 invoices for the policy
            """
            # set the initial invoice amount to the total policy due amount divided by number of times to pay it
            first_invoice.amount_due = first_invoice.amount_due / billing_schedules.get(
                self.policy.billing_schedule)

            # generate individual invoice for the number of time to pay for the policy
            for i in range(1,
                           billing_schedules.get(
                               self.policy.billing_schedule)):
                # calculate the month for the next payment
                months_after_eff_date = i * 6
                # set the date fr the bill date
                bill_date = self.policy.effective_date + relativedelta(
                    months=months_after_eff_date)
                # create an instance of invoice
                invoice = Invoice(
                    self.policy.id,
                    bill_date,  # bill date
                    bill_date + relativedelta(months=1),  # due date
                    bill_date +
                    relativedelta(months=1, days=14),  # cancel date
                    self.policy.annual_premium /
                    billing_schedules.get(self.policy.billing_schedule))
                # add the generated invoice to invoice list
                invoices.append(invoice)
        elif self.policy.billing_schedule == "Quarterly":
            """
            if the policy billing schedule is Quarterly generate 4 invoices for the policy
            """
            # set the initial invoice amount to the total policy due amount divided by number of times to pay it
            first_invoice.amount_due = first_invoice.amount_due / billing_schedules.get(
                self.policy.billing_schedule)
            # generate individual invoice for the number of time to pay for the policy
            for i in range(1,
                           billing_schedules.get(
                               self.policy.billing_schedule)):
                # calculate the month for the next payment
                months_after_eff_date = i * 3
                # set the date fr the bill date
                bill_date = self.policy.effective_date + relativedelta(
                    months=months_after_eff_date)
                # create an instance of invoice
                invoice = Invoice(
                    self.policy.id,
                    bill_date,  # bill date
                    bill_date + relativedelta(months=1),  # due date
                    bill_date +
                    relativedelta(months=1, days=14),  # cancel date
                    self.policy.annual_premium /
                    billing_schedules.get(self.policy.billing_schedule))
                # add the generated invoice to invoice list
                invoices.append(invoice)

        elif self.policy.billing_schedule == "Monthly":
            """
            if the policy billing schedule is Monthly generate invoice for monthly payment yet
            """
            pass
        else:
            print "You have chosen a bad billing schedule."

        # save all the generated invoices to the database
        for invoice in invoices:
            db.session.add(invoice)
        db.session.commit()
コード例 #20
0
    def make_invoices(self):
        """
            Creates first invoice and every invoice aferwards; Dependent on which billing schedule is selected.
        """
        for invoice in self.policy.invoices:
            invoice.delete()

        billing_schedules = {
            'Annual': None,
            'Two-Pay': 2,
            'Quarterly': 4,
            'Monthly': 12
        }

        invoices = []
        first_invoice = Invoice(
            self.policy.id,
            self.policy.effective_date,  #bill_date
            self.policy.effective_date + relativedelta(months=1),  #due
            self.policy.effective_date +
            relativedelta(months=1, days=14),  #cancel
            self.policy.annual_premium)  #amount owed
        invoices.append(first_invoice)

        if self.policy.billing_schedule == "Annual":
            pass
        elif self.policy.billing_schedule == "Two-Pay":
            first_invoice.amount_due = first_invoice.amount_due / billing_schedules.get(
                self.policy.billing_schedule)
            for i in range(1,
                           billing_schedules.get(
                               self.policy.billing_schedule)):
                months_after_eff_date = i * 6
                bill_date = self.policy.effective_date + relativedelta(
                    months=months_after_eff_date)
                invoice = Invoice(
                    self.policy.id, bill_date,
                    bill_date + relativedelta(months=1),
                    bill_date + relativedelta(months=1, days=14),
                    self.policy.annual_premium /
                    billing_schedules.get(self.policy.billing_schedule))
                invoices.append(invoice)
        elif self.policy.billing_schedule == "Quarterly":
            first_invoice.amount_due = first_invoice.amount_due / billing_schedules.get(
                self.policy.billing_schedule)
            for i in range(1,
                           billing_schedules.get(
                               self.policy.billing_schedule)):
                months_after_eff_date = i * 3
                bill_date = self.policy.effective_date + relativedelta(
                    months=months_after_eff_date)
                invoice = Invoice(
                    self.policy.id, bill_date,
                    bill_date + relativedelta(months=1),
                    bill_date + relativedelta(months=1, days=14),
                    self.policy.annual_premium /
                    billing_schedules.get(self.policy.billing_schedule))
                invoices.append(invoice)
        elif self.policy.billing_schedule == "Monthly":  #problem 1.
            first_invoice.amount_due = first_invoice.amount_due / billing_schedules.get(
                self.policy.billing_schedule
            )  #sets first invoice amount_due = amount_due/billing_schedule
            #loop thru each invoice - 1
            for i in range(1,
                           billing_schedules.get(
                               self.policy.billing_schedule)):
                months_after_eff_date = i
                bill_date = self.policy.effective_date + relativedelta(
                    months=months_after_eff_date)
                invoice = Invoice(
                    self.policy.id,  #create new invoice object with new info.
                    bill_date,  #bill date
                    bill_date + relativedelta(months=1),  #due date
                    bill_date + relativedelta(months=1, days=14),  #cancel date
                    self.policy.annual_premium / billing_schedules.get(
                        self.policy.billing_schedule))  #amount left/due
                invoices.append(invoice)
        else:
            print "You have chosen a bad billing schedule."

        for invoice in invoices:
            db.session.add(invoice)
        db.session.commit()
コード例 #21
0
    def schedule_changing(self, new_billing_schedule):
        account_balance = self.return_account_balance()
        # dictionary for billing schedules
        billing_schedules = {
            'Annual': None,
            'Two-Pay': 2,
            'Semi-Annual': 3,
            'Quarterly': 4,
            'Monthly': 12
        }
        if new_billing_schedule in billing_schedules.keys():
            self.policy.billing_schedule = new_billing_schedule

            for invoice in self.policy.invoices:
                # get payment for this invoice
                payment = Payment.query.filter_by(policy_id=self.policy.id) \
                    .filter(Payment.transaction_date <= invoice.cancel_date,
                            Payment.transaction_date >= invoice.bill_date) \
                    .all()

                # set invoice to delete if no payment made yet for the transaction
                if not payment:
                    invoice.deleted = True

            # create an empty list to store all the new invoices generated for the policy
            invoices = []
            # create a initial invoice that holds the total annual amount to paid on the policy
            first_invoice = Invoice(
                self.policy.id,
                self.policy.effective_date,  # bill_date
                self.policy.effective_date + relativedelta(months=1),  # due
                self.policy.effective_date +
                relativedelta(months=1, days=14),  # cancel
                account_balance)
            # add the initial invoice to invoice list
            invoices.append(first_invoice)

            if self.policy.billing_schedule == "Annual":
                """
                if the policy billing schedule is Annual don't generate any additional invoice(s) for the policy
                """
                pass
            elif self.policy.billing_schedule == "Two-Pay":
                """
                if the policy billing schedule is Two-Pay generate 2 invoices for the policy
                """
                # set the initial invoice amount to the total policy due amount divided by number of times to pay it
                first_invoice.amount_due = first_invoice.amount_due / billing_schedules.get(
                    self.policy.billing_schedule)

                # generate individual invoice for the number of time to pay for the policy
                for i in range(
                        1,
                        billing_schedules.get(self.policy.billing_schedule)):
                    # calculate the month for the next payment
                    months_after_eff_date = i * 6
                    # set the date fr the bill date
                    bill_date = self.policy.effective_date + relativedelta(
                        months=months_after_eff_date)
                    # create an instance of invoice
                    invoice = Invoice(
                        self.policy.id,
                        bill_date,  # bill date
                        bill_date + relativedelta(months=1),  # due date
                        bill_date +
                        relativedelta(months=1, days=14),  # cancel date
                        account_balance /
                        billing_schedules.get(self.policy.billing_schedule))
                    # add the generated invoice to invoice list
                    invoices.append(invoice)
            elif self.policy.billing_schedule == "Quarterly":
                """
                if the policy billing schedule is Quarterly generate 4 invoices for the policy
                """
                # set the initial invoice amount to the total policy due amount divided by number of times to pay it
                first_invoice.amount_due = first_invoice.amount_due / billing_schedules.get(
                    self.policy.billing_schedule)
                # generate individual invoice for the number of time to pay for the policy
                for i in range(
                        1,
                        billing_schedules.get(self.policy.billing_schedule)):
                    # calculate the month for the next payment
                    months_after_eff_date = i * 3
                    # set the date fr the bill date
                    bill_date = self.policy.effective_date + relativedelta(
                        months=months_after_eff_date)
                    # create an instance of invoice
                    invoice = Invoice(
                        self.policy.id,
                        bill_date,  # bill date
                        bill_date + relativedelta(months=1),  # due date
                        bill_date +
                        relativedelta(months=1, days=14),  # cancel date
                        account_balance /
                        billing_schedules.get(self.policy.billing_schedule))
                    # add the generated invoice to invoice list
                    invoices.append(invoice)

            elif self.policy.billing_schedule == "Monthly":
                """
                if the policy billing schedule is Monthly generate invoices for monthly payment 
                """
                first_invoice.amount_due = first_invoice.amount_due / billing_schedules.get(
                    self.policy.billing_schedule)
                for i in range(
                        1,
                        billing_schedules.get(self.policy.billing_schedule)):
                    months_after_eff_date = i * 1
                    bill_date = self.policy.effective_date + relativedelta(
                        months=months_after_eff_date)
                    # create an instance of invoice
                    invoice = Invoice(
                        self.policy.id, bill_date,
                        bill_date + relativedelta(months=1),
                        bill_date + relativedelta(months=1, days=14),
                        account_balance /
                        billing_schedules.get(self.policy.billing_schedule))
                    # add the generated invoice to invoice list
                    invoices.append(invoice)

            # save all the generated invoices to the database
            for invoice in invoices:
                db.session.add(invoice)
            db.session.commit()
            print self.policy.policy_number, " billing schedule changed to ", self.policy.billing_schedule, \
                " successfully"
        else:
            print "Bad Billing Schedule Selected"
コード例 #22
0
    def make_invoices(self):
        for invoice in self.policy.invoices:
            invoice.delete()

        billing_schedules = {
            'Annual': None,
            'Semi-Annual': 3,
            'Quarterly': 4,
            'Monthly': 12
        }

        invoices = []
        first_invoice = Invoice(
            self.policy.id,
            self.policy.effective_date,  #bill_date
            self.policy.effective_date + relativedelta(months=1),  #due
            self.policy.effective_date +
            relativedelta(months=1, days=14),  #cancel
            self.policy.annual_premium)
        invoices.append(first_invoice)

        if self.policy.billing_schedule == "Annual":
            pass
        elif self.policy.billing_schedule == "Two-Pay":
            first_invoice.amount_due = first_invoice.amount_due / billing_schedules.get(
                self.policy.billing_schedule)
            for i in range(1,
                           billing_schedules.get(
                               self.policy.billing_schedule)):
                months_after_eff_date = i * 6
                bill_date = self.policy.effective_date + relativedelta(
                    months=months_after_eff_date)
                invoice = Invoice(
                    self.policy.id, bill_date,
                    bill_date + relativedelta(months=1),
                    bill_date + relativedelta(months=1, days=14),
                    self.policy.annual_premium /
                    billing_schedules.get(self.policy.billing_schedule))
                invoices.append(invoice)
        elif self.policy.billing_schedule == "Quarterly":
            first_invoice.amount_due = first_invoice.amount_due / billing_schedules.get(
                self.policy.billing_schedule)
            for i in range(1,
                           billing_schedules.get(
                               self.policy.billing_schedule)):
                months_after_eff_date = i * 3
                bill_date = self.policy.effective_date + relativedelta(
                    months=months_after_eff_date)
                invoice = Invoice(
                    self.policy.id, bill_date,
                    bill_date + relativedelta(months=1),
                    bill_date + relativedelta(months=1, days=14),
                    self.policy.annual_premium /
                    billing_schedules.get(self.policy.billing_schedule))
                invoices.append(invoice)
        elif self.policy.billing_schedule == "Monthly":
            pass
        else:
            print "You have chosen a bad billing schedule."

        for invoice in invoices:
            db.session.add(invoice)
        db.session.commit()
コード例 #23
0
    def make_invoices(self):
        billing_schedules = {'Annual': None, 'Two-Pay': 2, 'Quarterly': 4, 'Monthly': 12}

        invoices = []

        first_invoice = Invoice(self.policy.id, # Create an invoice based on the policy
                                self.policy.effective_date, # bill_date
                                self.policy.effective_date + relativedelta(months=1), # due_date
                                self.policy.effective_date + relativedelta(months=1, days=14), # cancel_date
                                self.policy.annual_premium)

        invoices.append(first_invoice) # Add first_invoice to the invoices[] array

        if self.policy.billing_schedule == "Annual":
            pass # An annual billing policy allows us to simply use the above first_invoice because the values don't change
        elif self.policy.billing_schedule == "Two-Pay":
            # Set the invoice amount equal to itself divided by the billing schedule
            first_invoice.amount_due = first_invoice.amount_due / billing_schedules.get(self.policy.billing_schedule)

            for i in range(1, billing_schedules.get(self.policy.billing_schedule)): # For each bill in the billing schedule...
                # Based on the billing schedule, get the next time the customer has to pay and set that as the billing date. 
                months_after_eff_date = i*6

                bill_date = self.policy.effective_date + relativedelta(months=months_after_eff_date)

                invoice = Invoice(self.policy.id,
                                  bill_date,
                                  bill_date + relativedelta(months=1),
                                  bill_date + relativedelta(months=1, days=14),
                                  self.policy.annual_premium / billing_schedules.get(self.policy.billing_schedule))

                invoices.append(invoice)
        elif self.policy.billing_schedule == "Quarterly":
            first_invoice.amount_due = first_invoice.amount_due / billing_schedules.get(self.policy.billing_schedule)

            for i in range(1, billing_schedules.get(self.policy.billing_schedule)):
                months_after_eff_date = i*3

                bill_date = self.policy.effective_date + relativedelta(months=months_after_eff_date)

                invoice = Invoice(self.policy.id,
                                  bill_date,
                                  bill_date + relativedelta(months=1),
                                  bill_date + relativedelta(months=1, days=14),
                                  self.policy.annual_premium / billing_schedules.get(self.policy.billing_schedule))

                invoices.append(invoice)
        elif self.policy.billing_schedule == "Monthly":
            first_invoice.amount_due = first_invoice.amount_due / billing_schedules.get(self.policy.billing_schedule)

            for i in range(1, billing_schedules.get(self.policy.billing_schedule)):
                months_after_eff_date = i

                bill_date = self.policy.effective_date + relativedelta(months=months_after_eff_date)

                invoice = Invoice(self.policy.id,
                                  bill_date,
                                  bill_date + relativedelta(months=1),
                                  bill_date + relativedelta(months=1, days=14),
                                  self.policy.annual_premium / billing_schedules.get(self.policy.billing_schedule))

                invoices.append(invoice)
        else:
            print "You have chosen a bad billing schedule."

        for invoice in invoices: # For every invoice created, add it to the database.
            db.session.add(invoice)
            
        db.session.commit() # Commit the changes (save)