Example #1
0
    def handle(self, *args, **options):
        bpoint_total = Decimal('0.00')
        oracle_total = Decimal('0.00')
        invoice_total = Decimal('0.00')
        today = datetime.today()  # - timedelta(days=3)
        fiveminutesago = datetime.now() - timedelta(minutes=5)
        system = settings.PS_PAYMENT_SYSTEM_ID
        system = system.replace('S', '0')
        print(system)
        try:
            print("Calculation Bpoint Transaction Total")
            bpoint_trans = BpointTransaction.objects.filter(
                created__gte=fiveminutesago,
                crn1__startswith=settings.PS_PAYMENT_SYSTEM_ID)
            for i in bpoint_trans:
                print(i)

        except Exception as e:
            print("Error: Sending Email Notification: " +
                  settings.NOTIFICATION_EMAIL)
            context = {'error_report': str(e)}
            email_list = []
            for email_to in settings.NOTIFICATION_EMAIL.split(","):
                email_list.append(email_to)
            sendHtmlEmail(tuple(email_list),
                          "[MOORING] oracle and bpoint total mistatch",
                          context,
                          'mooring/email/oracle_bpoint.html',
                          None,
                          None,
                          settings.EMAIL_FROM,
                          'system-oim',
                          attachments=None)
Example #2
0
    def handle(self, *args, **options):
            bpoint_total = Decimal('0.00')
            oracle_total = Decimal('0.00')
            invoice_total = Decimal('0.00')
            today = datetime.today()# - timedelta(days=3)
            system = settings.PS_PAYMENT_SYSTEM_ID
            system = system.replace('S','0')
            print (system)
            try:
                 print ("Calculation Bpoint Transaction Total")
                 bpoint_trans = BpointTransaction.objects.filter(settlement_date=today, crn1__istartswith=system)
                 for i in bpoint_trans:
                      if i.action == 'payment':
                              bpoint_total = bpoint_total + Decimal(i.amount)
                      if i.action == 'refund':
                              bpoint_total = bpoint_total - Decimal(i.amount)


                 print (bpoint_total)
                 print ("Calculation Invoice Settlemnt Oracle Totals")

                 invoices = Invoice.objects.filter(settlement_date=today)
                 for i in invoices:
                     #print (i.reference)
                     invoice_total = invoice_total + Decimal(i.amount)
                     #print (i.order)
                     for ol in Order.objects.get(number=i.order_number).lines.all():
                          for order_total in ol.payment_details['order']:
                              oracle_total = oracle_total + Decimal(ol.payment_details['order'][order_total])
                              #print (Decimal(ol.payment_details['order'][order_total]))
                              #print (oracle_total)
                 print ("ORACLE TOTAL")
                 print (oracle_total)
                 print (invoice_total)

                 if bpoint_total != oracle_total:
                      raise ValidationError("Bpoint and Oracle Totals do not match. Bpoint Total: "+str(bpoint_total)+" Oracle Total: "+str(oracle_total))
            except Exception as e:
                 print ("Error: Sending Email Notification: "+settings.NOTIFICATION_EMAIL)
                 context = {
                     'error_report' : str(e)
                 }
                 email_list = []
                 for email_to in settings.NOTIFICATION_EMAIL.split(","):
                        email_list.append(email_to)
                 sendHtmlEmail(tuple(email_list),"[MOORING] oracle and bpoint total mistatch",context,'mooring/email/oracle_bpoint.html',None,None,settings.EMAIL_FROM,'system-oim',attachments=None)
Example #3
0
    def handle(self, *args, **options):
        bpoint_total = Decimal('0.00')
        oracle_total = Decimal('0.00')
        invoice_total = Decimal('0.00')
        yesterday = datetime.today() - timedelta(days=1)
        today = datetime.today()  # - timedelta(days=41)
        tomorrow = datetime.today() + timedelta(days=1)

        system = settings.PS_PAYMENT_SYSTEM_ID
        system = system.replace('S', '0')
        bpoint_array = {}
        invoice_array = {}
        mismatch_bpoint = []
        mismatch_invoice = []
        ba_missing = []
        ia_missing = []
        dates_to_check = [yesterday, today, tomorrow]

        print(system)
        try:
            for settlement_date in dates_to_check:
                print("Settlement Date: " +
                      str(settlement_date.strftime("%d/%m/%Y")))
                bpoint_total = Decimal('0.00')
                oracle_total = Decimal('0.00')
                invoice_total = Decimal('0.00')
                bpoint_array = {}
                invoice_array = {}
                mismatch_bpoint = []
                mismatch_invoice = []
                ba_missing = []
                ia_missing = []

                print("Calculation Bpoint Transaction Total")
                bpoint_trans = BpointTransaction.objects.filter(
                    settlement_date=settlement_date, crn1__istartswith=system)
                for i in bpoint_trans:
                    tran_total = Decimal('0.00')
                    if i.action == 'payment':
                        bpoint_total = bpoint_total + Decimal(i.amount)
                        tran_total = Decimal(i.amount)
                    if i.action == 'refund':
                        bpoint_total = bpoint_total - Decimal(i.amount)
                        tran_total = tran_total - Decimal(i.amount)
                    bpoint_array[i.crn1] = tran_total

                print(bpoint_total)
                print("Calculation Invoice Settlemnt Oracle Totals")

                invoices = Invoice.objects.filter(
                    settlement_date=settlement_date)
                for i in invoices:
                    #print (i.reference)
                    invoice_total = invoice_total + Decimal(i.amount)
                    #print (i.order)
                    trans_order_total = Decimal('0.00')
                    for ol in Order.objects.get(
                            number=i.order_number).lines.all():
                        for order_total in ol.payment_details['order']:
                            oracle_total = oracle_total + Decimal(
                                ol.payment_details['order'][order_total])
                            trans_order_total = trans_order_total + Decimal(
                                ol.payment_details['order'][order_total])
                            #print (Decimal(ol.payment_details['order'][order_total]))
                            #print (oracle_total)
                        invoice_array[i.reference] = trans_order_total
                print("ORACLE TOTAL")
                print(oracle_total)
                print(invoice_total)
                #bpoint with mismatching invoice
                for ba in bpoint_array:
                    if ba in invoice_array:
                        if bpoint_array[ba] != invoice_array[ba]:
                            mismatch_bpoint.append('Mismatch: ' + ba + '(' +
                                                   invoice_array[ba] + ')' +
                                                   '(' + bpoint_array[ba] +
                                                   ')')
                        else:
                            ba_missing.append('BP No exist: ' + ba + '(' +
                                              str(bpoint_array[ba]) + ')')

                # invoice with mismatching bpoint
                for ia in invoice_array:
                    #print (ia)
                    #print (invoice_array[ia])
                    if ia in bpoint_array:
                        #print (bpoint_array[ia])
                        if invoice_array[ia] != bpoint_array[ia]:
                            mismatch_invoice.append('Mismatch: ' + ia + '(' +
                                                    invoice_array[ia] + ')' +
                                                    '(' + bpoint_array[ia] +
                                                    ')')
                        else:
                            ia_missing.append(ia + '(' +
                                              str(invoice_array[ia]) + ')')

                if bpoint_total != oracle_total:
                    print("Sending Report")
                    context = {
                        'error_report':
                        "Bpoint and Oracle Totals do not match. Bpoint Total: "
                        + str(bpoint_total) + " Oracle Total: " +
                        str(oracle_total),
                        'mismatch_bpoint':
                        mismatch_bpoint,
                        'mismatch_invoice':
                        mismatch_invoice,
                        'ba_missing':
                        ba_missing,
                        'ia_missing':
                        ia_missing,
                        'settlement_date':
                        settlement_date
                    }
                    email_list = []
                    for email_to in settings.NOTIFICATION_EMAIL.split(","):
                        email_list.append(email_to)
                    sendHtmlEmail(tuple(email_list),
                                  "[MOORING] oracle and bpoint total mistatch",
                                  context,
                                  'mooring/email/oracle_bpoint_report.html',
                                  None,
                                  None,
                                  settings.EMAIL_FROM,
                                  'system-oim',
                                  attachments=None)
                    #raise ValidationError("Bpoint and Oracle Totals do not match. Bpoint Total: "+str(bpoint_total)+" Oracle Total: "+str(oracle_total))
        except Exception as e:
            print("Error: Sending Email Notification: " +
                  settings.NOTIFICATION_EMAIL)
            context = {
                'error_report': str(e),
            }
            email_list = []
            for email_to in settings.NOTIFICATION_EMAIL.split(","):
                email_list.append(email_to)
            sendHtmlEmail(tuple(email_list),
                          "[MOORING] oracle and bpoint total mistatch",
                          context,
                          'mooring/email/oracle_bpoint.html',
                          None,
                          None,
                          settings.EMAIL_FROM,
                          'system-oim',
                          attachments=None)
    def handle(self, *args, **options):
        rows = []
        system = settings.PS_PAYMENT_SYSTEM_ID
        system = system.replace('S', '0')
        rows = bpoint_integrity_checks(system, 2, 10)

        for r in rows:
            print(r['booking_reference'])
            print(r)
            booking_reference_split = r['booking_reference'].split('-')
            if len(booking_reference_split) == 2:
                booking_group_type = booking_reference_split[0]
                booking_id = booking_reference_split[1]

                if booking_group_type == 'AA':
                    baa = models.BookingAnnualAdmission.objects.filter(
                        id=booking_id)
                    basket = Basket.objects.filter(id=int(r['basket']))
                    if baa.count() > 0:
                        pass
                        if baa[0].booking_type == 3:
                            baa[0].annual_booking_period_group.mooring_group
                            mooring_group_id = baa[
                                0].annual_booking_period_group.mooring_group.id
                            al = models.AdmissionsLocation.objects.get(
                                mooring_group__id=mooring_group_id)
                            cp = context_processors.mooring_url_group(al.key)
                            context = utils.booking_annual_admission_success(
                                basket, baa[0], cp)
                            bpoint_integrity_checks_completed(
                                r['bpoint_id'], r['reference'])

                            emails = models.EmailGroup.objects.filter(
                                email_group=1, mooring_group=mooring_group_id)
                            context = {
                                'booking':
                                baa[0],
                                'booking_reference':
                                r['booking_reference'].replace("-", ""),
                                'invoice':
                                r['reference'],
                                'customer_name':
                                baa[0].details['first_name'] + ' ' +
                                baa[0].details['last_name']
                            }
                            email_list = []
                            for e in emails:
                                email_list.append(e.email)
                            sendHtmlEmail(
                                tuple(email_list),
                                "[MOORING] Annual Admission Booking Recovery for ("
                                +
                                str(r['booking_reference'].replace("-", "")) +
                                ") with invoice (" + r['reference'] + ")",
                                context,
                                'mooring/email/booking_recovery.html',
                                None,
                                None,
                                settings.EMAIL_FROM,
                                'system-oim',
                                attachments=None)

                            print("AA")
                            print(baa[0].id)
                        else:
                            bpoint_integrity_checks_completed(
                                r['bpoint_id'], r['reference'])
                if booking_group_type == 'AD':
                    baa = models.AdmissionsBooking.objects.filter(
                        id=booking_id)
                    basket = Basket.objects.filter(id=int(r['basket']))

                    if baa.count() > 0:
                        pass
                        if baa[0].booking_type == 3:
                            al = models.AdmissionsLine.objects.filter(
                                admissionsBooking=baa[0])
                            cp = context_processors.mooring_url_group(
                                al[0].location.key)
                            context = utils.booking_admission_success(
                                basket, baa[0], cp)
                            print("AD")
                            print(baa[0].id)
                            bpoint_integrity_checks_completed(
                                r['bpoint_id'], r['reference'])
                            print("Sending Email")
                            emails = models.EmailGroup.objects.filter(
                                email_group=2,
                                mooring_group=al[0].location.mooring_group.id)
                            context = {
                                'booking':
                                baa[0],
                                'booking_reference':
                                r['booking_reference'].replace("-", ""),
                                'invoice':
                                r['reference'],
                                'customer_name':
                                baa[0].customer
                            }

                            email_list = []
                            for e in emails:
                                email_list.append(e.email)
                            sendHtmlEmail(
                                tuple(email_list),
                                "[MOORING] Admission Booking Recovery for (" +
                                str(r['booking_reference'].replace("-", "")) +
                                ") with invoice (" + r['reference'] + ")",
                                context,
                                'mooring/email/booking_recovery.html',
                                None,
                                None,
                                settings.EMAIL_FROM,
                                'system-oim',
                                attachments=None)
                        else:
                            bpoint_integrity_checks_completed(
                                r['bpoint_id'], r['reference'])

                if booking_group_type == 'PS':
                    baa = models.Booking.objects.filter(id=booking_id)
                    if baa.count() > 0:
                        basket = Basket.objects.filter(id=int(r['basket']))
                        if baa[0].mooringarea:
                            if baa[0].booking_type == 3:

                                mg = models.MooringAreaGroup.objects.filter(
                                    moorings__in=[baa[0].mooringarea.id])
                                al = models.AdmissionsLocation.objects.get(
                                    mooring_group__id=mg[0].id)
                                cp = context_processors.mooring_url_group(
                                    al.key)
                                context = utils.booking_success(
                                    basket, baa[0], cp)
                                bpoint_integrity_checks_completed(
                                    r['bpoint_id'], r['reference'])
                                emails = models.EmailGroup.objects.filter(
                                    email_group=1, mooring_group=mg[0])
                                context = {
                                    'booking':
                                    baa[0],
                                    'booking_reference':
                                    r['booking_reference'].replace("-", ""),
                                    'invoice':
                                    r['reference'],
                                    'customer_name':
                                    baa[0].details['first_name'] + ' ' +
                                    baa[0].details['last_name']
                                }

                                email_list = []
                                for e in emails:
                                    email_list.append(e.email)
                                sendHtmlEmail(
                                    tuple(email_list),
                                    "[MOORING] Booking Recovery for (" +
                                    str(r['booking_reference'].replace(
                                        "-", "")) + ") with invoice (" +
                                    r['reference'] + ")",
                                    context,
                                    'mooring/email/booking_recovery.html',
                                    None,
                                    None,
                                    settings.EMAIL_FROM,
                                    'system-oim',
                                    attachments=None)
                            else:
                                bpoint_integrity_checks_completed(
                                    r['bpoint_id'], r['reference'])
            else:
                bpoint_integrity_checks_completed(r['bpoint_id'],
                                                  r['reference'])