Esempio n. 1
0
 def add_new_location(self, ort, ken):
     changed_data = {"Ort": ort, "Kennung": ken}
     #self.new_location_data = changed_data
     if self.new_location is None:
         self.new_location = AfpSQLTableSelection(self.mysql, "TORT",
                                                  self.debug, "OrtsNr",
                                                  self.feldnamen_orte)
         self.new_location.new_data(False, True)
     self.new_location.set_data_values(changed_data)
     print "AfpToRoute.add_new_location:", ort, ken
Esempio n. 2
0
 def spezial_selection(self, selname, new=False):
     AdSelection = None
     if selname == "Bez":
         #print  self.selections["ADRESSE"].get_feldnamen()
         feldnamen = self.selections["ADRESSE"].get_feldnamen()
         if new:
             AdSelection = AfpSQLTableSelection(self.mysql, "ADRESSE",
                                                self.debug, None, feldnamen)
             AdSelection.new_data()
         else:
             AdSelection = AfpSQLTableSelection(self.mysql, "ADRESSE",
                                                self.debug, None, feldnamen)
             KNr = self.selections["ADRESSE"].get_value("Bez")
             if not KNr: KNr = 0
             data = []
             self.spezial_bez = []
             if KNr != 0:
                 Index = feldnamen.index("Bez")
                 KundenNr = int(self.mainvalue)
                 while KNr != KundenNr and KNr != 0:
                     if KNr < 0: KNr = -KNr
                     row = self.mysql.select(
                         "*", "KundenNr = " + Afp_toString(KNr), "ADRESSE")
                     self.spezial_bez.append(KNr)
                     KNr = int(row[0][Index])
                     data.append(row[0])
                 AdSelection.set_data(data)
     return AdSelection
Esempio n. 3
0
 def add_invoice(self):
     print "AfpCharter.add_invoice"
     invoice = AfpSQLTableSelection(self.get_mysql(), "RECHNG", self.debug,
                                    "RechNr")
     KNr = self.get_value("KundenNr")
     data = {
         "Datum": self.globals.today(),
         "KundenNr": KNr,
         "Name": self.get_name(True),
         "Fahrt": self.get_value("FahrtNr")
     }
     data["Debitor"] = Afp_getIndividualAccount(self.get_mysql(), KNr)
     betrag = self.get_value("Preis")
     data["Zahlbetrag"] = betrag
     betrag2 = self.extract_taxfree_portion()
     if betrag2:
         betrag -= betrag2
         data["Betrag2"] = betrag
         data["Konto2"] = Afp_getSpecialAccount(self.get_mysql(), "EMFA")
     data["RechBetrag"] = betrag
     data["Kontierung"] = Afp_getSpecialAccount(self.get_mysql(), "EMF")
     data["Zustand"] = "offen"
     data["Wofuer"] = "Mietfahrt Nr " + self.get_string_value(
         "FahrtNr") + " am " + self.get_string_value(
             "Abfahrt") + " nach " + self.get_string_value("Zielort")
     if self.get_value("ZahlDat"):
         data["Zahlung"] = self.get_value("Zahlung")
         data["ZahlDat"] = self.get_value("ZahlDat")
         if data["Zahlung"] >= betrag: data["Zustand"] = "bezahlt"
     invoice.new_data()
     invoice.set_data_values(data)
     self.selections["RECHNG"] = invoice
Esempio n. 4
0
 def spezial_selection(self, selname, new=False):
     LocSelection = None
     #print "AfpToRoute.sepzial_selection:", selname, new
     if selname == "Route":
         if new:
             LocSelection = AfpSQLTableSelection(self.mysql, "TROUTE",
                                                 self.debug)
             LocSelection.new_data()
         else:
             LocSelection = AfpSQLTableSelection(self.mysql, "TROUTE",
                                                 self.debug)
             select = "KennNr >= " + Afp_toString(
                 self.kennnr) + " AND KennNr < " + Afp_toString(
                     self.kennnr + 1000)
             LocSelection.load_data(select)
         self.feldnamen_route = LocSelection.get_feldnamen()
     elif selname == "Orte":
         if new:
             LocSelection = AfpSQLTableSelection(self.mysql, "TORT",
                                                 self.debug)
             LocSelection.new_data()
         else:
             LocSelection = AfpSQLTableSelection(self.mysql, "TORT",
                                                 self.debug)
             data = []
             kenns = self.get_selection("Route").get_values("KennNr")
             for ken in kenns:
                 ort = ken[0] - int(ken[0] / 1000) * 1000
                 row = self.mysql.select("*",
                                         "OrtsNr = " + Afp_toString(ort),
                                         "TORT")
                 if row:
                     #print  "AfpToRoute.sepzial_selection row:", ort, row
                     data.append(row[0])
                     self.spezial_orte.append(ort)
                 LocSelection.set_data(data)
         self.feldnamen_orte = LocSelection.get_feldnamen()
     return LocSelection
Esempio n. 5
0
class AfpToRoute(AfpSelectionList):
    ## initialize AfpToRoute class
    # @param globals - global values including the mysql connection - this input is mandatory
    # @param RouteNr - if given and sb == None, data will be retrieved this database entry
    # @param sb - if given data will  be retrieved from the actuel AfpSuperbase data
    # @param debug - flag for debug information
    # @param complete - flag if data from all tables should be retrieved durin initialisation \n
    # \n
    # either RouteNr or sb (superbase) has to be given for initialisation, otherwise a new, clean object is created
    def __init__(self,
                 globals,
                 RouteNr=None,
                 sb=None,
                 debug=None,
                 complete=False):
        AfpSelectionList.__init__(self, globals, "Route", debug)
        if debug: self.debug = debug
        else: self.debug = globals.is_debug()
        self.new = False
        self.mainindex = "TourNr"
        self.mainvalue = ""
        self.kennnr = None
        self.feldnamen_route = None
        self.feldnamen_orte = None
        self.spezial_orte = []
        self.free_text = " - anderen Ort auswählen - ".decode("UTF-8")
        self.new_text = " - neuen Ort eingeben - "
        self.raste_text = "Raststätten".decode("UTF-8")
        self.new_location = None
        self.new_route_index = None
        if sb:
            self.mainvalue = sb.get_string_value("TourNr.TNAME")
            Selection = sb.gen_selection("TNAME", "TourNr", debug)
            self.selections["TNAME"] = Selection
        else:
            if RouteNr:
                self.mainvalue = Afp_toString(RouteNr)
            else:
                self.new = True
        if self.mainvalue:
            self.kennnr = 1000 * Afp_fromString(self.mainvalue)
        self.mainselection = "TNAME"
        self.set_main_selects_entry()
        if not self.mainselection in self.selections:
            self.create_selection(self.mainselection)
        #  self.selects[name of selection]  [tablename,, select criteria, optional: unique fieldname]
        self.selects["Route"] = []
        self.selects["Orte"] = []
        if complete: self.create_selections()
        if self.debug: print "AfpToRoute Konstruktor, TourNr:", self.mainvalue

    ## destuctor
    def __del__(self):
        if self.debug: print "AfpToRoute Destruktor"
        #AfpSelectionList.__del__(self)

    ## special selection (overwritten from AfpSelectionList) \n
    # to handle the selection 'Orte'  which holds all attached location data of all departure points
    # @param selname - name of selection (in our case 'Orte' is implemented)
    # @param new - flag if a new empty list has to be created
    def spezial_selection(self, selname, new=False):
        LocSelection = None
        #print "AfpToRoute.sepzial_selection:", selname, new
        if selname == "Route":
            if new:
                LocSelection = AfpSQLTableSelection(self.mysql, "TROUTE",
                                                    self.debug)
                LocSelection.new_data()
            else:
                LocSelection = AfpSQLTableSelection(self.mysql, "TROUTE",
                                                    self.debug)
                select = "KennNr >= " + Afp_toString(
                    self.kennnr) + " AND KennNr < " + Afp_toString(
                        self.kennnr + 1000)
                LocSelection.load_data(select)
            self.feldnamen_route = LocSelection.get_feldnamen()
        elif selname == "Orte":
            if new:
                LocSelection = AfpSQLTableSelection(self.mysql, "TORT",
                                                    self.debug)
                LocSelection.new_data()
            else:
                LocSelection = AfpSQLTableSelection(self.mysql, "TORT",
                                                    self.debug)
                data = []
                kenns = self.get_selection("Route").get_values("KennNr")
                for ken in kenns:
                    ort = ken[0] - int(ken[0] / 1000) * 1000
                    row = self.mysql.select("*",
                                            "OrtsNr = " + Afp_toString(ort),
                                            "TORT")
                    if row:
                        #print  "AfpToRoute.sepzial_selection row:", ort, row
                        data.append(row[0])
                        self.spezial_orte.append(ort)
                    LocSelection.set_data(data)
            self.feldnamen_orte = LocSelection.get_feldnamen()
        return LocSelection

    ## special save (overwritten from AfpSelectionList) \n
    # store the special selection 'Bez'
    # @param selname - name of selection (in our case 'Route' is implemented)
    def spezial_save(self, selname):
        if selname == "Route":
            route = self.get_selection("Route")
            if route.has_changed():
                route.store()
        elif selname == "Orte":
            if self.new_location:
                if self.new_location.get_value("OrtsNr") is None:
                    self.new_location.store()
                    if not self.new_route_index is None:
                        ortsnr = self.new_location.get_value("OrtsNr")
                        self.get_selection("Route").set_value(
                            "KennNr", self.gen_ident(ortsnr),
                            self.new_route_index)

    ## retrieve spezial text
    # @param  typ - typ of text to be retrieved
    def get_spezial_text(self, typ=None):
        if typ is None or typ == "new":
            text = self.new_text
        elif typ == "free":
            text = self.free_text
        elif typ == "raste":
            text = self.raste_text
        else:
            text = None
        return text

    ## look if locations with given 'Kennung' are available
    # @param ken - if given only location having this 'Kennung' are selected (used for rest-point 'RA')
    def location_available(self, ken=None):
        if ken:
            available = False
            rows = self.get_selection("Orte").get_values("Kennung")
            for row in rows:
                if ken in row: available = True
            return available
        else:
            return self.get_selection("Orte").get_data_length() >= 1

    ## get all locations referred by route sorted alphabethically
    # @param typ -  see get_location_list
    # @param add - see get_location_list
    def get_sorted_location_list(self, typ=None, add=False):
        values, idents = self.get_location_list(typ, add)
        return Afp_sortSimultan(values, idents)

    ## get all locations referred by route
    # @param typ -  the following locations are delivered:
    # - typ = None: all route locations
    # - typ = 'routeOnlyRaste': all route rest-points
    # - typ = 'routeNoRaste': all route locations without rest-points,
    # one common 'Raststätten' entry for the key -10, if a rest-point is available in this route
    # - typ = 'all': all locations in the database
    # - typ = 'allNoRoute': all locations in the database, which do not belong to this route
    # @param add - will add additonal text output list
    # - typ = 'routeNoRaste': text for free location selection for key -12
    # - typ = 'all...': text for new location entry for key -11
    def get_location_list(self, typ=None, add=False):
        if typ is None:
            ortsdict = self.get_all_locations()
        elif typ == "routeOnlyRaste":
            ortsdict = self.get_all_locations('RA')
        elif typ == "routeNoRaste":
            ortsdict = self.get_all_locations('RA', True)
            if self.location_available('RA'):
                ortsdict[-10] = self.raste_text
            if add:
                ortsdict[-12] = self.free_text
        elif typ == "all":
            ortsdict = self.get_possible_locations(True)
            if add:
                ortsdict[-11] = self.new_text
        elif typ == "allNoRoute":
            ortsdict = self.get_possible_locations()
            if add:
                ortsdict[-11] = self.new_text
                #ortsdict[0] = self.new_text
        return ortsdict.values(), ortsdict.keys()

    ## get all possible locations
    # @param all - if given and true, all locations are extraced directly,
    # otherwise only locations not in route are returned
    def get_possible_locations(self, all=None):
        rows = self.mysql.select("OrtsNr,Ort,Kennung", None, "TORT")
        orte = {}
        for row in rows:
            if row[1] and (all or not row[0] in self.spezial_orte):
                orte[row[0]] = Afp_toString(row[1]) + " [" + Afp_toString(
                    row[2]) + "]"
        return orte
## get all locations referred by route
# @param ken - if given only location having this 'Kennung' are selected (used for rest-point 'RA')
# @param rev - if given the selection above is reversed (only locations without this 'Kennung' are selected)

    def get_all_locations(self, ken=None, rev=None):
        rows = self.get_selection("Orte").get_values("OrtsNr,Ort,Kennung")
        orte = {}
        #print "AfpToRoute.get_all_locations:", rows
        for row in rows:
            if ken is None or (row[2] == ken
                               and not rev) or (rev and row[2] != ken):
                orte[row[0]] = Afp_toString(row[1]) + " [" + Afp_toString(
                    row[2]) + "]"
        return orte

    ## get location data
    # @param ortsnr - identifier of departure point
    # @param index - if ortsnr == None and given, index in location list
    def get_location_data(self, ortsnr, index=None):
        row = None
        if ortsnr and ortsnr in self.spezial_orte:
            index = self.spezial_orte.index(ortsnr)
        if not index is None:
            row_route = self.get_selection("Route").get_values(None, index)[0]
            row_ort = self.get_selection("Orte").get_values(None, index)[0]
            row = row_ort + row_route
        else:
            row = self.mysql.select("*", "OrtsNr = " + Afp_toString(ortsnr),
                                    "TORT")[0]
        return row

    ## set location data
    # @param changed_data - dictionary holding data to be stored
    # @param ortsnr - if given, identifier of departure point
    # @param index - if ortsnr == None and given, index in location list \n
    #  if ortsnr and index is None a new row is added
    def set_location_data(self, changed_data, ortsnr=None, index=None):
        route = self.get_selection("Route")
        orte = self.get_selection("Orte")
        if ortsnr and ortsnr in self.spezial_orte:
            index = self.spezial_orte.index(ortsnr)
        elif index is None:
            add = True
            index = orte.get_data_length()
        for data in changed_data:
            if data in self.feldnamen_route:
                route.set_value(data, changed_data[data], index)
            elif data in self.feldnamen_orte:
                orte.set_value(data, changed_data[data], index)

    ## generate rout identifier ("Kennung")
    # @param ortsnr - identifier of location
    def gen_ident(self, ortsnr):
        ken = 1000 * self.get_value("TourNr") + ortsnr
        return ken

    ## add a location to this route
    # @param ortsnr - identfier of location to be added
    # @param time - if given, start time in route relativ to starting point of route (float)
    # @param preis - if given, additional price for departure at that location
    def add_location_to_route(self, ortsnr, time=None, preis=None):
        if ortsnr is None:
            changed_data = {"Zeit": time, "Preis": preis, "OrtsNr": -1}
            self.new_route_index = len(self.spezial_orte)
        else:
            changed_data = {}
            if not ortsnr in self.spezial_orte:
                row = self.mysql.select("*",
                                        "OrtsNr = " + Afp_toString(ortsnr),
                                        "TORT")[0]
                changed_data = {
                    "OrtsNr": row[0],
                    "Ort": row[1],
                    "Kennung": row[2]
                }
            else:
                changed_data = {}
            changed_data["KennNr"] = self.gen_ident(ortsnr)
            changed_data["Zeit"] = time
            changed_data["Preis"] = preis
        self.set_location_data(changed_data, ortsnr)
        print "AfpToRoute.add_location_to_route:", ortsnr, time, preis

    ## add location without adding route entry
    # @param ort - name of location
    # @param ken - short name of location ('Kennung')
    def add_new_location(self, ort, ken):
        changed_data = {"Ort": ort, "Kennung": ken}
        #self.new_location_data = changed_data
        if self.new_location is None:
            self.new_location = AfpSQLTableSelection(self.mysql, "TORT",
                                                     self.debug, "OrtsNr",
                                                     self.feldnamen_orte)
            self.new_location.new_data(False, True)
        self.new_location.set_data_values(changed_data)
        print "AfpToRoute.add_new_location:", ort, ken

    ## add the identification number to the new location data
    # @param ortsnr - identification number
    def add_new_location_nr(self, ortsnr):
        if self.new_location:
            self_new_loacation.set_value("OrtsNr", ortsnr)
        if not self.new_route_index is None:
            self.get_selection("Route").set_value("KennNr",
                                                  self.gen_ident(ortsnr),
                                                  self.new_route_index)

    ## add location and add it to route
    # @param ort - name of location
    # @param ken - short name of location ('Kennung')
    # @param time - if given, start time in route relativ to starting point of route (float)
    # @param preis - if given, additional price for departure at that location
    def add_new_route_location(self, ort, ken, time=None, preis=None):
        self.add_new_location(ort, ken)
        self.add_location_to_route(None, time, preis)
        print "AfpToRoute.add_new_route_location"
Esempio n. 6
0
 def __init__(self,
              globals,
              AnmeldNr=None,
              sb=None,
              debug=None,
              complete=False):
     AfpSelectionList.__init__(self, globals, "Tourist", debug)
     if debug: self.debug = debug
     else: self.debug = globals.is_debug()
     self.finance = None
     self.new = False
     self.mainindex = "AnmeldNr"
     self.mainvalue = ""
     self.spezial_bez = []
     if sb:
         if sb.get_value("FahrtNr.REISEN") == sb.get_value(
                 "FahrtNr.ANMELD"):
             self.mainvalue = sb.get_string_value("AnmeldNr.ANMELD")
             Selection = sb.gen_selection("ANMELD", "AnmeldNr", debug)
         else:
             self.new = True
             Selection = AfpSQLTableSelection(self.mysql, "ANMELD",
                                              self.debug, "AnmeldNr")
         self.selections["ANMELD"] = Selection
     else:
         if AnmeldNr:
             self.mainvalue = Afp_toString(AnmeldNr)
         else:
             self.new = True
     self.mainselection = "ANMELD"
     self.set_main_selects_entry()
     if not self.mainselection in self.selections:
         self.create_selection(self.mainselection)
     #  self.selects[name of selection]  [tablename,, select criteria, optional: unique fieldname]
     self.selects["ADRESSE"] = ["ADRESSE", "KundenNr = KundenNr.ANMELD"]
     self.selects["REISEN"] = ["REISEN", "FahrtNr = FahrtNr.ANMELD"]
     self.selects["PREISE"] = ["PREISE", "FahrtNr = FahrtNr.ANMELD"]
     self.selects["TORT"] = ["TORT", "OrtsNr = Ab.ANMELD"]
     self.selects["ANMELDER"] = ["ANMELDER", "AnmeldNr = AnmeldNr.ANMELD"]
     self.selects["ANMELDEX"] = ["ANMELDEX", "AnmeldNr = AnmeldNr.ANMELD"]
     self.selects["RECHNG"] = ["RECHNG", "RechNr = RechNr.ANMELD", "RechNr"]
     self.selects["ARCHIV"] = ["ARCHIV", "AnmeldNr = AnmeldNr.ANMELD"]
     self.selects["AUSGABE"] = [
         "AUSGABE", "Typ = Art.REISEN + Zustand.ANMELD"
     ]
     #self.selects["AUSGABE"] = [ "AUSGABE","Typ = \"EigenAnmeldung\""]
     self.selects["RechNr"] = ["ANMELD", "RechNr = RechNr.ANMELD"]
     self.selects["Agent"] = ["ADRESSE", "KundenNr = AgentNr.ANMELD"]
     self.selects["ExtraPreis"] = ["PREISE", "!FahrtNr = 0"]
     self.selects["Preis"] = ["PREISE", "Kennung = PreisNr.ANMELD"]
     self.selects["Umbuchung"] = ["REISEN", "FahrtNr = UmbFahrt.ANMELD"]
     #self.selects["ERTRAG"] = [ "ERTRAG","FahrtNr = FahrtNr.ANMELD"]
     #self.selects["EINSATZ"] = [ "EINSATZ","ReiseNr = FahrtNr.ANMELD"]
     self.selects["TORT"] = ["TORT", "OrtsNr = Ab.ANMELD"]
     if complete: self.create_selections()
     if not self.globals.skip_accounting():
         self.finance_modul = Afp_importAfpModul("Finance", self.globals)[0]
         if self.finance_modul:
             self.finance = self.finance_modul.AfpFinanceTransactions(
                 self.globals)
     print "AfpTourist.finance:", self.finance
     if self.debug:
         print "AfpTourist Konstruktor, AnmeldNr:", self.mainvalue