Ejemplo n.º 1
0
 def receive_shipment(self, arrOfCurrOrder):
     supplier = self.suppliers.findByName(arrOfCurrOrder[0])
     vaccToAdd = DTO.Vaccine(0, arrOfCurrOrder[2], supplier[0],
                             arrOfCurrOrder[1])
     self.vaccines.insert(vaccToAdd)
     logistic = self.logistics.findByID(supplier[2])
     self.logistics.updateReceivedCount(logistic[0], arrOfCurrOrder[1])
     self._conn.commit()
Ejemplo n.º 2
0
def receive(order):
    name = order[0]
    amount = int(order[1])
    date = order[2].replace('\n','')
    id = repo.vaccines.last_id + 1
    supp = repo.suppliers.find(name=name)[0]
    repo.vaccines.insert(DTO.Vaccine(id, date, supp.id, amount))
    logi = repo.logistics.find(id=supp.logistic)[0]
    repo.logistics.update({'count_received': (logi.count_received + amount)}, {'id': logi.id})
Ejemplo n.º 3
0
 def receive_shipment(self, name, amount, date):
     self._output.increase_total_inventory(amount)
     self._output.increase_total_received(amount)
     id_supplier = self.suppliers.find_by_name(name).id
     cursor = self._con.cursor()
     next_id = self.vaccines.get_new_index(cursor)
     self.vaccines.insert(DTO.Vaccine(next_id, date, id_supplier, amount))
     logistic_id = self.suppliers.find_by_name(name).logistic
     self.logistics.increase_count_received(amount, logistic_id)
     self._output.update_output()
Ejemplo n.º 4
0
def receive_shipment(lst):
    supplier = get_supplier(lst[0], "name")
    supplier_id = supplier.id
    amount = int(lst[1])
    c = lst[2][4]
    date = datetime.datetime.strptime(lst[2], "%Y" + c + "%m" + c + "%d")
    vaccine_id = DTO.Vaccine.counter + 1
    add_vaccine(DTO.Vaccine(vaccine_id, date, supplier_id, amount))
    logistic_id = supplier.logistic
    update_logistic(logistic_id, amount)
Ejemplo n.º 5
0
def read_vaccines(x, f):
    for i in range(x):
        s = f.readline()
        parser = s[0:-1].split(',')
        vaccine_id = int(parser[0])
        c = parser[1][4]
        date = datetime.datetime.strptime(parser[1], "%Y" + c + "%m" + c + "%d")
        supplier = int(parser[2])
        quantity = int(parser[3])
        add_vaccine(DTO.Vaccine(vaccine_id, date, supplier, quantity))
Ejemplo n.º 6
0
def main():
    repo = _Repository()
    repo.create_tables()

    # Parsing config file
    with open(sys.argv[1]) as config:
        lines = config.readlines()
        index = 1
        num_of_each = lines[0].split(",")
        vaccines = lines[index:index + int(num_of_each[0])]
        index = index + int(num_of_each[0])
        suppliers = lines[index:index + int(num_of_each[1])]
        index = index + int(num_of_each[1])
        clinics = lines[index:index + int(num_of_each[2])]
        index = index + int(num_of_each[2])
        logistics = lines[index:]
        for line in vaccines:
            line = line.replace("\n", "")
            args = line.split(",")
            repo.vac_dao.insert(
                DTO.Vaccine(int(args[0]), args[1], int(args[2]), int(args[3])))
        for line in suppliers:
            line = line.replace("\n", "")
            args = line.split(",")
            repo.sup_dao.insert(
                DTO.Supplier(int(args[0]), args[1], int(args[2])))
        for line in clinics:
            line = line.replace("\n", "")
            args = line.split(",")
            repo.clin_dao.insert(
                DTO.Clinic(int(args[0]), args[1], int(args[2]), int(args[3])))
        for line in logistics:
            line = line.replace("\n", "")
            args = line.split(",")
            repo.log_dao.insert(
                DTO.Logistic(int(args[0]), args[1], int(args[2]),
                             int(args[3])))

    # Executing orders from orders file
    with open(sys.argv[2]) as orders, open(sys.argv[3], "w") as output:
        lines = orders.readlines()
        for line in lines:
            args = line.split(",")
            if len(args) == 3:
                repo.receive_ship(args[0], int(args[1]), args[2])
            else:
                repo.send_ship(args[0], int(args[1]))
            a, b, c, d = repo.create_record()
            output.write("{},{},{},{}\n".format(a[0], b[0], c[0], d[0]))

    repo.close()
Ejemplo n.º 7
0
def readConfig(filePath):
    with open(filePath, "r") as config:
        amountOfEachPart = config.readline()[0:-1].split(',')
        numOfVaccines = int(amountOfEachPart[0])
        # first read the vaccines
        for x in range(0, numOfVaccines):
            line = config.readline()
            # remove \n at the end of each line if exists
            if "\n" in line:
                vaccineDetails = line[0:-1].split(',')
            else:
                vaccineDetails = line.split(',')
            vaccine = DTO.Vaccine(*vaccineDetails)
            repo.vaccines.insert(vaccine)
            sum.totalInventory += int(vaccineDetails[3])
        # read the suppliers
        numOfSuppliers = int(amountOfEachPart[1])
        for i in range(0, numOfSuppliers):
            line = config.readline()
            # remove \n at the end of each line if exists
            if "\n" in line:
                supplierDetails = line[0:-1].split(',')
            else:
                supplierDetails = line.split(',')
            supplier = DTO.Supplier(*supplierDetails)
            repo.suppliers.insert(supplier)
        # read the clinics
        numOfClinics = int(amountOfEachPart[2])
        for i in range(0, numOfClinics):
            line = config.readline()
            # remove \n at the end of each line if exists
            if "\n" in line:
                clinicDetails = line[0:-1].split(',')
            else:
                clinicDetails = line.split(',')
            clinic = DTO.Clinic(*clinicDetails)
            repo.clinics.insert(clinic)
            sum.totalDemand += int(clinicDetails[2])
        # read the logistics
        numOfLogistics = int(amountOfEachPart[3])
        for i in range(0, numOfLogistics):
            line = config.readline()
            # remove \n at the end of each line if exists
            if "\n" in line:
                logisticDetails = line[0:-1].split(',')
            else:
                logisticDetails = line.split(',')
            logistic = DTO.Logistic(*logisticDetails)
            repo.logistics.insert(logistic)
Ejemplo n.º 8
0
    def receiveShipment(self, nameOfSup, amount, date):
        # insert the next vaccine to the vaccine table
        # get the id of the logistics from the suppliers table using the name

        supplier = self.suppliers.find(name=nameOfSup)
        supplierIndex = supplier[0].id
        # get the id of the last inserted line to create a new id for the new vaccine
        lastId = self.vaccines.getLastInsertedId()
        newId = lastId[0] + 1
        newVaccine = DTO.Vaccine(newId, date, supplierIndex, amount)
        self.vaccines.insert(newVaccine)

        idOfLogistics = supplier[0].logistic

        # update the count_received of this logistics company in logistics table
        logistic = self.logistics.find(id=idOfLogistics)
        currCountRec = logistic[0].count_Received
        set_value = {'count_received': currCountRec + int(amount)}

        # only where the id = idOfLogistics we got from the find query
        cond = {'id': idOfLogistics}
        self.logistics.update(set_value, cond)
Ejemplo n.º 9
0
 def receive_ship(self, _name, amount, date):
     sup_id = self.sup_dao.get_sup_id(_name)
     max_id = self.vac_dao.max_id()
     self.vac_dao.insert(DTO.Vaccine(max_id[0] + 1, date, sup_id, amount))
     log_id = self.sup_dao.get_log_id(sup_id)
     self.log_dao.update_count_r(log_id, amount)
Ejemplo n.º 10
0
 def getVaccineToSend(self):
     c = self._conn.cursor()
     c.execute("""
             SELECT * FROM vaccines ORDER BY(date) ASC 
     """)
     return DTO.Vaccine(*c.fetchone())
Ejemplo n.º 11
0
 def find_vaccine(self):
     c = self.cursor
     c.execute("SELECT * FROM Vaccines ORDER BY date")
     return DTO.Vaccine(*c.fetchone())