def get(self):
        Guser = users.get_current_user()

        try:

            if Guser:
                strPolicyNum = self.request.get('vstrPolicyNumber')
                strPolicyNum = str(strPolicyNum)
                logging.info("Policy Number on Create Family Handler : " +
                             strPolicyNum)

                strFamilyPlanChoice = self.request.get('vstrFamilyPlanChoice')
                strFamilyPlanChoice = str(strFamilyPlanChoice)
                strFamilyPlanChoice = strFamilyPlanChoice.strip()
                strPaymentDay = self.request.get('vstrPaymentDay')
                strPaymentDay = str(strPaymentDay).strip()
                strClientSignature = self.request.get('vstrClientSignature')
                strClientSignature = strClientSignature.strip()
                strEmployeeSignature = self.request.get(
                    'vstrEmployeeSignature')
                strEmployeeSignature = strEmployeeSignature.strip()

                today = datetime.datetime.today()
                today = today.date()

                thisMonth = today.month
                thisYear = today.year

                if (thisMonth == 12):
                    thisMonth = 1
                    thisYear = today.year + 1
                else:
                    thisMonth = thisMonth + 1

                thisDay = int(strPaymentDay)

                strFirstPremiumDate = datetime.date(year=thisYear,
                                                    month=thisMonth,
                                                    day=thisDay)

                strPremium = 0
                if (strFamilyPlanChoice == "A"):
                    strPremium = 50
                elif (strFamilyPlanChoice == "B"):
                    strPremium = 60
                elif (strFamilyPlanChoice == "C"):
                    strPremium = 85
                elif (strFamilyPlanChoice == "D"):
                    strPremium = 95

                thisPolicy = Policy()
                findRequest = Covers.query(Covers.strCoverType == "Family")
                thisCover = findRequest.fetch()

                if len(thisCover) > 0:
                    thisCover = thisCover[0]
                else:
                    thisCover = Covers()

                findRequest = Policy.query(Policy.strPolicyNum == strPolicyNum)
                thisPolicyList = findRequest.fetch()

                if len(thisPolicyList) > 0:
                    thisPolicy = thisPolicyList[0]

                try:
                    thisPolicy.writeCoverCode(
                        strinput=thisCover.readCoverCode())

                    thisPolicy.writeFirstPremiumDate(
                        strinput=strFirstPremiumDate)

                    thisPolicy.writePaymentCode(
                        strinput=strPolicyNum)  # Payment Transactions Code
                    thisPolicy.writeReference(strinput=Guser.user_id())

                    thisPolicy.writePolicyNum(strinput=strPolicyNum)
                    thisPolicy.writePlanChoice(strinput=strFamilyPlanChoice)
                    thisPolicy.writeTotalPremiums(strinput=strPremium)

                    thisPolicy.writePaymentDay(strinput=strPaymentDay)
                    thisPolicy.writeClientSignature(
                        strinput=strClientSignature)

                    thisPolicy.writeEmployeeSignature(
                        strinput=strEmployeeSignature)

                    thisPolicy.put()
                except:
                    self.response.write("""<strong>ERROR :</strong>""")

                self.response.write("""
                <strong>Policy Created and Saved---Please Add Payment Details if you have not done so yet and then activate the Policy</h3>

                """)
            else:
                self.response.write("""
                 <strong>Policy not Saved</strong>
                 """)
        except:
            self.response.write("""

            <strong>Error Saving Policy</strong>

            """)
    def get(self):
        strPolicyNumber = self.request.get('vstrPolicyNumber')
        logging.info(strPolicyNumber)
        strPaymentAmount = self.request.get('vstrPaymentAmount')
        logging.info(strPaymentAmount)
        strNotification = str(self.request.get('strPaymentNotification'))
        strPayMonthsList = self.request.get('vstrPayMonthsList')

        strPayMonthsList = strPayMonthsList
        strPayMonthsList = strPayMonthsList.strip(",")

        tempArray = []
        tString = ""
        tcount = 1
        for tc in strPayMonthsList:
            if tcount > 3:
                tempArray.append(tString)
                tcount = 1
                tString = ""
            else:
                tString = tString + tc
                tcount = tcount + 1
        tempArray.append(tString)

        strPayMonthsList = tempArray

        SMSbox = SMS()
        EmailBox = Emails()
        FormattedMessage = "Payment for Midey Funeral Policy Number : " + strPolicyNumber + " was received"

        if strNotification.isdigit():
            SMSbox.sendSMS(strCell=strNotification,
                           strMessage=FormattedMessage)
        elif "@" in strNotification:
            EmailBox.sendEmailNotification(
                strEmail=strNotification,
                strSubject="Midey Funeral Payment Notifications",
                strMessage=FormattedMessage)
        else:
            pass

        self.response.write("Payment Processing...")

        findRequest = Policy.query(Policy.strPolicyNum == strPolicyNumber)
        PolicyList = findRequest.fetch()

        if len(PolicyList) > 0:
            thisPolicy = PolicyList[0]
        else:
            thisPolicy = Policy()

        thisPolicy.writePaymentCode(strinput=thisPolicy.readPolicyNum())
        thisPolicy.put()

        findRequest = PaymentHistory.query()
        PaymentList = findRequest.fetch()
        payindex = len(PaymentList)

        findRequest = PaymentHistory.query(
            PaymentHistory.strPaymentCode == strPolicyNumber).order(
                PaymentHistory.strDatePaymentMade)
        PaymentList = findRequest.fetch()

        strPaymentAmount = str(strPaymentAmount)

        tc = 0
        for m in strPayMonthsList:
            tc = tc + 1

        logging.info(str(tc))
        if strPaymentAmount.isdigit():
            strPaymentAmount = int(strPaymentAmount)
            AtomicPaymentAmount = strPaymentAmount / len(strPayMonthsList)
            logging.info("PLEASE CHECK THIS AMOUNT : " +
                         str(AtomicPaymentAmount) +
                         "COMPARE TO THE DIVISOR : " +
                         str(len(strPayMonthsList)))
        else:
            AtomicPaymentAmount = 0

        TotalMonths = len(strPayMonthsList)

        ThisMonth = datetime.datetime.now()
        MyDate = ThisMonth.date()
        ThisMonth = MyDate.month
        ThisYear = MyDate.year

        if TotalMonths > (12 - ThisMonth):
            FinalYear = ThisYear + 1

        Count = 0
        for Month in strPayMonthsList:
            Payment = PaymentHistory()
            Payment.writePaymentsCode(strinput=strPolicyNumber)

            Payment.writeIndex(strinput=payindex)
            payindex = payindex + 1
            Payment.strDatePaymentMade = datetime.datetime.now()
            Payment.writePaymentMethod(strinput="cash")
            logging.info("Months About to Be written to the System : " + Month)
            logging.info(" -- ")
            Payment.writePayForMonth(strinput=Month)
            Payment.writePaymentAmount(strinput=AtomicPaymentAmount)
            if Count <= (12 - ThisMonth):
                Payment.writePayYear(strinput=ThisYear)
                Count = Count + 1
            else:
                Payment.writePayYear(strinput=FinalYear)
                ThisYear = FinalYear
                Count = 0
            Payment.put()

        self.response.write("Payment Processing Complete...")
    def get(self):

        Guser = users.get_current_user()

        if Guser:
            strPolicyNum = self.request.get('vstrPolicyNumber')
            strPolicyNum = str(strPolicyNum)
            strPolicyNum = strPolicyNum.strip()
            strFamilyPlanChoice = self.request.get('vstrFamilyPlanChoice')
            strFamilyPlanChoice = str(strFamilyPlanChoice)
            strFamilyPlanChoice = strFamilyPlanChoice.strip()
            strExtendedPlanChoice = self.request.get('vstrExtendedPlanChoice')
            strExtendedPlanChoice = strExtendedPlanChoice.strip()

            strPaymentDay = self.request.get('vstrPaymentDay')
            strPaymentDay = str(strPaymentDay).strip()

            strClientSignature = self.request.get('vstrClientSignature')
            strClientSignature = strClientSignature.strip()

            strEmployeeSignature = self.request.get('vstrEmployeeSignature')
            strEmployeeSignature = strEmployeeSignature.strip()

            strPremiumCalculated = self.request.get('vstrTotalPremium')

            today = datetime.datetime.today()
            today = today.date()

            thisMonth = today.month
            thisYear = today.year

            if thisMonth == 12:
                thisMonth = 1
                thisYear = today.year + 1
            else:
                thisMonth = thisMonth + 1

            thisDay = int(strPaymentDay)

            strFirstPremiumDate = datetime.date(year=thisYear,
                                                month=thisMonth,
                                                day=thisDay)

            thisPolicy = Policy()
            findRequest = Covers.query(Covers.strCoverType == "Extended")
            thisCover = findRequest.fetch()

            if len(thisCover) > 0:
                thisCover = thisCover[0]
            else:
                thisCover = Covers()

            findRequest = Policy.query(Policy.strPolicyNum == strPolicyNum)
            thisPolicyList = findRequest.fetch()

            if len(thisPolicyList) > 0:
                thisPolicy = thisPolicyList[0]

            thisPolicy.writeCoverCode(strinput=thisCover.readCoverCode())
            thisPolicy.writeFirstPremiumDate(strinput=strFirstPremiumDate)
            thisPolicy.writePaymentCode(
                strinput=strPolicyNum)  # Payment Transactions Code
            thisPolicy.writeReference(strinput=Guser.user_id())
            thisPolicy.writePolicyNum(strinput=strPolicyNum)
            thisPolicy.writePlanChoice(strinput=strFamilyPlanChoice)
            thisPolicy.writeExtendedPlanChoice(strinput=strExtendedPlanChoice)
            thisPolicy.writeTotalPremiums(strinput=strPremiumCalculated)
            thisPolicy.writePaymentDay(strinput=strPaymentDay)
            thisPolicy.writeClientSignature(strinput=strClientSignature)
            thisPolicy.writeEmployeeSignature(strinput=strEmployeeSignature)
            thisPolicy.put()

            self.response.write("Policy Created and SAVED")
        else:
            self.response.write("Policy not Saved")