Esempio n. 1
0
    def post(self, request):
        uploaded_text = request.POST['upload-lc-register-text'].strip(' \n\r')
        date_format = request.POST['date-format']
        logger.info("Raw data received from client:\n%s" % uploaded_text)

        if uploaded_text:
            parser_utility = UploadCSVParserUtility()
            lc_classes = LCClass.objects.values_list('prod_code', flat=True)

            for data in json.loads(uploaded_text):
                logger.info('About to create or update lc using raw data from client:\n%s' % data)

                data["expiry_date"] = parser_utility.normalize_date(data["expiry_date"], date_format)
                data["estb_date"] = parser_utility.normalize_date(data["estb_date"], date_format)
                data['ccy_obj'] = Currency.objects.get(code=data['ccy_obj'].strip(' \n\r'))
                data["lc_amt_org_ccy"] = round(float(data["lc_amt_org_ccy"].strip(' \n\r').replace(',', '')), 2)
                data["os_amount"] = round(float(data["os_amount"].strip(' \n\r').replace(',', '')), 2)

                logger.info('About to create or update lc after raw data from client cleaned up:\n%s' % data)

                lc_number = data['lc_number'].strip(' \n\r')
                data['lc_number'] = lc_number

                if 'GTE-' in lc_number:
                    continue

                logger.info("Checking if LC %s exists in database" % lc_number)
                lc_qs = LCRegister.objects.filter(lc_number=lc_number)

                if not lc_qs.exists():
                    ref_class = lc_number[:7]
                    if ref_class in lc_classes:
                        data['lc_class'] = ref_class
                    logger.info('LC "%s" does not exist in database, it will be created', lc_number)
                    lc_obj = LCRegister.objects.create(**data)
                    logger.info('LC "%s" successfully created.' % lc_number)

                else:
                    logger.info(
                            "LC %s exists in database, it will be updated if at least one attribute value has changed" %
                            lc_number)

                    lc_obj = self.update_only_if_lc_changed(lc_number, lc_qs, data)

                form_m_qs = FormM.objects.filter(number=data['mf'].strip(' \n\r'), lc__isnull=True)

                if form_m_qs.exists():
                    logger.info('LC %s: if form M was not previously attached, form M "%s" will now be attached.' % (
                        lc_number, data['mf']))
                    form_m_qs[0].attach_lc(lc=lc_obj)

        return redirect(admin_url(LCRegister))
Esempio n. 2
0
    def parse(self, file_obj):
        parser_utility = UploadCSVParserUtility()
        for row in csv.reader(file_obj, delimiter="\t"):
            if self.ok_to_parse(row):
                ref = parser_utility.normalize_ref(row[col.b])
                posting_date = parser_utility.normalize_date(row[col.c], self.date_format)
                acct_number = parser_utility.normalize_acct_numb(row[col.d])
                ccy = parser_utility.normalize(row[col.f])
                amount_raw = parser_utility.normalize_amount(row[col.j])
                amount = -amount_raw if row[col.h] == "D" else amount_raw
                narration = parser_utility.normalize(row[col.g])
                success = parser_utility.normalize(row[col.j])

                post_obj = TIPostingStatusReport.objects.filter(
                    ref=ref, posting_date=posting_date, amount=amount, ccy=ccy, narration=narration
                )

                if not post_obj.exists():
                    TIPostingStatusReport.objects.create(
                        ref=ref,
                        posting_date=posting_date,
                        amount=amount,
                        acct_number=acct_number,
                        ccy=ccy,
                        success=success,
                        narration=narration,
                    )
                else:
                    post = post_obj[0]
                    if post.success != success and post.acct_number:
                        post.success = success
                        post.save()
Esempio n. 3
0
    def post(self, request):
        log_prefix = 'About to create lc commission: '
        uploaded_text = request.POST['upload-lc-commission'].strip(' \n\r')
        logger.info("%s raw data received from client:\n%s", log_prefix, uploaded_text)
        commission_upload_status = None

        if uploaded_text:
            list_lc_not_uploaded = []
            created_commission_count = 0
            parser_utility = UploadCSVParserUtility()

            for data in json.loads(uploaded_text):
                logger.info('%s using raw data from client:\n%s', log_prefix, data)
                lc_number = data['lc_ref'].strip(' \n\r')
                lc_qs = LCRegister.objects.filter(lc_number=lc_number)
                lc = None

                if lc_qs.exists():
                    logging.info('%s LC already exists in database and commission will be created: %s', log_prefix,
                                 lc_number)
                    lc = lc_qs[0]
                    if not lc.acct_numb:
                        lc.acct_numb = data['acct_numb']
                        lc.save()
                else:
                    list_lc_not_uploaded.append(lc_number)
                    logging.warn('%s LC does not exist yet in database: %s', log_prefix, lc_number)
                    continue

                data["charge_date"] = parser_utility.normalize_date(data["charge_date"])
                data["charge_amount"] = round(float(data["charge_amount"].strip(' \n\r').replace(',', '')), 2)
                data["transaction_amount"] = round(float(data["transaction_amount"].strip(' \n\r').replace(',', '')), 2)
                logger.info('%s LC commission will be created with data: %s', log_prefix, data)
                del data['lc_ref']
                data['lc'] = lc_qs[0]
                LcCommission.objects.create(**data)
                created_commission_count += 1

            if created_commission_count or list_lc_not_uploaded:
                commission_upload_status = 'Total uploaded: %d' % created_commission_count

                if list_lc_not_uploaded:
                    commission_upload_status = '%s\n\n\n\nLC not in database: %s' % (
                        commission_upload_status, json.dumps(list_lc_not_uploaded)
                    )

        return self.get(request, commission_upload_status=commission_upload_status)
Esempio n. 4
0
    def post(self, request):
        uploaded_text = request.POST["update-lc-register-text"].strip(" \n\r")

        if uploaded_text:
            parser_utility = UploadCSVParserUtility()

            for data in json.loads(uploaded_text):
                lc_obj = LCRegister.objects.filter(lc_number=data["lc_number"])
                if lc_obj.exists():
                    lc_obj = lc_obj[0]
                    del data["lc_number"]
                    data["expiry_date"] = parser_utility.normalize_date(data["expiry_date"])

                    for key in data:
                        if hasattr(lc_obj, key) and data[key]:
                            setattr(lc_obj, key, data[key])
                    lc_obj.save()

        return redirect(admin_url(LCRegister))
Esempio n. 5
0
    def parse(self, fobj):
        parser_utility = UploadCSVParserUtility()
        pattern = re.compile(r"^([A-Z0-9]{7,})(?:[A-Z]{3}\d{3})?$")

        for row in csv.reader(fobj, delimiter="\t"):
            if self.ok_to_parse(row):
                dr_cr = row[col.m]
                fcy_amt = parser_utility.normalize_amount(row[col.k])
                lcy_amt = parser_utility.normalize_amount(row[col.l])

                TIFlexRecons.objects.get_or_create(
                    brn_code=row[col.a],
                    brn_name=row[col.b],
                    flex_ref=row[col.e],
                    ti_ref=re.sub(pattern, r"\1", row[col.f].strip(" \n\r\t")),
                    acct_numb=row[col.g],
                    acct_name=row[col.i],
                    ccy=row[col.j],
                    dr_cr=dr_cr,
                    fcy_amt=-fcy_amt if dr_cr == "D" else fcy_amt,
                    lcy_amt=-lcy_amt if dr_cr == "D" else lcy_amt,
                    val_date=parser_utility.normalize_date(row[col.n], "-"),
                    narration=row[col.p],
                )
Esempio n. 6
0
    def parse(self, fobj):
        parser_utility = UploadCSVParserUtility()
        for row in csv.reader(fobj, delimiter="\t"):
            if self.ok_to_parse(row):
                booking_date = parser_utility.normalize_date(row[col.g], self.date_format)
                liq_date = parser_utility.normalize_date(row[col.h], self.date_format)
                fx_amt = parser_utility.normalize_amount(row[col.j])
                ngn_amt = parser_utility.normalize_amount(row[col.k])
                narration = parser_utility.normalize(row[col.l])
                flex_module = row[col.d]
                gl_code = row[col.b]
                ccy = row[col.i]

                ti_ref_pattern = LC_REF_RE.search(narration)
                ti_ref = ti_ref_pattern and ti_ref_pattern.group() or ""

                flex_ref = row[col.a]

                if not ContingentReport.objects.filter(
                    flex_ref=flex_ref,
                    gl_code=gl_code,
                    ccy=ccy,
                    booking_date=booking_date,
                    flex_module=flex_module,
                    fx_amt=fx_amt,
                    narration=narration,
                ).exists():
                    ContingentReport.objects.create(
                        flex_ref=flex_ref,
                        flex_module=flex_module,
                        gl_code=gl_code,
                        booking_date=booking_date,
                        liq_date=liq_date,
                        ccy=ccy,
                        fx_amt=fx_amt,
                        ngn_amt=ngn_amt,
                        ti_ref=ti_ref,
                        narration=narration,
                        acct_numb=ContingentAccount.objects.get(gl_code=gl_code),
                    )