示例#1
0
    def _build_recurrences(self):
        recurrences = self._payment.scheme.recurrences

        for rec in recurrences:
            amt, curr = rec.amount # pylint: disable=W0612
            paid, curr = rec.paid_amount
            open_amt, curr = rec.open_amount
            date = date_time.get_formatted_date(rec.recurrence_date)

            if rec.cleared:
                icon = "🟢"
            else:
                icon = "🔴"

            rec_dict = {"date": date,
                        "amount": amt,
                        "paid": paid,
                        "open": open_amt,
                        "icon": icon,
                        "collections": []}

            collections = rec.collections

            for coll in collections:
                coll_amo, coll_curr = coll.amount
                coll_dict = {"date": date_time.get_formatted_date(coll.date),
                             "amount": coll_amo,
                             "currency": coll_curr,
                             "description": coll.description}
                rec_dict["collections"].append(coll_dict)

            self._out["recurrences"].append(rec_dict)
示例#2
0
    def _recurrence_select(self, dummy):  # pylint: disable=W0613
        # Prepare
        self._clear_collection_tree()

        # Get clicked recurrence payments
        clicked_recurrence = self._get_selected_recurrence()
        if clicked_recurrence is None:
            return

        collections = clicked_recurrence.collections

        # Paint
        for collection in collections:
            amount, currency = collection.amount
            tree_val = (collection.description,
                        util_amount.get_formatted_amount(amount) + currency)

            id_in_tree = self._collection_tree.insert(
                '',
                'end',
                text=date_time.get_formatted_date(collection.date),
                value=tree_val)
            self._collection_tree_content[id_in_tree] = collection

        self.update()
示例#3
0
    def _fill_tree_with_activities(self):
        self._activities = Activity.get_activities()

        self._activities["activities"] = sorted(
            self._activities["activities"],
            key=lambda x: x["date"],
            reverse=True)

        self._tree_content = {}

        self._tree.delete(*self._tree.get_children())

        for activity_line in self._activities["activities"]:
            activity_obj = activity.Activity(activity_line)
            project_obj = activity_obj.project
            tree_val = (
                project_obj.client.name,
                project_obj.name,
                activity_obj.location,
                activity_obj.guid
            )

            id_in_tree = self._tree.insert(
                '',
                'end',
                text=date_time.get_formatted_date(activity_obj.date),
                value=tree_val
            )
            self._tree_content[id_in_tree] = activity_obj

        self.update()
示例#4
0
def _generate_asset_value_history(assets: dict) -> dict:
    """ Adds value history to asset dict """
    max_val_hist_size = config.CONSTANTS["ASSET_HISTORY_SIZE"]
    result = deepcopy(assets)

    for asset in result["assets"]:
        if "value_history" in asset:
            last_hist_idx = len(asset["value_history"]) - 1
            if last_hist_idx >= 0:
                last_hist_val = asset["value_history"][last_hist_idx]

                if last_hist_val["value"] == asset["sales_value"]:
                    continue

        new_hist_val = {
            "date": get_formatted_date(datetime.now()),
            "value": asset["sales_value"]
        }

        asset["value_history"].append(new_hist_val)

        if len(asset["value_history"]) > max_val_hist_size:
            len_diff = len(asset["value_history"]) - max_val_hist_size
            del asset["value_history"][0:len_diff]

    return result
示例#5
0
    def _build_summary(self):
        total_amount, curr = self._payment.total_amount
        total_open_amount, curr = self._payment.open_amount
        paid_amount = total_amount - total_open_amount

        if total_amount == 0:
            paid_perc = 0
        else:
            paid_perc = int(paid_amount * 100 / total_amount)

        amt, curr = self._payment.amount
        scheme = self._payment.scheme
        freq, per = scheme.frequency
        pay_plan = amount.get_formatted_amount(amt) + " "
        pay_plan += curr + " every " + str(freq) + " "
        pay_plan += per + " x" + str(scheme.repeat)
        pay_plan += "; starting " + date_time.get_formatted_date(scheme.start_date)

        self._out["summary"] = {"description": self._payment.description,
                                "company": self._payment.company.name,
                                "total_amount": total_amount,
                                "open_amount": total_open_amount,
                                "paid_amount": paid_amount,
                                "paid_perc": paid_perc,
                                "currency": curr,
                                "pay_plan": pay_plan}
示例#6
0
    def _fill_tree_with_payments(self):
        self._payments = payment.get_payments()
        self._tree_content = {}

        self._tree.delete(*self._tree.get_children())

        sorted_payments = self._payments["payments"]
        sorted_payments.sort(
            key=lambda x: payment.Payment(x).scheme.next_significant_date)

        for payment_line in sorted_payments:
            payment_obj = payment.Payment(payment_line)
            amount, currency = payment_obj.amount
            open_amount, open_currency = payment_obj.open_amount

            tree_val = (payment_obj.company.name,
                        util_amount.get_formatted_amount(amount) +
                        " " + currency,
                        util_amount.get_formatted_amount(open_amount) + " " +
                        open_currency, payment_obj.direction,
                        payment_obj.description)

            tree_txt_date = payment_obj.scheme.next_significant_date
            id_in_tree = self._tree.insert(
                '',
                'end',
                text=date_time.get_formatted_date(tree_txt_date),
                value=tree_val)
            self._tree_content[id_in_tree] = payment_obj

        self.update()
示例#7
0
    def result(self) -> dict:
        """ Returns result """
        out = {"Profits": [],
               "Sums": {"liquid_sales": 0,
                        "liquid_profit": 0,
                        "sales": 0,
                        "liquid_sales_home": 0,
                        "liquid_profit_home": 0,
                        "sales_home": 0}}

        assets = imp_asset.get_assets(deduct_income_tax=True, own_percentage_only=True)
        assets["assets"].sort(key=lambda x: imp_asset.is_liquid(x["type"]), reverse=True)

        for asset in assets["assets"]:
            asset_profit = self._calc_asset_profit(asset)

            history = ""
            prev_hist_val = 0
            if "value_history" in asset:
                for history_entry in asset["value_history"]:
                    hist_asset = deepcopy(asset)
                    hist_asset["sales_value"] = history_entry["value"]
                    hist_profit = self._calc_asset_profit(hist_asset)

                    if history != "":
                        if hist_profit["usd_profit"] > prev_hist_val:
                            history += " ↑ "
                        else:
                            history += " ↓ "
                    history += str(round(hist_profit["usd_profit"]))
                    prev_hist_val = hist_profit["usd_profit"]

            asset_dict = deepcopy(asset_profit)
            asset_dict["name"] = asset["name"]
            asset_dict["purchase_date"] = date_time.get_formatted_date(asset_profit["purchase_date"]) # pylint: disable=C0301
            asset_dict["quantity"] = asset["quantity"]
            asset_dict["history"] = history

            out["Profits"].append(asset_dict)

            if imp_asset.is_liquid(asset["type"]):
                out["Sums"]["liquid_sales"] += int(asset_dict["actual_usd_total"])
                out["Sums"]["liquid_profit"] += int(asset_dict["usd_profit"])
            out["Sums"]["sales"] += int(asset_dict["actual_usd_total"])

        out["Sums"]["liquid_sales_home"] = int(self._curr_conv.convert_to_local_currency(
            out["Sums"]["liquid_sales"],
            "USD"))

        out["Sums"]["liquid_profit_home"] = int(self._curr_conv.convert_to_local_currency(
            out["Sums"]["liquid_profit"],
            "USD"))

        out["Sums"]["sales_home"] = int(self._curr_conv.convert_to_local_currency(
            out["Sums"]["sales"],
            "USD"))

        return out
示例#8
0
 def all_activities(self) -> dict:
     """ Returns all activities """
     if not self._all_activities_read:
         self._all_activities = Activity.get_activities()
         for act in self._all_activities["activities"]:
             activity = Activity(act)
             act["date"] = date_time.get_formatted_date(activity.date)
         self._all_activities_read = True
     return self._all_activities
示例#9
0
def _get_payment_suffix(pay: Payment,
                        rec_date: datetime.datetime = None,
                        amount: float = None,
                        currency: str = None) -> str:
    output = " (" + pay.direction + "):"
    if rec_date is not None:
        output += " " + date_time.get_formatted_date(rec_date)
    if amount is not None and currency is not None:
        output += " - "
        output += util_amount.get_formatted_amount(amount) + " " + currency
    output += " (" + pay.description + ") {" + pay.guid + "}"
    return output
示例#10
0
    def _paint_recurrences(self):
        self._recurrence_tree_content = {}
        self._recurrence_tree.delete(*self._recurrence_tree.get_children())
        self.update()

        recurrences = self._payment.scheme.recurrences

        for recurrence in recurrences:
            amount, currency = recurrence.amount
            open_amount, open_currency = recurrence.open_amount
            tree_val = (date_time.get_formatted_date(
                recurrence.expected_payment_date),
                        util_amount.get_formatted_amount(amount) + currency,
                        util_amount.get_formatted_amount(open_amount) +
                        open_currency, str(recurrence.cleared))

            id_in_tree = self._recurrence_tree.insert(
                '',
                'end',
                text=date_time.get_formatted_date(recurrence.recurrence_date),
                value=tree_val)
            self._recurrence_tree_content[id_in_tree] = recurrence

        self.update()
示例#11
0
    def _fill_tree_with_invoices(self):
        self._invoices = get_invoices()
        self._invoices["invoices"].sort(key=lambda x: x["invoice_date"],
                                        reverse=True)
        self._tree_content = {}

        self._tree.delete(*self._tree.get_children())

        for invoice_line in self._invoices["invoices"]:
            invoice_obj = Invoice(invoice_line)
            tree_val = (invoice_obj.payer.name,
                        amount.get_formatted_amount(invoice_obj.amount) + " " +
                        invoice_obj.currency, invoice_obj.serial,
                        invoice_obj.guid)

            id_in_tree = self._tree.insert('',
                                           'end',
                                           text=date_time.get_formatted_date(
                                               invoice_obj.invoice_date),
                                           value=tree_val)
            self._tree_content[id_in_tree] = invoice_obj

        self.update()
示例#12
0
    def _append_month(self, year: int, month: int, elem: str):
        sap_year = str(year)
        sap_month = date_time.get_two_digit_month(month)
        ecz_activities = ecz_daha.get_monthly_activity(p_sap_year=sap_year,
                                                       p_sap_month=sap_month)

        for ecz_activity in ecz_activities:
            date_of_activity = date_time.parse_sap_date(ecz_activity["date"])

            kifu_hour_sum = Activity.get_time_sum(client_name=self._ecz,
                                                  date=date_of_activity)

            date = date_time.get_formatted_date(
                date_time.parse_sap_date(ecz_activity["date"]))

            entry = {
                "date": date,
                "comment": ecz_activity["comment"],
                "ecz_hours": ecz_activity["hours"],
                "kifu_hours": kifu_hour_sum,
                "different": kifu_hour_sum != ecz_activity["hours"]
            }

            self._result[elem].append(entry)
示例#13
0
def get_payment_objects_from_invoice(invoice: Invoice) -> list:
    """ Extracts new payment objects out of an invoice """
    # Preparation
    output = []

    currency_converter = CurrencyConverter()
    inc_tax_calc = IncomeTaxCalculatorFactory.get_instance()

    invoice_currency = invoice.currency
    invoice_date = invoice.invoice_date
    invoice_payer = invoice.payer
    invoice_serial = invoice.serial
    payment_amount = invoice.amount_plus_vat

    description_prefix = invoice_payer.name + " - " + date_time.get_formatted_date(
        invoice_date) + "(" + invoice_serial + ")"

    # Incoming payment

    incoming_payment_json = {
        "guid": identifier.get_guid(),
        "creation_date": datetime.datetime.now().isoformat(),
        "company": invoice_payer.name,
        "description": description_prefix + " - Incoming payment",
        "invoice_guid": invoice.guid,
        "direction": DIRECTION_IN,
        "amount": payment_amount,
        "currency": invoice_currency,
        "cleared": False
    }

    incoming_scheme_json = {
        "frequency":
        1,
        "period":
        PERIOD_DAILY,
        "start":
        invoice.due_date.isoformat(),
        "repeat":
        1,
        "recurrence": [{
            "recurrence_date": invoice.due_date.isoformat(),
            "expected_payment_date": invoice.due_date.isoformat(),
            "amount": payment_amount,
            "currency": invoice_currency,
            "cleared": False,
            "collections": []
        }]
    }

    incoming_scheme_obj = Scheme(incoming_scheme_json)

    incoming_payment_obj = Payment(incoming_payment_json)
    incoming_payment_obj.scheme = incoming_scheme_obj

    output.append(incoming_payment_obj)

    # VAT transfer

    if invoice.is_vat_liable:
        vat_amount = invoice.vat_amount_in_local_currency

        vat_transfer_json = {
            "guid": identifier.get_guid(),
            "creation_date": datetime.datetime.now().isoformat(),
            "company": config.CONSTANTS["DEFAULT_BANK"],
            "description": description_prefix + " - VAT transfer",
            "invoice_guid": "",
            "direction": DIRECTION_TRANSFER,
            "amount": vat_amount,
            "currency": config.CONSTANTS["HOME_CURRENCY"],
            "cleared": False
        }

        vat_transfer_date = invoice.vat_transfer_date

        vat_transfer_scheme_json = {
            "frequency":
            1,
            "period":
            PERIOD_DAILY,
            "start":
            vat_transfer_date.isoformat(),
            "repeat":
            1,
            "recurrence": [{
                "recurrence_date":
                vat_transfer_date.isoformat(),
                "expected_payment_date":
                vat_transfer_date.isoformat(),
                "amount":
                vat_amount,
                "currency":
                config.CONSTANTS["HOME_CURRENCY"],
                "cleared":
                False,
                "collections": []
            }]
        }

        vat_transfer_scheme_obj = Scheme(vat_transfer_scheme_json)

        vat_transfer_payment_obj = Payment(vat_transfer_json)
        vat_transfer_payment_obj.scheme = vat_transfer_scheme_obj

        output.append(vat_transfer_payment_obj)

    # VAT payment

    if invoice.is_vat_liable:
        vat_amount = invoice.vat_amount_in_local_currency

        vat_payment_json = {
            "guid": identifier.get_guid(),
            "creation_date": datetime.datetime.now().isoformat(),
            "company": config.CONSTANTS["HOME_GOVERNMENT"],
            "description": description_prefix + " - VAT payment",
            "invoice_guid": "",
            "direction": DIRECTION_OUT,
            "amount": vat_amount,
            "currency": config.CONSTANTS["HOME_CURRENCY"],
            "cleared": False,
            "is_vat": True
        }

        vat_payment_date = invoice.vat_payment_date

        vat_payment_scheme_json = {
            "frequency":
            1,
            "period":
            PERIOD_DAILY,
            "start":
            vat_payment_date.isoformat(),
            "repeat":
            1,
            "recurrence": [{
                "recurrence_date":
                vat_payment_date.isoformat(),
                "expected_payment_date":
                vat_payment_date.isoformat(),
                "amount":
                vat_amount,
                "currency":
                config.CONSTANTS["HOME_CURRENCY"],
                "cleared":
                False,
                "collections": []
            }]
        }

        vat_payment_scheme_obj = Scheme(vat_payment_scheme_json)

        vat_payment_payment_obj = Payment(vat_payment_json)
        vat_payment_payment_obj.scheme = vat_payment_scheme_obj

        output.append(vat_payment_payment_obj)

    # Income tax investment & transfer

    itax_amount = currency_converter.convert_to_local_currency(
        invoice.income_tax_amount, invoice_currency)

    itax_investment_rate = 100
    itax_investment_rate -= inc_tax_calc.safety_tax_rate
    itax_investment_rate -= inc_tax_calc.temp_tax_rate
    itax_investment_amount = itax_amount * itax_investment_rate / 100
    itax_amount -= itax_investment_amount

    itax_transfer_json = {
        "guid": identifier.get_guid(),
        "creation_date": datetime.datetime.now().isoformat(),
        "company": config.CONSTANTS["DEFAULT_BANK"],
        "description": description_prefix + " - income tax investment",
        "invoice_guid": "",
        "direction": DIRECTION_TRANSFER,
        "amount": itax_investment_amount,
        "currency": config.CONSTANTS["HOME_CURRENCY"],
        "cleared": False
    }

    itax_transfer_date = invoice.income_tax_transfer_date

    itax_transfer_scheme_json = {
        "frequency":
        1,
        "period":
        PERIOD_DAILY,
        "start":
        itax_transfer_date.isoformat(),
        "repeat":
        1,
        "recurrence": [{
            "recurrence_date": itax_transfer_date.isoformat(),
            "expected_payment_date": itax_transfer_date.isoformat(),
            "amount": itax_amount,
            "currency": config.CONSTANTS["HOME_CURRENCY"],
            "cleared": False,
            "collections": []
        }]
    }

    itax_transfer_scheme_obj = Scheme(itax_transfer_scheme_json)
    itax_transfer_payment_obj = Payment(itax_transfer_json)
    itax_transfer_payment_obj.scheme = itax_transfer_scheme_obj
    output.append(itax_transfer_payment_obj)

    itax_transfer_json = {
        "guid": identifier.get_guid(),
        "creation_date": datetime.datetime.now().isoformat(),
        "company": config.CONSTANTS["DEFAULT_BANK"],
        "description": description_prefix + " - income tax transfer",
        "invoice_guid": "",
        "direction": DIRECTION_TRANSFER,
        "amount": itax_amount,
        "currency": config.CONSTANTS["HOME_CURRENCY"],
        "cleared": False
    }

    itax_transfer_date = invoice.income_tax_transfer_date

    itax_transfer_scheme_json = {
        "frequency":
        1,
        "period":
        PERIOD_DAILY,
        "start":
        itax_transfer_date.isoformat(),
        "repeat":
        1,
        "recurrence": [{
            "recurrence_date": itax_transfer_date.isoformat(),
            "expected_payment_date": itax_transfer_date.isoformat(),
            "amount": itax_amount,
            "currency": config.CONSTANTS["HOME_CURRENCY"],
            "cleared": False,
            "collections": []
        }]
    }

    itax_transfer_scheme_obj = Scheme(itax_transfer_scheme_json)
    itax_transfer_payment_obj = Payment(itax_transfer_json)
    itax_transfer_payment_obj.scheme = itax_transfer_scheme_obj
    output.append(itax_transfer_payment_obj)

    # Income tax payment

    itax_amount = currency_converter.convert_to_local_currency(
        invoice.income_tax_amount, invoice_currency)

    itax_payment_json = {
        "guid": identifier.get_guid(),
        "creation_date": datetime.datetime.now().isoformat(),
        "company": config.CONSTANTS["HOME_GOVERNMENT"],
        "description": description_prefix + " - income tax payment",
        "invoice_guid": "",
        "direction": DIRECTION_OUT,
        "amount": itax_amount,
        "currency": config.CONSTANTS["HOME_CURRENCY"],
        "cleared": False,
        "is_income_tax": True
    }

    itax_payment_date = invoice.income_tax_payment_date

    itax_payment_scheme_json = {
        "frequency":
        1,
        "period":
        PERIOD_DAILY,
        "start":
        itax_payment_date.isoformat(),
        "repeat":
        1,
        "recurrence": [{
            "recurrence_date": itax_payment_date.isoformat(),
            "expected_payment_date": itax_payment_date.isoformat(),
            "amount": itax_amount,
            "currency": config.CONSTANTS["HOME_CURRENCY"],
            "cleared": False,
            "collections": []
        }]
    }

    itax_payment_scheme_obj = Scheme(itax_payment_scheme_json)

    itax_payment_payment_obj = Payment(itax_payment_json)
    itax_payment_payment_obj.scheme = itax_payment_scheme_obj

    output.append(itax_payment_payment_obj)

    # Alms

    alms_amount = currency_converter.convert_to_local_currency(
        invoice.alms_amount, invoice_currency)

    alms_payment_json = {
        "guid": identifier.get_guid(),
        "creation_date": datetime.datetime.now().isoformat(),
        "company": config.CONSTANTS["COMPANY_NAME_UNKNOWN"],
        "description": description_prefix + " - alms",
        "invoice_guid": "",
        "direction": DIRECTION_OUT,
        "amount": alms_amount,
        "currency": config.CONSTANTS["HOME_CURRENCY"],
        "cleared": False
    }

    alms_payment_date = invoice.alms_payment_date

    alms_payment_scheme_json = {
        "frequency":
        1,
        "period":
        PERIOD_DAILY,
        "start":
        alms_payment_date.isoformat(),
        "repeat":
        1,
        "recurrence": [{
            "recurrence_date": alms_payment_date.isoformat(),
            "expected_payment_date": alms_payment_date.isoformat(),
            "amount": alms_amount,
            "currency": config.CONSTANTS["HOME_CURRENCY"],
            "cleared": False,
            "collections": []
        }]
    }

    alms_payment_scheme_obj = Scheme(alms_payment_scheme_json)

    alms_payment_payment_obj = Payment(alms_payment_json)
    alms_payment_payment_obj.scheme = alms_payment_scheme_obj

    output.append(alms_payment_payment_obj)

    # Flush
    return output