Пример #1
0
def get_request_members_in_project(project, client_order, ym):
    """指定案件の指定注文書の中に、対象のメンバーを取得する。

    :param project: 指定案件
    :param client_order: 指定注文書
    :param ym: 対象年月
    :return: メンバーのリスト
    """
    if client_order.projects.public_filter(is_deleted=False).count() > 1:
        # 一つの注文書に複数の案件がある場合
        projects = client_order.projects.public_filter(is_deleted=False)
        project_members = models.ProjectMember.objects.public_filter(project__in=projects)
    elif project.get_order_by_month(ym[:4], ym[4:]).count() > 1:
        # 1つの案件に複数の注文書ある場合
        project_members = []
        if client_order.member_comma_list:
            # 重複したメンバーを外す。
            member_id_list = sorted(set(client_order.member_comma_list.split(",")))
            first_day = common.get_first_day_from_ym(ym)
            last_day = common.get_last_day_by_month(first_day)
            for pm_id in member_id_list:
                try:
                    project_members.append(
                        models.ProjectMember.objects.get(pk=int(pm_id), is_deleted=False, status=2,
                                                         start_date__lte=last_day,
                                                         end_date__gte=first_day))
                except ObjectDoesNotExist:
                    pass
    else:
        project_members = project.get_project_members_by_month(ym=ym)
    return project_members
Пример #2
0
    def get_pay_date(self, date=timezone.now().today()):
        """支払い期限日を取得する。

        :param date:
        :return:
        """
        months = int(self.payment_month) if self.payment_month else 1
        pay_month = common.add_months(date, months)
        if self.payment_day == '99' or not self.payment_day:
            return common.get_last_day_by_month(pay_month)
        else:
            pay_day = int(self.payment_day)
            last_day = common.get_last_day_by_month(pay_month)
            if last_day.day < pay_day:
                return last_day
            return datetime.date(pay_month.year, pay_month.month, pay_day)
Пример #3
0
def get_request_members_in_project(project, customer_order, year, month):
    """指定案件の指定注文書の中に、対象のメンバーを取得する。

    :param project: 指定案件
    :param customer_order: 指定注文書
    :param year: 対象年
    :param month: 対象月
    :return: メンバーのリスト
    """
    first_day = common.get_first_day_from_ym(year + month)
    last_day = common.get_last_day_by_month(first_day)
    if customer_order.projects.filter(is_deleted=False).count() > 1:
        # 一つの注文書に複数の案件がある場合
        projects = customer_order.projects.filter(is_deleted=False)
        project_members = models.ProjectMember.objects.filter(
            project__in=projects,
            start_date__lte=last_day,
            end_date__gte=first_day,
            is_deleted=False,
        )
    elif project.customerorder_set.filter(start_date__lte=last_day,
                                          end_date__gte=first_day,
                                          is_deleted=False).count() > 1:
        # 1つの案件に複数の注文書ある場合
        raise CustomException(constants.ERROR_NOT_IMPLEMENTED)
    else:
        project_members = project.get_project_members_by_month(year, month)
    return project_members
Пример #4
0
def get_next_change_list():
    """入退場リスト

    :return:
    """
    first_day = common.get_first_day_current_month()
    last_day = common.get_last_day_by_month(first_day)
    next_first_day = common.get_first_day_by_month(common.add_months(first_day, 1))
    next_last_day = common.get_last_day_by_month(next_first_day)
    members = models.Member.objects.public_filter(Q(projectmember__end_date__gte=first_day,
                                                    projectmember__end_date__lte=last_day,
                                                    projectmember__is_deleted=False,
                                                    projectmember__status=2)
                                                  | Q(projectmember__start_date__gte=next_first_day,
                                                      projectmember__start_date__lte=next_last_day,
                                                      projectmember__is_deleted=False,
                                                      projectmember__status=2)).distinct()
    return members.filter(section__is_on_sales=True)
Пример #5
0
def get_user_holidays_by_month(sys_user, year, month):
    used_days = 0
    if sys_user:
        first_day = common.get_first_day_from_ym('%s%02d' % (year, int(month)))
        last_day = common.get_last_day_by_month(first_day)
        used_holidays = models.HolidaysApplication.objects.\
            filter(Q(start_date__gte=first_day) | Q(end_date__lte=last_day),
                   employee=sys_user)
        for holiday in used_holidays:
            used_days += holiday.use_days
    return used_days
Пример #6
0
def cost_subcontractor_members_by_month(year, month):
    first_day = common.get_first_day_from_ym(year + month)
    last_day = common.get_last_day_by_month(first_day)
    queryset = models.MemberAttendance.objects.public_filter(
        Q(project_member__member__bpcontract__end_date__gte=first_day)
        | Q(project_member__member__bpcontract__end_date__isnull=True),
        project_member__member__bpcontract__start_date__lte=last_day,
        year=year,
        month=month,
    ).order_by('project_member__member__first_name',
               'project_member__member__last_name').distinct()
    return queryset
Пример #7
0
 def post(self, request, *args, **kwargs):
     company = Company.get_company()
     partner = models.Partner.objects.get(pk=kwargs.get('pk'))
     project_member = ProjectMember.objects.get(
         pk=kwargs.get('project_member_id'))
     year = request.data.get('year')
     month = request.data.get('month')
     first_day = common.get_first_day_from_ym(year + month)
     last_day = common.get_last_day_by_month(first_day)
     end_date = last_day if last_day <= project_member.end_date else project_member.end_date
     publish_date = datetime.datetime.strptime(
         request.data.get('publish_date'), '%Y-%m-%d')
     end_year = request.data.get('end_year')
     end_month = request.data.get('end_month')
     salesperson = get_member_salesperson_by_month(project_member.member,
                                                   end_date)
     order = models.BpMemberOrder.get_next_bp_order(partner, project_member,
                                                    year, month,
                                                    publish_date, end_year,
                                                    end_month, salesperson)
     order_data = self.get_order_data(
         company=company,
         partner=partner,
         order_no=order.order_no,
         year=year,
         month=month,
         publish_date=publish_date,
         salesperson=salesperson,
         end_year=end_year,
         end_month=end_month,
         project_member=project_member,
     )
     if not order.pk:
         order.created_user = request.user
     order.updated_user = request.user
     order.save(other_data=order_data)
     filename, filename_request = common.get_order_file_path(
         order.order_no, project_member.member.full_name)
     # 注文書
     attachment = self.create_order_file(order, 'partner/member_order.html',
                                         order_data, filename,
                                         order.filename)
     order.filename = attachment.uuid
     # 注文請書
     attachment = self.create_order_file(
         order, 'partner/member_order_request.html', order_data, filename,
         order.filename_request)
     order.filename_request = attachment.uuid
     order.save(update_fields=('filename', 'filename_request'))
     return Response(serializers.BpMemberOrderDisplaySerializer(order).data)
Пример #8
0
def get_project_members_month(date):
    """指定月の案件メンバー全部取得する。

    :param date 指定月
    :return
    """
    first_day = common.get_first_day_by_month(date)
    today = datetime.date.today()
    if date.year == today.year and date.month == today.month:
        first_day = today
    last_day = common.get_last_day_by_month(date)
    return models.ProjectMember.objects.public_filter(end_date__gte=first_day,
                                                      end_date__lte=last_day,
                                                      project__status=4,
                                                      status=2)
Пример #9
0
    def get_project_members_by_month(self, year, month):
        """指定年月に案件にアサインしているメンバー

        :param year:
        :param month:
        :return:
        """
        first_day = common.get_first_day_from_ym(year + month)
        last_day = common.get_last_day_by_month(first_day)
        return self.projectmember_set.filter(
            start_date__lte=last_day,
            end_date__gte=first_day,
            is_deleted=False
        ).exclude(
            status='1'  # 提案中を除外
        )
Пример #10
0
 def get_form(self, request, obj=None, **kwargs):
     form = super(ClientOrderAdmin, self).get_form(request, obj, **kwargs)
     project_id = request.GET.get('project_id', None)
     ym = request.GET.get("ym", None)
     banks = BankInfo.objects.public_all()
     if project_id:
         project = Project.objects.public_filter(pk=project_id)
         form.base_fields['projects'].initial = project
         form.base_fields['name'].initial = project[0].name if project.count() > 0 else ""
     if ym:
         first_day = common.get_first_day_from_ym(ym)
         form.base_fields['start_date'].initial = first_day
         form.base_fields['end_date'].initial = common.get_last_day_by_month(first_day)
     if banks.count() > 0:
         form.base_fields['bank_info'].initial = banks[0]
     return form
Пример #11
0
def get_working_members(date=None):
    """稼働中のメンバー

    :param date: 対象年月
    :return:
    """
    if not date:
        first_day = last_day = datetime.date.today()
    else:
        first_day = common.get_first_day_by_month(date)
        last_day = common.get_last_day_by_month(date)
    members = get_sales_members().filter(projectmember__start_date__lte=last_day,
                                         projectmember__end_date__gte=first_day,
                                         projectmember__is_deleted=False,
                                         projectmember__status=2).distinct()
    return members
Пример #12
0
 def get_form(self, request, obj=None, **kwargs):
     form = super(ClientOrderAdmin, self).get_form(request, obj, **kwargs)
     project_id = request.GET.get('project_id', None)
     ym = request.GET.get("ym", None)
     banks = models.BankInfo.objects.public_all()
     if project_id:
         project = models.Project.objects.public_filter(pk=project_id)
         form.base_fields['projects'].initial = project
         form.base_fields['name'].initial = project[
             0].name if project.count() > 0 else ""
     if ym:
         first_day = common.get_first_day_from_ym(ym)
         form.base_fields['start_date'].initial = first_day
         form.base_fields[
             'end_date'].initial = common.get_last_day_by_month(first_day)
     if banks.count() > 0:
         form.base_fields['bank_info'].initial = banks[0]
     return form
Пример #13
0
def get_projects_orders(ym, q=None, o=None):
    """案件の注文情報を取得する。

    :param ym:対象年月
    :param q:絞り込み条件
    :param o:並び順
    :return:
    """
    first_day = common.get_first_day_from_ym(ym)
    last_day = common.get_last_day_by_month(first_day)

    project_orders = models.ClientOrder.projects.through.objects\
        .filter(Q(clientorder__isnull=True) | Q(clientorder__start_date__lte=last_day,
                                                clientorder__end_date__gte=first_day),
                project__start_date__lte=last_day,
                project__end_date__gte=first_day).distinct()

    if q:
        if 'project__projectrequest__request_no__contains' in q:
            q.update({'project__projectrequest__year': ym[:4],
                      'project__projectrequest__month': ym[4:]})
        project_orders = project_orders.filter(**q)

    order_by_request_no = None
    if o:
        if 'project__projectrequest__request_no' in o:
            order_by_request_no = 'ASC'
            o.remove('project__projectrequest__request_no')
        elif '-project__projectrequest__request_no' in o:
            order_by_request_no = 'DESC'
            o.remove('-project__projectrequest__request_no')
        project_orders = project_orders.order_by(*o)

    all_project_orders = []
    for project_order in project_orders:
        project_request = project_order.project.get_project_request(ym[:4], ym[4:], project_order.clientorder)
        all_project_orders.append((project_order.project, project_request, project_order.clientorder))
    if order_by_request_no == 'ASC':
        all_project_orders.sort(key=lambda d: d[1].request_no)
    elif order_by_request_no == 'DESC':
        all_project_orders.sort(key=lambda d: d[1].request_no, reverse=True)
    return all_project_orders
Пример #14
0
def get_partner_member_contract(partner, member, year=None, month=None):
    """協力社員の契約を取得

    :param partner: 協力会社
    :param member: 社員
    :param year: 対象年
    :param month: 対象月
    :return:
    """
    try:
        first_day = common.get_first_day_from_ym(year + month)
        last_day = common.get_last_day_by_month(first_day)
        return models.BpContract.objects.get(
            Q(end_date__gte=first_day) | Q(end_date__isnull=True),
            start_date__lte=last_day,
            company=partner,
            member=member,
        )
    except ObjectDoesNotExist:
        raise CustomException(constants.ERROR_NO_PARTNER_CONTRACT.format(name=member, company=partner))
    except MultipleObjectsReturned:
        raise CustomException(constants.ERROR_MULTI_PARTNER_CONTRACT.format(name=member, company=partner))
Пример #15
0
def cost_subcontractors_by_month(year, month):
    first_day = common.get_first_day_from_ym(year + month)
    last_day = common.get_last_day_by_month(first_day)
    queryset = models.MemberAttendance.objects.public_filter(
        Q(project_member__member__bpcontract__end_date__gte=first_day)
        | Q(project_member__member__bpcontract__end_date__isnull=True),
        project_member__member__bpcontract__start_date__lte=last_day,
        year=year,
        month=month,
    ).order_by(
        'project_member__member__subcontractor').distinct().prefetch_related(
            'project_member__member__subcontractor', )

    subcontractors = dict()
    for member_attendance in queryset:
        cost = member_attendance.get_all_cost()
        if member_attendance.project_member.member.subcontractor in subcontractors:
            subcontractors[
                member_attendance.project_member.member.subcontractor] += cost
        else:
            subcontractors[
                member_attendance.project_member.member.subcontractor] = cost
    return subcontractors.items()
Пример #16
0
def batch_sync_contract(batch):
    logger = batch.get_logger()
    # 契約社員の契約情報だけを抽出する。
    query_set = contract_models.Contract.objects.public_all().annotate(
        max_contract_no=Subquery(
            contract_models.Contract.objects.public_filter(
                is_deleted=False,
                member=OuterRef('member'),
                start_date__lte=OuterRef('start_date')).exclude(
                    status__in=['04', '05']).order_by('-contract_no').values(
                        'contract_no')[:1],
            output_field=CharField()),
        first_start_date=Subquery(
            contract_models.Contract.objects.public_filter(
                is_deleted=False, member=OuterRef('member')).exclude(
                    status__in=['04', '05']).order_by('start_date').values(
                        'start_date')[:1],
            output_field=DateField()),
    ).exclude(status__in=['04', '05']).order_by('member_id', 'contract_no',
                                                'start_date').prefetch_related(
                                                    Prefetch('member'), )
    today = datetime.date.today()
    count = query_set.count()
    for i, contract in enumerate(query_set):
        if contract.member.pk == 609:
            pass
        if contract.contract_no == contract.max_contract_no:
            if contract.start_date == contract.first_start_date and contract.join_date is None:
                contract.join_date = contract.start_date
                contract.save(update_fields=['join_date'])
                logger.info(u'%s: %sの入社日が%sに設定しました。' %
                            (unicode(contract.member), contract.contract_no,
                             contract.join_date))
            filters = {
                'member': contract.member,
                'start_date__gt': contract.start_date,
                'status__in': ['01', '02', '03', '05']
            }
            if contract.member.is_retired and contract.member.retired_date is None:
                # すでに退職で、かつ退職日が入れてない場合はスキップする。
                continue
            elif contract.retired_date:
                # 退職した場合はスキップする。
                continue
            elif contract.member_type == 1:
                # 正社員の場合、契約終了日を再設定する。
                if i + 1 < count and contract.member.pk == query_set[
                        i + 1].member.pk:
                    end_date = query_set[i +
                                         1].start_date + datetime.timedelta(
                                             days=-1)
                    if contract.end_date is None and contract.end_date2 is None:
                        contract.end_date2 = end_date
                        contract.save(update_fields=['end_date2'])
                        logger.info(u'%s: %sの雇用終了日(%s)が再設定しました。',
                                    unicode(contract.member),
                                    contract.contract_no, contract.end_date2)
            elif i + 1 < count and contract.member.pk == query_set[
                    i + 1].member.pk:
                # 新しい契約が存在する場合
                if contract.end_date is None:
                    # 契約終了日が空白の場合はスキップする。
                    continue
                if query_set[
                        i +
                        1].start_date == contract.end_date + datetime.timedelta(
                            days=1):
                    # 新しい契約との契約期間が連続の場合はスキップする。
                    continue
                if query_set[i + 1].start_date < contract.end_date:
                    # 契約期間が重複した場合は契約終了日を再設定する。
                    end_date = query_set[i +
                                         1].start_date + datetime.timedelta(
                                             days=-1)
                    if contract.end_date2 is not None and contract.end_date2 == end_date:
                        continue
                    contract.end_date2 = end_date
                    contract.save(update_fields=['end_date2'])
                    logger.info(u'%s: %sの雇用終了日(%s)が再設定しました。',
                                unicode(contract.member), contract.contract_no,
                                contract.end_date2)
                    continue
                filters['start_date__lt'] = query_set[i + 1].start_date
                filters['contract_no__gte'] = contract.contract_no

                auto_contract_set = contract_models.Contract.objects.public_filter(
                    **filters).order_by('contract_no')
                if auto_contract_set.count() == 0:
                    contract.start_date = contract.end_date + datetime.timedelta(
                        days=1)
                    contract.end_date = query_set[
                        i + 1].start_date + datetime.timedelta(days=-1)
                    contract.status = '05'
                    contract.pk = None
                    contract.save()
                    logger.info(u'%s: %sの契約期間(%s~%s)が自動追加しました。',
                                unicode(contract.member), contract.contract_no,
                                contract.start_date, contract.end_date)
            elif contract.end_date and contract.end_date < today:
                # 新しい契約が存在しない場合
                filters['start_date__lt'] = common.get_last_day_by_month(today)
                auto_contract_set = contract_models.Contract.objects.public_filter(
                    **filters).order_by('-contract_no', '-start_date')
                if auto_contract_set.count() == 0:
                    # 自動更新された契約もない場合、今月末まで更新する。
                    contract.start_date = contract.end_date + datetime.timedelta(
                        days=1)
                    if contract.member.is_retired and contract.member.retired_date:
                        end_date = contract.member.retired_date
                        contract.retired_date = end_date
                    else:
                        end_date = filters['start_date__lt']
                    contract.end_date = end_date
                    contract.status = '05'
                    contract.pk = None
                    contract.save()
                    logger.info(
                        u'%s: %sが自動更新しました。' %
                        (unicode(contract.member), contract.contract_no))
                else:
                    # 自動更新された契約が存在する場合、今月末まで足りない期間分の契約を追加する。
                    if auto_contract_set[0].retired_date is not None:
                        # 退職済みの場合はスキップする。
                        continue
                    last_end_date = auto_contract_set[0].end_date
                    if last_end_date < filters['start_date__lt']:
                        contract.start_date = last_end_date + datetime.timedelta(
                            days=1)
                        contract.end_date = filters['start_date__lt']
                        contract.status = '05'
                        contract.pk = None
                        contract.save()
                        logger.info(
                            u'%s: %sが自動更新しました。' %
                            (unicode(contract.member), contract.contract_no))
Пример #17
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
Пример #18
0
def generate_partner_order_heading(
        company, partner, contract, year, month, publish_date, interval, salesperson,
        project_member=None,
):
    first_day = common.get_first_day_from_ym(year + month)
    last_day = common.get_last_day_by_month(first_day)
    data = dict()
    if project_member is not None:
        project = project_member.project
        member = project_member.member
        start_date = first_day if first_day >= project_member.start_date else project_member.start_date
        end_date = last_day if last_day <= project_member.end_date else project_member.end_date
    else:
        # 一括の場合
        project = contract.project
        member = None
        data['delivery_date'] = contract.delivery_date
        data['project_content'] = contract.project_content
        data['workload'] = contract.workload
        data['project_result'] = contract.project_result
        data['allowance_base'] = contract.get_cost()
        data['allowance_base_tax'] = contract.allowance_base_tax
        data['allowance_base_total'] = contract.allowance_base_total
        start_date = project.start_date
        end_date = project.end_date
    data['publish_date'] = publish_date.strftime('%Y-%m-%d') \
        if isinstance(publish_date, (datetime.date, datetime.datetime)) else publish_date
    data['partner_name'] = partner.name
    data['partner_post_code'] = partner.post_code
    data['partner_address1'] = partner.address1
    data['partner_address2'] = partner.address2
    data['partner_tel'] = partner.tel
    data['partner_fax'] = partner.fax
    # 本社情報
    data['company_name'] = company.name
    data['company_tel'] = company.tel
    data['company_address1'] = company.address1
    data['company_address2'] = company.address2
    # 案件情報
    data['project_name'] = project.name
    data['start_date'] = start_date
    data['end_date'] = end_date
    data['master'] = company.president
    data['middleman'] = salesperson.full_name if salesperson else None
    data['partner_master'] = partner.president
    data['partner_middleman'] = partner.middleman
    data['member_name'] = member.full_name if member else None
    data['location'] = project.address if project.address else constants.LABEL_BP_ORDER_DEFAULT_LOCATION
    # 精算情報
    data['is_hourly_pay'] = contract.is_hourly_pay
    if project_member is not None:
        data['is_fixed_cost'] = contract.is_fixed_cost
        data['is_show_formula'] = contract.is_show_formula
        data['calculate_type_comment'] = contract.get_calculate_type_comment()
        data['allowance_base'] = contract.get_cost() * interval
        data['allowance_base_memo'] = contract.allowance_base_memo
        if interval > 1:
            data['allowance_base_memo'] = "基本料金:¥{}円  ({}税金抜き)".format(
                humanize.intcomma(data['allowance_base']),
                '固定、' if contract.is_fixed_cost else '',
            )
        data['allowance_time_min'] = contract.get_allowance_time_min(year, month)
        data['allowance_time_max'] = contract.allowance_time_max
        data['allowance_time_memo'] = contract.get_allowance_time_memo(year, month)
        data['allowance_overtime'] = contract.allowance_overtime
        data['allowance_overtime_memo'] = contract.allowance_overtime_memo
        data['allowance_absenteeism'] = contract.get_allowance_absenteeism(year, month)
        data['allowance_absenteeism_memo'] = contract.get_allowance_absenteeism_memo(year, month)
        data['allowance_other'] = contract.allowance_other
        data['allowance_other_memo'] = contract.get_allowance_other_memo()
        data['delivery_properties_comment'] = Config.get_bp_order_delivery_properties()
        data['payment_condition_comments'] = Config.get_bp_order_payment_condition()
        data['contract_items_comments'] = Config.get_bp_order_contract_items()
    data['comment'] = contract.comment
    return data
Пример #19
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