Exemplo n.º 1
0
def save_connection(request):
    form = forms.create_clients(request.POST)

    if form.is_valid():
        company_name = form.cleaned_data["company"]
        company = Company.objects.filter(name=str(company_name))
        if company.first() is None:
            #form = form.save()
            company_table = Company(
                name=form.cleaned_data["company"],
                mail=form.cleaned_data["mail"],
                tel=form.cleaned_data["TEL"],
                web_site_link=form.cleaned_data["web"],
                industry=form.cleaned_data["industry"],
                address=form.cleaned_data["address"],
            )
            company_table.save()
        stage = Client_stage.objects.values('id').filter(
            stage=form.cleaned_data["stage"])

        new_id = Company.objects.values('id').filter(name=company_name)
        #連絡先をupdateする
        Connection.objects.filter(id=form.cleaned_data["index"]).update(
            clients_name=form.cleaned_data["name"],
            company_id=new_id[0]["id"],
            clients_mail=form.cleaned_data["mail"],
            tel=form.cleaned_data["TEL"],
            web_site_link=form.cleaned_data["web"],
            stage_id=stage[0]["id"],
            industry=form.cleaned_data["industry"],
            annual_revenue=form.cleaned_data["revenue"],
            accuracy=form.cleaned_data["accuracy"],
            address=form.cleaned_data["address"],
            memo1=form.cleaned_data["memo1"],
            memo2=form.cleaned_data["memo2"],
        )
        # connection_table = Connection(clients_name=form.cleaned_data["name"],
        #            company_id = new_id[0]["id"],
        #            clients_mail=form.cleaned_data["mail"],
        #            tel=form.cleaned_data["TEL"],
        #            web_site_link=form.cleaned_data["web"],
        #            stage_id=form.cleaned_data["stage"],
        #            industry=form.cleaned_data["industry"],
        #            annual_revenue=form.cleaned_data["revenue"],
        #            accuracy=form.cleaned_data["accuracy"],
        #            address=form.cleaned_data["address"],
        #            memo1=form.cleaned_data["memo1"],
        #            memo2=form.cleaned_data["memo2"],
        #            )
        #
        # form = form.save()
    return redirect('connection')
Exemplo n.º 2
0
def save_client(request):

    today = dt.datetime.now()
    #登録された見込み客の情報を受け取る
    form = forms.create_clients(request.POST)
    #フォームに正しい値が入力されていたら
    if form.is_valid():
        #企業名を取得
        company_name = form.cleaned_data["company"]
        #Companyテーブルの中から企業名が一致するレコードを取得
        company = Company.objects.filter(name=str(company_name))
        #レコードがなければ(登録されていない企業なら)
        if company.first() is None:
            #form = form.save()
            #新しい企業のレコードをinsert
            company_table = Company(
                name=form.cleaned_data["company"],
                mail=form.cleaned_data["mail"],
                tel=form.cleaned_data["TEL"],
                web_site_link=form.cleaned_data["web"],
                industry=form.cleaned_data["industry"],
                address=form.cleaned_data["address"],
            )
            #レコードを保存
            company_table.save()
        #入力されたステージIDと一致するステージを取得
        stage = Client_stage.objects.values('id').filter(
            stage=form.cleaned_data["stage"])
        #フォームから取得した企業名と一致するレコードのidを取得
        new_id = Company.objects.values('id').filter(name=company_name)
        #見込み客をinsert
        clients_table = Clients(
            clients_name=form.cleaned_data["name"],
            company_id=new_id[0]["id"],
            clients_mail=form.cleaned_data["mail"],
            tel=form.cleaned_data["TEL"],
            web_site_link=form.cleaned_data["web"],
            stage_id=stage[0]["id"],
            industry=form.cleaned_data["industry"],
            annual_revenue=form.cleaned_data["revenue"],
            accuracy=form.cleaned_data["accuracy"],
            address=form.cleaned_data["address"],
            memo1=form.cleaned_data["memo1"],
            memo2=form.cleaned_data["memo2"],
        )
        #レコードを保存
        clients_table.save()
        # form = form.save()

    return redirect('client')
Exemplo n.º 3
0
def to_connection(request):
    today = dt.datetime.now()
    form = forms.create_clients(request.POST)

    if form.is_valid():
        company_name = form.cleaned_data["company"]
        company = Company.objects.filter(name=str(company_name))
        if company.first() is None:
            company_table = Company(
                name=form.cleaned_data["company"],
                mail=form.cleaned_data["mail"],
                tel=form.cleaned_data["TEL"],
                web_site_link=form.cleaned_data["web"],
                industry=form.cleaned_data["industry"],
                address=form.cleaned_data["address"],
            )
            company_table.save()
        stage = Client_stage.objects.values('id').filter(
            stage=form.cleaned_data["stage"])

        new_id = Company.objects.values('id').filter(name=company_name)
        #Connectionテーブルに見込み客情報をinsert
        connection_table = Connection(
            clients_name=form.cleaned_data["name"],
            company_id=new_id[0]["id"],
            clients_mail=form.cleaned_data["mail"],
            tel=form.cleaned_data["TEL"],
            web_site_link=form.cleaned_data["web"],
            stage_id=stage[0]["id"],
            industry=form.cleaned_data["industry"],
            annual_revenue=form.cleaned_data["revenue"],
            accuracy=form.cleaned_data["accuracy"],
            address=form.cleaned_data["address"],
            memo1=form.cleaned_data["memo1"],
            memo2=form.cleaned_data["memo2"],
        )
        connection_table.save()

        index = form.cleaned_data["index"]
        #連絡先に追加した見込み客情報をClientsテーブルから削除
        Clients.objects.filter(id=index).delete()
        # form = form.save()

    return redirect('client')
Exemplo n.º 4
0
def save_business_talk(request):
    if request.method == "POST":
        form = forms.create_business_talk(request.POST)
        if form.is_valid():
            company_name = form.cleaned_data["company"]
            company = Company.objects.filter(name=str(company_name))
            if company.first() is None:
                company_table = Company(
                    name=form.cleaned_data["company"],
                    mail=form.cleaned_data["mail"],
                    tel=form.cleaned_data["tel"],
                    web_site_link=form.cleaned_data["web"],
                    industry=form.cleaned_data["industry"],
                    address=form.cleaned_data["address"],
                )
                company_table.save()
            # return render(request, 'login/log.html', {'log': form.cleaned_data["stage"]})
            new_id = Company.objects.values('id').filter(name=company_name)
            stage = Business_talk_stage.objects.values('id').filter(
                stage=form.cleaned_data["stage"])
            next_step = Business_talk_stage.objects.values('id').filter(
                stage=form.cleaned_data["next_step"])
            #フォームに入力された商談情報をinsert
            business_talk_table = Business_talk(
                name=form.cleaned_data["name"],
                company_id=new_id[0]["id"],
                tel=form.cleaned_data["tel"],
                mail=form.cleaned_data["mail"],
                client_representive=form.cleaned_data["client_name"],
                web_site_link=form.cleaned_data["web"],
                date=form.cleaned_data["date"],
                stage_id=stage[0]["id"],
                accuracy=form.cleaned_data["accuracy"],
                next_step=next_step[0]["id"],
                content=form.cleaned_data["content"],
                memo1=form.cleaned_data["memo1"],
                memo2=form.cleaned_data["memo2"],
                complete=int(b),
            )
            business_talk_table.save()
            return redirect('business_talk')
        return render(request, 'login/log.html', {'log': form})
Exemplo n.º 5
0
def insert_company(data):
    c = Company(**data)
    c.save()
    return c.id
Exemplo n.º 6
0
def finish(request):
    usermail = request.session.get('user_mail')
    cnamech1 = request.POST.get('cnamech1')
    cnameeg1 = request.POST.get('cnameeg1')
    cnamech2 = request.POST.get('cnamech2')
    cnameeg2 = request.POST.get('cnameeg2')
    addressen = request.POST.get('addressen')
    addressch = request.POST.get('addressch')
    czipcode = request.POST.get('czipcode')
    if request.session.get('is_login', None) == None:
        message = {'message': '非法', 'suc': 'timeout'}
    else:
        try:
            lookfor = Company.objects.filter(cnamech1=cnamech1,
                                             cnamech2=cnamech2,
                                             cnameeg1=cnameeg1,
                                             cnameeg2=cnameeg2,
                                             addressch=addressch,
                                             addressen=addressen,
                                             czipcode=czipcode)
            if lookfor:
                lookfor1 = Company.objects.get(cnamech1=cnamech1,
                                               cnamech2=cnamech2,
                                               cnameeg1=cnameeg1,
                                               cnameeg2=cnameeg2,
                                               addressch=addressch,
                                               addressen=addressen,
                                               czipcode=czipcode)
                findaid = Author.objects.get(amail=usermail)
                new_ac = AuthorCompany(acorder=1,
                                       accurrent=True,
                                       author=findaid,
                                       company=lookfor1)
                new_ac.save()
                account.objects.filter(umail=usermail).update(uall=True)
                request.session['uall'] = True
                message = {'message': '已为您录入基本信息', 'suc': 'yes'}
            else:
                new_com = Company(cnamech1=cnamech1,
                                  cnamech2=cnamech2,
                                  cnameeg1=cnameeg1,
                                  cnameeg2=cnameeg2,
                                  addressch=addressch,
                                  addressen=addressen,
                                  czipcode=czipcode)
                new_com.save()
                findcid = Company.objects.get(cnamech1=cnamech1,
                                              cnamech2=cnamech2,
                                              cnameeg1=cnameeg1,
                                              cnameeg2=cnameeg2,
                                              addressch=addressch,
                                              addressen=addressen,
                                              czipcode=czipcode)
                findaid = Author.objects.get(amail=usermail)
                new_ac = AuthorCompany(acorder=1,
                                       accurrent=True,
                                       author=findaid,
                                       company=findcid)
                new_ac.save()
                account.objects.filter(umail=usermail).update(uall=True)
                request.session['uall'] = True
                message = {'message': '已为您录入基本信息', 'suc': 'yes'}
        except:
            message = {'message': '服务器内部错误', 'suc': 'no'}
    return JsonResponse(message)
Exemplo n.º 7
0
def import_clients(request):
    if request.method == 'POST':
        form = forms.UploadFileForm2(request.POST, request.FILES)
        if form.is_valid():
            #ファイルが選択されていれば
            if 'file' in request.FILES:
                df = handle_uploaded_file2(request.FILES['file'])

                clients_name = df.loc[:, "clients_name"]
                company_name = df.loc[:, "company"]
                clients_mail = df.loc[:, "clients_mail"]
                tel = df.loc[:, "tel"]
                web_site_link = df.loc[:, "web_site_link"]
                stage_id = df.loc[:, "stage_id"]
                accuracy = df.loc[:, "accuracy"]
                industry = df.loc[:, "industry"]
                revenue = df.loc[:, "annual_revenue"]
                address = df.loc[:, "address"]
                memo1 = df.loc[:, "memo1"]
                memo2 = df.loc[:, "memo2"]

                for i in range(len(df)):

                    company = Company.objects.filter(name=str(company_name[i]))

                    if company.first() is None:
                        company_table = Company(
                            name=company_name[i],
                            mail=clients_mail[i],
                            tel=tel[i],
                            web_site_link=web_site_link[i],
                            industry=industry[i],
                            address=address[i],
                        )
                        company_table.save()
                    new_id = Company.objects.values('id').filter(
                        name=company_name[i])
                    clients = Clients.objects.filter(
                        company_id=new_id[0]["id"])

                    if clients.first() is None:
                        clients_table = Clients(
                            clients_name=clients_name[i],
                            company_id=new_id[0]["id"],
                            clients_mail=clients_mail[i],
                            tel=tel[i],
                            web_site_link=web_site_link[i],
                            stage_id=stage_id[i],
                            industry=industry[i],
                            annual_revenue=revenue[i],
                            accuracy=accuracy[i],
                            address=address[i],
                            memo1=memo1[i],
                            memo2=memo2[i],
                        )
                        clients_table.save()
                return redirect('client')
            #return render(request,'login/log.html',{"log":clients_name[0]})
            #ファイルが選択されていなければ
            else:
                error = "ファイルを選択してください"
                form = forms.search_clients(request.GET or None)
                form2 = forms.UploadFileForm2(request.POST or None)

                clients = Clients.objects.all().values("clients_name",
                                                       "company_id",
                                                       "clients_mail", "tel")
                for i in range(len(clients)):
                    company = Company.objects.values('name').filter(
                        id=int(clients[i]["company_id"]))
                    clients[i]["company"] = company[0]["name"]

                if clients.first() != None:
                    return render(
                        request, 'login/future_client.html', {
                            "clients": clients,
                            "form": form,
                            "form2": form2,
                            "error": error
                        })
                content = []

                return render(
                    request, 'login/future_client.html', {
                        "clients": content,
                        "form": form,
                        "form2": form2,
                        "error": error
                    })
Exemplo n.º 8
0
def file_import(request):
    if request.method == 'POST':
        form = forms.UploadFileForm(request.POST, request.FILES)
        if form.is_valid():
            if 'file' in request.FILES:
                #フォームで取得したファイルを保存する関数
                #保存したファイルをpandasで読み込んだものを返す
                df = handle_uploaded_file(request.FILES['file'])
                #カラムごとに格納
                clients_name = df.loc[:, "clients_name"]
                company_name = df.loc[:, "company"]
                clients_mail = df.loc[:, "clients_mail"]
                tel = df.loc[:, "tel"]
                web_site_link = df.loc[:, "web_site_link"]
                stage_id = df.loc[:, "stage_id"]
                accuracy = df.loc[:, "accuracy"]
                industry = df.loc[:, "industry"]
                revenue = df.loc[:, "annual_revenue"]
                address = df.loc[:, "address"]
                memo1 = df.loc[:, "memo1"]
                memo2 = df.loc[:, "memo2"]
                #csvファイルの情報を一つずつConnectionテーブルに保存する
                for i in range(len(df)):

                    company = Company.objects.filter(name=str(company_name[i]))

                    if company.first() is None:
                        company_table = Company(
                            name=company_name[i],
                            mail=clients_mail[i],
                            tel=tel[i],
                            web_site_link=web_site_link[i],
                            industry=industry[i],
                            address=address[i],
                        )
                        company_table.save()
                    new_id = Company.objects.values('id').filter(
                        name=company_name[i])
                    connection = Connection.objects.filter(
                        company_id=new_id[0]["id"])

                    if connection.first() is None:
                        connection_table = Connection(
                            clients_name=clients_name[i],
                            company_id=new_id[0]["id"],
                            clients_mail=clients_mail[i],
                            tel=tel[i],
                            web_site_link=web_site_link[i],
                            stage_id=stage_id[i],
                            industry=industry[i],
                            annual_revenue=revenue[i],
                            accuracy=accuracy[i],
                            address=address[i],
                            memo1=memo1[i],
                            memo2=memo2[i],
                        )
                        connection_table.save()
                return redirect('connection')
            #ファイルが選択されていなかったらエラー文を返す
            else:
                form = forms.search_clients(request.GET or None)
                form2 = forms.UploadFileForm(request.POST or None)
                error = "ファイルを選択してください"
                connection = Connection.objects.all().values(
                    "clients_name", "company_id", "clients_mail", "tel")
                for i in range(len(connection)):
                    company = Company.objects.values('name').filter(
                        id=int(connection[i]["company_id"]))
                    connection[i]["company"] = company[0]["name"]

                if connection.first() != None:
                    return render(
                        request, 'login/contact_information.html', {
                            "clients": connection,
                            "form": form,
                            "form2": form2,
                            "error": error
                        })
                content = []
                return render(
                    request, 'login/contact_information.html', {
                        "clients": content,
                        "form": form,
                        "form2": form2,
                        "error": error
                    })