Exemplo n.º 1
0
def generate_order_data(company, subcontractor, user, ym):
    """註文書を生成するために使うデータを生成する。

    :param company 発注元会社
    :param subcontractor 発注先
    :param user ログインしているユーザ
    :param ym 対象年月
    :return エクセルのバイナリー
    """
    data = {'DETAIL': {}}
    # 発行年月日
    date = datetime.date.today()
    data['DETAIL']['PUBLISH_DATE'] = u"%s年%02d月%02d日" % (date.year, date.month, date.day)
    # 下請け会社名
    data['DETAIL']['SUBCONTRACTOR_NAME'] = subcontractor.name
    # 委託業務責任者(乙)
    data['DETAIL']['SUBCONTRACTOR_MASTER'] = subcontractor.president
    # 作成者
    salesperson = get_user_profile(user)
    data['DETAIL']['AUTHOR_FIRST_NAME'] = salesperson.first_name if salesperson else ''
    # 会社名
    data['DETAIL']['COMPANY_NAME'] = company.name
    # 本社郵便番号
    data['DETAIL']['POST_CODE'] = common.get_full_postcode(company.post_code)
    # 本社電話番号
    data['DETAIL']['TEL'] = company.tel
    # 代表取締役
    member = company.get_master()
    data['DETAIL']['MASTER'] = u"%s %s" % (member.first_name, member.last_name) if member else ""
    # 本社住所
    data['DETAIL']['ADDRESS1'] = company.address1
    data['DETAIL']['ADDRESS2'] = company.address2
    # 作業期間
    if not ym:
        first_day = common.get_first_day_current_month()
    else:
        first_day = common.get_first_day_from_ym(ym)
    last_day = common.get_last_day_by_month(first_day)
    data['DETAIL']['START_DATE'] = u"%s年%02d月%02d日" % (first_day.year, first_day.month, first_day.day)
    data['DETAIL']['END_DATE'] = u"%s年%02d月%02d日" % (last_day.year, last_day.month, last_day.day)

    members = []
    # 全ての協力社員の注文情報を取得する。
    for member in subcontractor.get_members_by_month(first_day):
        bp_member_info = member.get_bp_member_info(first_day)
        members.append({'ITEM_NAME': member.__unicode__(),  # 協力社員名前
                        'ITEM_COST': humanize.intcomma(member.cost),  # 月額基本料金
                        'ITEM_MIN_HOUR': humanize.intcomma(bp_member_info.min_hours),  # 基準時間(最小値)
                        'ITEM_MAX_HOUR': humanize.intcomma(bp_member_info.max_hours),  # 基準時間(最大値)
                        'ITEM_PLUS_PER_HOUR': humanize.intcomma(bp_member_info.plus_per_hour),  # 超過単価
                        'ITEM_MINUS_PER_HOUR': humanize.intcomma(bp_member_info.minus_per_hour),  # 不足単価
                        })
    data['MEMBERS'] = members

    # 注文情報を追加する
    try:
        order = models.SubcontractorOrder.objects.get(subcontractor=subcontractor,
                                                      year=str(first_day.year),
                                                      month="%02d" % (first_day.month,))
        data['DETAIL']['ORDER_NO'] = order.order_no
        order.updated_user = user
    except ObjectDoesNotExist:
        data['DETAIL']['ORDER_NO'] = get_order_no(user)
        order = models.SubcontractorOrder(subcontractor=subcontractor,
                                          order_no=data['DETAIL']['ORDER_NO'],
                                          year=str(first_day.year),
                                          month="%02d" % (first_day.month,))
        order.created_user = user
    order.save()
    return data
Exemplo n.º 2
0
def generate_request_data(company, project, client_order, bank_info, ym, project_request):
    first_day = common.get_first_day_from_ym(ym)
    last_day = common.get_last_day_by_month(first_day)
    data = {'DETAIL': {}, 'EXTRA': {}}
    data['EXTRA']['YM'] = ym
    # お客様郵便番号
    data['DETAIL']['CLIENT_POST_CODE'] = common.get_full_postcode(project.client.post_code)
    # お客様住所
    data['DETAIL']['CLIENT_ADDRESS'] = project.client.address1 + project.client.address2
    # お客様電話番号
    data['DETAIL']['CLIENT_TEL'] = project.client.tel
    # お客様名称
    data['DETAIL']['CLIENT_COMPANY_NAME'] = project.client.name
    # 作業期間
    data['DETAIL']['WORK_PERIOD'] = first_day.strftime(u'%Y年%m月%d日'.encode('utf-8')).decode('utf-8') + u" ~ " + last_day.strftime(u'%Y年%m月%d日'.encode('utf-8')).decode('utf-8')
    data['EXTRA']['WORK_PERIOD_START'] = first_day
    data['EXTRA']['WORK_PERIOD_END'] = last_day
    # 注文番号
    data['DETAIL']['ORDER_NO'] = client_order.order_no if client_order.order_no else u""
    # 注文日
    data['DETAIL']['REQUEST_DATE'] = client_order.order_date.strftime('%Y/%m/%d') if client_order.order_date else ""
    # 契約件名
    data['DETAIL']['CONTRACT_NAME'] = project_request.request_name
    # お支払い期限
    data['DETAIL']['REMIT_DATE'] = project.client.get_pay_date(date=first_day).strftime('%Y/%m/%d')
    data['EXTRA']['REMIT_DATE'] = project.client.get_pay_date(date=first_day)
    # 請求番号
    data['DETAIL']['REQUEST_NO'] = project_request.request_no
    # 発行日(対象月の最終日)
    data['DETAIL']['PUBLISH_DATE'] = last_day.strftime(u"%Y年%m月%d日".encode('utf-8')).decode('utf-8')
    data['EXTRA']['PUBLISH_DATE'] = last_day
    # 本社郵便番号
    data['DETAIL']['POST_CODE'] = common.get_full_postcode(company.post_code)
    # 本社住所
    data['DETAIL']['ADDRESS'] = company.address1 + company.address2
    # 会社名
    data['DETAIL']['COMPANY_NAME'] = company.name
    # 代表取締役
    member = company.get_master()
    data['DETAIL']['MASTER'] = u"%s %s" % (member.first_name, member.last_name) if member else ""
    # 本社電話番号
    data['DETAIL']['TEL'] = company.tel
    # 振込先銀行名称
    data['EXTRA']['BANK'] = bank_info
    data['DETAIL']['BANK_NAME'] = bank_info.bank_name if bank_info else u""
    # 支店番号
    data['DETAIL']['BRANCH_NO'] = bank_info.branch_no if bank_info else u""
    # 支店名称
    data['DETAIL']['BRANCH_NAME'] = bank_info.branch_name if bank_info else u""
    # 預金種類
    data['DETAIL']['ACCOUNT_TYPE'] = bank_info.get_account_type_display() if bank_info else u""
    # 口座番号
    data['DETAIL']['ACCOUNT_NUMBER'] = bank_info.account_number if bank_info else u""
    # 口座名義人
    data['DETAIL']['BANK_ACCOUNT_HOLDER'] = bank_info.account_holder if bank_info else u""

    # 全員の合計明細
    detail_all = dict()
    # メンバー毎の明細
    detail_members = []

    project_members = get_request_members_in_project(project, client_order, ym)
    members_amount = 0
    if project.is_lump:
        members_amount = project.lump_amount
        # 番号
        detail_all['NO'] = u"1"
        # 項目:契約件名に設定
        detail_all['ITEM_NAME_ATTENDANCE_TOTAL'] = data['DETAIL']['CONTRACT_NAME']
        # 数量
        detail_all['ITEM_COUNT'] = u"1"
        # 単位
        detail_all['ITEM_UNIT'] = u"一式"
        # 金額
        detail_all['ITEM_AMOUNT_ATTENDANCE_ALL'] = members_amount
        # 備考
        detail_all['ITEM_COMMENT'] = project.lump_comment if project.is_lump else u""
    else:
        for i, project_member in enumerate(project_members):
            dict_expenses = dict()
            # この項目は請求書の出力ではなく、履歴データをProjectRequestDetailに保存するために使う。
            dict_expenses["EXTRA_PROJECT_MEMBER"] = project_member
            # 番号
            dict_expenses['NO'] = str(i + 1)
            # 項目
            dict_expenses['ITEM_NAME'] = project_member.member.__unicode__()
            # 時給の場合
            if project.is_hourly_pay:
                # 単価(円)
                dict_expenses['ITEM_PRICE'] = project_member.hourly_pay
                # Min/Max(H)
                dict_expenses['ITEM_MIN_MAX'] = u""
            else:
                # 単価(円)
                dict_expenses['ITEM_PRICE'] = project_member.price
                # Min/Max(H)
                dict_expenses['ITEM_MIN_MAX'] = "%s/%s" % (int(project_member.min_hours), int(project_member.max_hours))
            dict_expenses.update(project_member.get_attendance_dict(first_day.year, first_day.month))
            # 金額合計
            members_amount += dict_expenses['ITEM_AMOUNT_TOTAL']
            detail_members.append(dict_expenses)

    detail_expenses, expenses_amount = get_request_expenses_list(project,
                                                                 first_day.year,
                                                                 '%02d' % (first_day.month,),
                                                                 project_members)

    data['detail_all'] = detail_all
    data['MEMBERS'] = detail_members
    data['EXPENSES'] = detail_expenses  # 清算リスト
    data['DETAIL']['ITEM_AMOUNT_ATTENDANCE'] = members_amount
    if project.client.decimal_type == '0':
        data['DETAIL']['ITEM_AMOUNT_ATTENDANCE_TAX'] = int(round(members_amount * project.client.tax_rate))
    else:
        # 出勤のトータル金額の税金
        data['DETAIL']['ITEM_AMOUNT_ATTENDANCE_TAX'] = int(members_amount * project.client.tax_rate)
    data['DETAIL']['ITEM_AMOUNT_ATTENDANCE_ALL'] = members_amount + int(data['DETAIL']['ITEM_AMOUNT_ATTENDANCE_TAX'])
    data['DETAIL']['ITEM_AMOUNT_ALL'] = int(data['DETAIL']['ITEM_AMOUNT_ATTENDANCE_ALL']) + expenses_amount
    data['DETAIL']['ITEM_AMOUNT_ALL_COMMA'] = humanize.intcomma(data['DETAIL']['ITEM_AMOUNT_ALL'])

    project_request.amount = data['DETAIL']['ITEM_AMOUNT_ALL']
    project_request.turnover_amount = members_amount
    project_request.tax_amount = data['DETAIL']['ITEM_AMOUNT_ATTENDANCE_TAX']
    project_request.expenses_amount = expenses_amount

    return data
Exemplo n.º 3
0
def generate_request_heading(company, project, customer_order, year, month,
                             initial):
    first_day = common.get_first_day_from_ym(year + month)
    first_day = project.start_date if project.start_date > first_day else first_day
    last_day = common.get_last_day_from_ym(year + month)
    last_day = project.end_date if project.end_date < last_day else last_day
    data = dict()
    # 代表取締役
    data['MASTER'] = company.president
    # お客様郵便番号
    data['CUSTOMER_POST_CODE'] = common.get_full_postcode(
        project.customer.post_code)
    # お客様住所
    data['CUSTOMER_ADDRESS'] = (project.customer.address1
                                or '') + (project.customer.address2 or '')
    # お客様電話番号
    data['CUSTOMER_TEL'] = project.customer.tel or ''
    # お客様名称
    data['CUSTOMER_COMPANY_NAME'] = project.customer.name
    # 作業期間
    f = '%Y{0}%m{1}%d{2}'
    period_start = first_day.strftime(f).format(*'年月日')
    period_end = last_day.strftime(f).format(*'年月日')
    data['WORK_PERIOD'] = period_start + " ~ " + period_end
    data['WORK_PERIOD_START'] = first_day
    data['WORK_PERIOD_END'] = last_day
    # 注文番号
    if initial and 'order_no' in initial:
        data['ORDER_NO'] = initial.get('order_no')
    else:
        data[
            'ORDER_NO'] = customer_order.order_no if customer_order.order_no else ""
    # 注文日
    data['REQUEST_DATE'] = customer_order.order_date.strftime(
        '%Y/%m/%d') if customer_order.order_date else ""
    # 契約件名
    if initial and 'contract_name' in initial:
        data['CONTRACT_NAME'] = initial.get('contract_name')
    else:
        data['CONTRACT_NAME'] = customer_order.name
    # お支払い期限
    data['REMIT_DATE'] = project.customer.get_pay_date(
        date=first_day).strftime('%Y/%m/%d')
    data['REMIT_DATE_PURE'] = project.customer.get_pay_date(date=first_day)
    # # 請求番号
    # data['REQUEST_NO'] = project.get_next_request_no(year, month)
    # 発行日(対象月の最終日)
    data['PUBLISH_DATE'] = last_day.strftime(f).format(*'年月日')
    data['PUBLISH_DATE_PURE'] = last_day
    # 本社郵便番号
    data['POST_CODE'] = common.get_full_postcode(company.post_code)
    # 本社住所
    data['ADDRESS'] = (company.address1 or '') + (company.address2 or '')
    # 会社名
    data['COMPANY_NAME'] = company.name
    # 本社電話番号
    data['TEL'] = company.tel
    if initial and 'bank_account' in initial:
        bank_account = initial.get('bank_account')
    else:
        bank_account = customer_order.bank_account
    data['BANK_ACCOUNT'] = bank_account
    # 振込先銀行名称
    data['BANK_NAME'] = bank_account.bank.name if bank_account else ""
    # 支店番号
    data['BRANCH_NO'] = bank_account.branch_no if bank_account else ""
    # 支店名称
    data['BRANCH_NAME'] = bank_account.branch_name if bank_account else ""
    # 預金種類
    data['ACCOUNT_TYPE'] = bank_account.get_account_type_display(
    ) if bank_account else ""
    data[
        'ACCOUNT_TYPE_PURE'] = bank_account.account_type if bank_account else ""
    # 口座番号
    data[
        'ACCOUNT_NUMBER'] = bank_account.account_number if bank_account else ""
    # 口座名義人
    data[
        'BANK_ACCOUNT_HOLDER'] = bank_account.account_holder if bank_account else ""

    return data