Example #1
0
def takePayment(om_gui):
    '''
    raise a dialog, and take some money
    '''
    if om_gui.pt.serialno == 0:
        om_gui.advise("No patient Selected <br />Monies will be " +
                      "allocated to Other Payments, and no receipt offered")
    dl = PaymentDialog(om_gui)
    dl.set_treatment_default_amount(om_gui.pt.fees)
    dl.hide_treatment(om_gui.pt.serialno == 0)
    if dl.exec_():
        if om_gui.pt.serialno == 0:
            paymentPt = patient_class.patient(22963)
        else:
            paymentPt = om_gui.pt

        name = "%s %s" % (paymentPt.sname, paymentPt.fname[:1])
        if paymentPt.dnt2 != 0:
            dent = paymentPt.dnt2
        else:
            dent = paymentPt.dnt1

        LOGGER.debug("TAKING PAYMENT for patient %s" % paymentPt.serialno)

        if cashbook.paymenttaken(paymentPt.serialno, name, dent,
                                 paymentPt.cset, dl.tx_cash, dl.tx_cheque,
                                 dl.tx_card, dl.sundry_cash, dl.sundry_cheque,
                                 dl.sundry_card, dl.hdp, dl.other, dl.refund):

            paymentPt.addHiddenNote(
                "payment", " treatment %s sundries %s" %
                (dl.tx_total_text, dl.sundry_total_text))

            om_gui.updateHiddenNotesLabel()

            if om_gui.pt.serialno != 0:
                LOGGER.debug("loaded patient == payment patient")
                om_printing.printReceipt(om_gui, {
                    "Treatments and Services": dl.tx_total_text,
                    "Sundry Items": dl.sundry_total_text,
                    "Unspecified Items": dl.other_text,
                    "REFUND": dl.refund_text
                },
                                         total=dl.grand_total_text)

                #-- always refer to money in terms of pence
                print "adjusting money"
                if om_gui.pt.cset[:1] == "N":
                    om_gui.pt.money2 += dl.tx_total
                else:
                    om_gui.pt.money3 += dl.tx_total
                om_gui.pt.money11 -= dl.refund

            else:
                LOGGER.debug(
                    "Payment patient is not loaded. skipping receipt offer.")

            patient_write_changes.toNotes(paymentPt.serialno,
                                          paymentPt.HIDDENNOTES)

            LOGGER.debug("writing payment notes")
            if patient_write_changes.discreet_changes(
                    paymentPt,
                ("money2", "money3", "money11")) and om_gui.pt.serialno != 0:
                LOGGER.debug("updating patient's stored money values")
                om_gui.pt.dbstate.money2 = om_gui.pt.money2
                om_gui.pt.dbstate.money3 = om_gui.pt.money3
                om_gui.pt.dbstate.money11 = om_gui.pt.money11

            paymentPt.clearHiddenNotes()
            om_gui.updateDetails()
            om_gui.updateHiddenNotesLabel()
            LOGGER.info("PAYMENT ALL DONE!")
        else:
            LOGGER.warning("payment failed to write to database!")
            message = "%s<br />%s" % (
                _("error applying payment.... sorry!"),
                _("This shouldn't happen - please report as an urgent bug"))
            om_gui.advise(message, 2)
Example #2
0
def takePayment(om_gui):
    '''
    raise a dialog, and take some money
    '''
    if om_gui.pt.serialno == 0:
        try:
            paymentPt = patient_class.patient(22963)
        except PatientNotFoundError:
            om_gui.advise(_("Please choose a patient"), 1)
            return
        om_gui.advise(
            "%s <br />%s" %
            (_("No patient Selected"),
             _("Monies will be allocated to Other Payments, and no receipt "
               "offered")), 1)
    else:
        paymentPt = om_gui.pt

    dl = PaymentDialog(om_gui)
    dl.set_treatment_default_amount(paymentPt.fees)
    dl.hide_treatment(om_gui.pt.serialno == 0)
    payment_taken = False
    name = "%s %s" % (paymentPt.sname, paymentPt.fname[:1])
    if paymentPt.dnt2 != 0:
        dent = paymentPt.dnt2
    else:
        dent = paymentPt.dnt1

    while not payment_taken:
        if not dl.exec_():
            break
        if (dl.tx_total > paymentPt.fees and QtWidgets.QMessageBox.question(
                dl, _("Confirm"),
                _("Overpayment of treatment fees, is this correct?"),
                QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No,
                QtWidgets.QMessageBox.No) == QtWidgets.QMessageBox.No):
            continue

        LOGGER.debug("TAKING PAYMENT for patient %s", paymentPt.serialno)

        if cashbook.paymenttaken(paymentPt.serialno, name, dent,
                                 paymentPt.cset, dl.tx_cash, dl.tx_cheque,
                                 dl.tx_card, dl.sundry_cash, dl.sundry_cheque,
                                 dl.sundry_card, dl.hdp, dl.other, dl.refund):

            paymentPt.addHiddenNote(
                "payment", " treatment %s sundries %s" %
                (dl.tx_total_text, dl.sundry_total_text))

            om_gui.updateHiddenNotesLabel()

            if om_gui.pt.serialno != 0:
                LOGGER.debug("loaded patient == payment patient")
                om_printing.printReceipt(om_gui, {
                    "Treatments and Services": dl.tx_total_text,
                    "Sundry Items": dl.sundry_total_text,
                    "Unspecified Items": dl.other_text,
                    "REFUND": dl.refund_text
                },
                                         total=dl.grand_total_text)

                # always refer to money in terms of pence
                LOGGER.debug("adjusting money")
                if om_gui.pt.cset[:1] == "N":
                    om_gui.pt.money2 += dl.tx_total
                else:
                    om_gui.pt.money3 += dl.tx_total
                om_gui.pt.money11 -= dl.refund

            else:
                LOGGER.debug(
                    "Payment patient is not loaded. skipping receipt offer.")

            LOGGER.debug("writing payment notes")
            om_gui.pt.reset_billing()
            if patient_write_changes.discreet_changes(
                    paymentPt,
                ("money2", "money3", "money11", "billdate", "billct",
                 "billtype")) and om_gui.pt.serialno != 0:
                LOGGER.debug("updating patient's stored money values")
                om_gui.pt.dbstate.money2 = om_gui.pt.money2
                om_gui.pt.dbstate.money3 = om_gui.pt.money3
                om_gui.pt.dbstate.money11 = om_gui.pt.money11
                om_gui.pt.dbstate.reset_billing()

            om_gui.updateDetails()
            om_gui.updateHiddenNotesLabel()
            LOGGER.info("PAYMENT ALL DONE!")
            payment_taken = True