Beispiel #1
0
 def put(self):
     try:
         access_token = authenticator(request.headers.get('Authorization'))
         args = flask.request.get_json()
         cursor = db.cursor()
         cursor.execute('SELECT LOCATIONGRID FROM inventorystorage WHERE BARCODE = %s', (args['BARCODE']))
         loc = cursor.fetchone()
         if loc[0] == 'NA':
             status = cursor.execute('UPDATE inventorystorage SET LOCATIONGRID = %s, NAtoLOC = 1 WHERE BARCODE = %s',
                                     (args['LOCATIONGRID'], args['BARCODE']))
         else:
             status = cursor.execute('UPDATE inventorystorage SET LOCATIONGRID = %s WHERE BARCODE = %s',
                                     (args['LOCATIONGRID'], args['BARCODE']))
         if status > 0:
             if Log.register(request.headers.get('Authorization'),
                             'Issue item %s from loc %s to loc %s' % (args['BARCODE'], loc[0], args['LOCATIONGRID']),
                             True):
                 db.commit()
                 return flask.jsonify(edittag_json_response_array(cursor, args['BARCODE']))
             else:
                 return {'message': 'Try again'}, 500
         else:
             return {'message': 'Try again'}, 500
     except InterfaceError as e:
         CreateApi.reAssignDb()
         print(e)
     except Exception as e:
         print(e)
Beispiel #2
0
 def post(self):
     try:
         parser = reqparse.RequestParser()
         parser.add_argument('UserName', required=True, help='UserName is Required')
         parser.add_argument('Password', required=True, help='Password is Required')
         args = parser.parse_args()
         cursor = db.cursor()
         row_count = cursor.execute(
             'select Role from users where UserName=\'' + args['UserName'] + '\'' + 'and Password=\'' + args[
                 'Password'] + '\'')
         row = cursor.fetchone()
         if row_count > 0:
             payload = {
                 'UserName': args['UserName'],
                 'Password': args['Password'],
                 'Role': row[0]
             }
             access_token = jwt.encode(payload, 'secret', algorithm='HS256')
             print(access_token)
             message = {
                 'AuthToken': str(access_token),
                 'Role': payload['Role'],
                 'Request': 'Successful'
             }
         else:
             message = {
                 'AuthToken': 'Null',
                 'Request': 'Wrong Details'
             }
         return (message)
     except InterfaceError as e:
         CreateApi.reAssignDb()
         print(e)
     except Exception as e:
         print(e)
Beispiel #3
0
 def put(self):
     try:
         access_token = authenticator(request.headers.get('Authorization'))
         cursor = db.cursor()
         data = flask.request.get_json()
         if data['status'] == 'NAtoLOC' or data['status'] == 'TAGSTATUS':
             for i in data['data']:
                 cursor.execute(
                     'UPDATE inventorystorage SET ' + data['status'] +
                     ' = 0 WHERE BARCODE = %s', i)
         elif data['status'] == 'PROJECT':
             for i in data['data']:
                 update_project(cursor, data['PROJECTID'],
                                'inventorystorage', 'BARCODE', i,
                                access_token['UserName'],
                                access_token['Role'])
             Log.register(
                 request.headers.get('Authorization'),
                 'Projectid:%s assigned to barcodes %s' %
                 (data['PROJECTID'], ','.join(
                     [str(x) for x in data['data']])), True)
         db.commit()
         return 'success'
     except InvalidProjectUpdate as e:
         return {'message': str(e)}, 500
     except ProjectNotFound as e:
         db.rollback()
         return {'message': str(e)}, 404
     except InterfaceError as e:
         CreateApi.reAssignDb()
         print(e)
     except Exception as e:
         db.rollback()
         return {"message": str(e)}, 500
Beispiel #4
0
 def put(self):
     try:
         access_token = authenticator(
             flask.request.headers.get('Authorization'))
         Data = flask.request.get_json()
         cursor = db.cursor()
         row_count = cursor.execute(
             "insert inventorystorage select * from emptystorage where BARCODE = %s",
             (Data['BARCODE']))
         if row_count > 0:
             cursor.execute(
                 "update inventorystorage set QTY=%s,LASTDATE=%s,LASTUSER=%s where BARCODE=%s",
                 (Data['QTY'], datetime.datetime.now(),
                  access_token['UserName'], Data['BARCODE']))
             cursor.execute("delete from emptystorage where BARCODE=%s",
                            (Data['BARCODE']))
             if Log.register(
                     request.headers.get('Authorization'),
                     'Move Barcode %s from empty to inventory storage' %
                     Data['BARCODE'], True):
                 db.commit()
                 return {"message": "success"}
         else:
             db.rollback()
             return {
                 "message":
                 "barcode %s is not in empty storage" % Data['BARCODE']
             }, 404
     except InterfaceError as e:
         CreateApi.reAssignDb()
         print(e)
     except Exception as e:
         db.rollback()
         return {"message": str(e)}, 404
Beispiel #5
0
 def post(self):
     access_token = authenticator(request.headers.get('Authorization'))
     from pymysql import InterfaceError
     try:
         Data = flask.request.get_json()
         cursor = db.cursor()
         row = cursor.execute(
             "select SHIPMENTDATE,PROJECTID,PROJECTNAME,NBP,ASTRO,KEYMARK,DESCRIPTION,FINISHID,FINISHNAME,LENGTH,QTY,LBFT,NETWEIGHT,NOREX,LOCATION,LOCATIONGRID,MODEL,EASCO,EXTRUDER,NAtoLOC,TAGSTATUS,TICKET from inventorystorage where BARCODE = %s",
             (Data['BARCODE']))
         if row > 0:
             row = cursor.fetchone()
             if int(row[10]) > int(Data['QTY']):
                 max_barcode = get_max_barcode(cursor)
                 cursor.execute(
                     "insert into inventorystorage(BARCODE,TAG,SHIPMENTDATE,PROJECTID,PROJECTNAME,NBP,ASTRO,KEYMARK,DESCRIPTION,FINISHID,FINISHNAME,LENGTH,QTY,LBFT,NETWEIGHT,NOREX,LOCATION,LOCATIONGRID,MODEL,EASCO,EXTRUDER,NAtoLOC,TAGSTATUS,LASTDATE,LASTUSER,TICKET) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
                     ((max_barcode['BARCODE'] + 1), (max_barcode['BARCODE'] + tag_inc), row[0], row[1],
                      row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9], Data['QTY'], row[11], row[12],
                      row[13], row[14], row[15], row[16], row[17], row[18], row[19], row[20],
                      datetime.datetime.now(), access_token['UserName'], row[21]))
                 print('a')
                 cursor.execute("update inventorystorage SET QTY=%s where BARCODE=%s",
                                ((row[10] - int(Data['QTY'])), Data['BARCODE']))
                 Log.register(request.headers.get('Authorization'),
                              "split : barcode %s with %s" % (Data['BARCODE'], max_barcode['BARCODE']),
                              True)
                 return flask.jsonify(edittag_json_response_array(cursor, (max_barcode['BARCODE'] + 1)))
             else:
                 return {"message": "Quantity you have provided is more than the quantity stored"}, 500
         else:
             return {"message": "barcode %s does not exist" % Data['BARCODE']}, 500
     except InterfaceError as e:
         CreateApi.reAssignDb()
         print(e)
     except Exception as e:
         return {"message": str(e)}, 500
Beispiel #6
0
 def register(access_token, func_name, msg):
     try:
         if msg is True:
             d = datetime.datetime.today().strftime('%Y-%m-%d')
             t = datetime.datetime.today().strftime('%H:%M:%S')
             x = access_token
             try:
                 x = x[2:-1]
             except TypeError:
                 print(x)
             access_token = jwt.decode(x,
                                       'secret',
                                       algorithms='HS256',
                                       verify=False)
             cursor = db.cursor()
             row_count = cursor.execute(
                 "Insert into logs(DATE,TIME,USER,ACTION) VALUES ('" + d +
                 "','" + t + "','" + access_token['UserName'] + "','" +
                 func_name + "')")
             if row_count > 0:
                 print('Logged Succesfully')
                 message = True
             else:
                 print('Log Failure for: ' + access_token['UserName'] +
                       ' ' + func_name)
                 message = False
             db.commit()
             return (message)
     except InterfaceError as e:
         CreateApi.reAssignDb()
         print(e)
     except Exception as e:
         print(e)
Beispiel #7
0
    def put(self):
        try:
            access_token = authenticator(request.headers.get('Authorization'))

            parser = reqparse.RequestParser()
            parser.add_argument('PROJECTID')
            parser.add_argument('PROJECTNAME')
            parser.add_argument('FINISHID')
            parser.add_argument('FINISHNAME')
            args = parser.parse_args()
            cursor = db.cursor()
            if args['PROJECTID'] == '9999':
                return {"message": "stock cannot be edited"}, 500
            update_project_tuple(cursor, args, access_token['UserName'])
            if Log.register(
                    request.headers.get('Authorization'),
                    'Project %s updated with values PNAME:%s, FID:%s ,FNAME:%s'
                    % (args['PROJECTID'], args['PROJECTNAME'],
                       args['FINISHID'], args['FINISHNAME']), True):
                db.commit()
                return {
                    'PROJECTID': args['PROJECTID'],
                    'PROJECTNAME': args['PROJECTNAME'],
                    'FINISHID': args['FINISHID'],
                    'FINISHNAME': args['FINISHNAME']
                }
            else:
                db.rollback()
                return {'Message': 'Try again'}, 500
        except InterfaceError as e:
            CreateApi.reAssignDb()
            print(e)
        except Exception as e:
            return ({'message': str(e)}), 500
Beispiel #8
0
 def get(self):
     try:
         access_token = authenticator(request.headers.get('Authorization'))
         data = request.args
         cursor = db.cursor()
         if data['FINISHID'] == "" and data['FINISHNAME'] == "":
             cursor.execute(
                 'SELECT FINISHID, FINISHNAME FROM colors ORDER BY FINISHNAME'
             )
         elif data['FINISHNAME'] == "":
             cursor.execute(
                 'SELECT FINISHID, FINISHNAME FROM colors WHERE FINISHID LIKE %s ORDER BY FINISHNAME',
                 (data['FINISHID'] + '%'))
         elif data['FINISHID'] == "":
             cursor.execute(
                 'SELECT FINISHID, FINISHNAME FROM colors WHERE FINISHNAME LIKE %s ORDER BY FINISHNAME',
                 (data['FINISHNAME'] + '%'))
         else:
             cursor.execute(
                 'SELECT FINISHID, FINISHNAME FROM colors WHERE FINISHNAME LIKE %s AND FINISHID LIKE %s ORDER BY FINISHNAME',
                 ((data['FINISHNAME'] + '%'), (data['FINISHID'] + '%')))
         colors = cursor.fetchall()
         res = []
         for color in colors:
             res.append({"FINISHID": color[0], "FINISHNAME": color[1]})
         return flask.jsonify(res)
     except InterfaceError as e:
         CreateApi.reAssignDb()
         print(e)
     except Exception as e:
         return ({'message': str(e)}), 500
Beispiel #9
0
 def put(self):
     try:
         parser = reqparse.RequestParser()
         parser.add_argument('oldPassword', required=True, help='oldPassword is Required')
         parser.add_argument('newPassword', required=True, help='newPassword is Required')
         args = parser.parse_args()
         x = request.headers.get('Authorization')
         try:
             x = x[2:-1]
         except TypeError:
             print(x)
         access_token = jwt.decode(x, 'secret', algorithms='HS256', verify=False)
         cursor = db.cursor()
         cursor.execute('SELECT Password FROM users WHERE UserName = %s', (access_token['UserName']))
         pwd = cursor.fetchone()
         if (pwd[0] == args['oldPassword']):
             try:
                 cursor.execute('UPDATE users SET Password = %s WHERE UserName = %s',
                                (args['newPassword'], access_token['UserName']))
             except InterfaceError as e:
                 CreateApi.reAssignDb()
                 print(e)
             except Exception as e:
                 return {"message": "Please try again!"}, 500
             db.commit()
             return {"message": "Password changed successfully"}
         else:
             return {"message": "Password does not match"}, 500
     except InterfaceError as e:
         CreateApi.reAssignDb()
         print(e)
     except Exception as e:
         print(e)
 def get(self):
     try:
         access_token = authenticator(
             flask.request.headers.get('Authorization'))
         message = []
         Date = request.args['date']
         cursor = db.cursor()
         if (Date == ''):
             if cursor.execute(
                     "SELECT distinct UPLOADDATE FROM warehousemanifest"
             ) == 0:
                 return {"message": "no manifest available"}, 404
             else:
                 row = cursor.fetchall()
                 for i in range(0, len(row)):
                     message.append(row[i][0])
         else:
             Date = str(dateparser.parse(Date))
             if cursor.execute(
                     'SELECT NO,UPLOADDATE,SHIPMENTDATE,EXTRUDER,PROJECTID,PROJECTNAME,NBP,BL,MANIFEST,TICKET,SO,ITEM,ASTRO,KEYMARK,DESCRIPTION,FINISHID,FINISHNAME,LENGTH,QTY,LBFT,NETWEIGHT,NOREX,LOCATION,LASTDATE,LASTUSER FROM warehousemanifest where UPLOADDATE = %s',
                     Date) == 0:
                 return {'message': 'press Refresh'}
             else:
                 row = cursor.fetchall()
                 for i in range(0, len(row)):
                     message.append({
                         "NO": row[i][0],
                         "UPLOADDATE": row[i][1],
                         "SHIPMENTDATE": row[i][2],
                         "EXTRUDER": row[i][3],
                         "PROJECTID": row[i][4],
                         "PROJECTNAME": row[i][5],
                         "NBP": row[i][6],
                         "BL": row[i][7],
                         "MANIFEST": row[i][8],
                         "TICKET": row[i][9],
                         "SO": row[i][10],
                         "ITEM": row[i][11],
                         "ASTRO": row[i][12],
                         "KEYMARK": row[i][13],
                         "DESCRIPTION": row[i][14],
                         "FINISHID": row[i][15],
                         "FINISHNAME": row[i][16],
                         "LENGTH": row[i][17],
                         "QTY": row[i][18],
                         "LBFT": row[i][19],
                         "NETWEIGHT": row[i][20],
                         "NOREX": row[i][21],
                         "LOCATION": row[i][22],
                         "LASTDATE": row[i][23],
                         "LASTUSER": row[i][24]
                     })
         return flask.jsonify(message)
     except InterfaceError as e:
         CreateApi.reAssignDb()
         print(e)
     except Exception as e:
         return {'message': 'try again'}, 500
def get_color(cursor, color):
    try:
        row_count = cursor.execute(
            'select FINISHID from colors where FINISHNAME = %s', color)
        if row_count == 0:
            raise ColorNotFound("Can not find UC number for: %s" % color)
        return cursor.fetchone()
    except InterfaceError as e:
        CreateApi.reAssignDb()
        print(e)
def get_max_norex(cursor):
    try:
        max_norex = cursor.execute(
            "select MAX(NOREX) from rawvalues where LOCATION = 'teterboro'")
        max = cursor.fetchone()
    except InterfaceError as e:
        CreateApi.reAssignDb()
        print(e)
    except Exception as e:
        return {"message": str(e)}, 500
    return {"NOREX": max[0]}
def get_max_barcode(cursor):
    try:
        max_barcode = cursor.execute(
            "select MAX(BARCODE) from inventorystorage")
        max = cursor.fetchone()
    except InterfaceError as e:
        CreateApi.reAssignDb()
        print(e)
    except Exception as e:
        return {"message": str(e)}, 500
    return {"BARCODE": max[0]}
Beispiel #14
0
 def get(self):
     access_token = authenticator(request.headers.get('Authorization'))
     barcode = request.args.get('BARCODE')
     try:
         cursor = db.cursor()
         return flask.jsonify(edittag_json_response_array(cursor, barcode))
     except InterfaceError as e:
         CreateApi.reAssignDb()
         print(e)
     except Exception as e:
         return {'message': str(e)}, 500
Beispiel #15
0
 def put(self):
     try:
         access_token = authenticator(request.headers.get('Authorization'))
         data = request.get_json()
         cursor = db.cursor()
         values = []
         cursor.execute(
             'UPDATE colors SET FINISHNAME = %s, LASTDATE = %s,LASTUSER = %s WHERE FINISHID = %s',
             (data['FINISHNAME'], datetime.datetime.now(),
              access_token['UserName'], data['FINISHID']))
         if cursor.execute(
                 'SELECT PROJECTID FROM projects WHERE FINISHID = %s',
                 data['FINISHID']) != 0:
             projects = cursor.fetchall()
             for project in projects:
                 values.append('"' + project[0] + '"')
             values = '(' + ','.join(values) + ')'
             cursor.execute(
                 'update projects set FINISHNAME = %s, LASTDATE = %s,LASTUSER = %s WHERE PROJECTID IN '
                 + values, (data['FINISHNAME'], datetime.datetime.now(),
                            access_token['UserName']))
             cursor.execute(
                 'update inventorystorage set FINISHNAME = %s, LASTDATE = %s,LASTUSER = %s WHERE FINISHID != "MILL FINISH" AND FINISHID != "CLEAR ANODIZE" AND PROJECTID IN '
                 + values, (data['FINISHNAME'], datetime.datetime.now(),
                            access_token['UserName']))
             cursor.execute(
                 'update bufferpurchasingmanifest set FINISHNAME = %s, LASTDATE = %s,LASTUSER = %s WHERE FINISHID != "MILL FINISH" AND FINISHID != "CLEAR ANODIZE" AND PROJECTID IN '
                 + values, (data['FINISHNAME'], datetime.datetime.now(),
                            access_token['UserName']))
             cursor.execute(
                 'update purchasingmanifest set FINISHNAME = %s, LASTDATE = %s,LASTUSER = %s WHERE FINISHID != "MILL FINISH" AND FINISHID != "CLEAR ANODIZE" AND PROJECTID IN '
                 + values, (data['FINISHNAME'], datetime.datetime.now(),
                            access_token['UserName']))
             cursor.execute(
                 'update warehousemanifest set FINISHNAME = %s, LASTDATE = %s,LASTUSER = %s WHERE FINISHID != "MILL FINISH" AND FINISHID != "CLEAR ANODIZE" AND PROJECTID IN '
                 + values, (data['FINISHNAME'], datetime.datetime.now(),
                            access_token['UserName']))
             cursor.execute(
                 'update rejection set FINISHNAME = %s, LASTDATE = %s,LASTUSER = %s WHERE FINISHID != "MILL FINISH" AND FINISHID != "CLEAR ANODIZE" AND PROJECTID IN '
                 + values, (data['FINISHNAME'], datetime.datetime.now(),
                            access_token['UserName']))
         if Log.register(
                 request.headers.get('Authorization'),
                 'FINISH ID %s updated with FNAME:%s and it updated projects: %s'
                 % (data['FINISHID'], data['FINISHNAME'], values), True):
             db.commit()
         return flask.jsonify(data)
     except InterfaceError as e:
         CreateApi.reAssignDb()
         print(e)
     except Exception as e:
         db.rollback()
         return {"message": str(e)}, 500
Beispiel #16
0
 def post(self):
     try:
         access_token = authenticator(request.headers.get('Authorization'))
         parser = reqparse.RequestParser()
         parser.add_argument('NOREX')
         parser.add_argument('LOCATION')
         parser.add_argument('ASTRO')
         parser.add_argument('KEYMARK')
         parser.add_argument('EASCO')
         parser.add_argument('WINSYS')
         parser.add_argument('DESCRIPTION')
         parser.add_argument('MODEL')
         parser.add_argument('LBFT')
         parser.add_argument('SH')
         parser.add_argument('CAVITY')
         parser.add_argument('IMAGE')
         args = parser.parse_args()
         cursor = db.cursor()
         row_count = cursor.execute(
             'insert into rawvalues(NOREX,LOCATION,ASTRO,KEYMARK,EASCO,WINSYS,DESCRIPTION,MODEL,LBFT,SH,CAVITY,IMAGE,LASTDATE,LASTUSER) values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)',
             (args['NOREX'], args['LOCATION'], args['ASTRO'],
              args['KEYMARK'], args['EASCO'], args['WINSYS'],
              args['DESCRIPTION'], args['MODEL'], args['LBFT'],
              args['SH'], args['CAVITY'], args['IMAGE'],
              datetime.datetime.now(), access_token['UserName']))
         if row_count > 0:
             if Log.register(
                     request.headers.get('Authorization'),
                     'New NOREX added with NOREXID: %s ,LOCATION: %s,ASTRO: %s,KEYMARK: %s,EASCO: %s,WINSYS: %s,DESCRIPTION: %s,MODEL: %s,LBFT: %s,SH: %s,CAVITY: %s,'
                     % (args['NOREX'], args['LOCATION'], args['ASTRO'],
                        args['KEYMARK'], args['EASCO'], args['WINSYS'],
                        args['DESCRIPTION'], args['MODEL'], args['LBFT'],
                        args['SH'], args['CAVITY']), True):
                 db.commit()
                 return {'Message': 'Successful'}
             else:
                 db.rollback()
                 return {'message': 'Error - Try Again'}, 500
         else:
             db.rollback()
             return {'message': 'Error - Try Again'}, 500
     except InterfaceError as e:
         CreateApi.reAssignDb()
         print(e)
     except Exception as e:
         if "Duplicate entry" in str(e):
             message = {
                 'message': "Norex %s already exists." % args['NOREX']
             }
         else:
             message = {"message": str(e)}
         db.rollback()
         return message, 500
 def post(self):
     try:
         x = request.headers.get('Authorization')
         try:
             x = x[2:-1]
         except TypeError:
             print(x)
         access_token = jwt.decode(x,
                                   'secret',
                                   algorithms='HS256',
                                   verify=False)
         parser = reqparse.RequestParser()
         parser.add_argument('UserName',
                             required=True,
                             help='UserName is Required')
         parser.add_argument('Role', required=True, help='Role is Required')
         args = parser.parse_args()
         cursor = db.cursor()
         try:
             row_count = cursor.execute(
                 "Insert into users(UserName,Password,Role,LASTDATE,LASTUSER) VALUES (%s,%s,%s,%s,%s)",
                 (args['UserName'], '123456', args['Role'],
                  datetime.datetime.now(), access_token['UserName']))
         except InterfaceError as e:
             CreateApi.reAssignDb()
             print(e)
         except Exception as e:
             print(e.args[1])
             if ("Duplicate entry" in e.args[1]):
                 raise BadRequest("user already exists")
             else:
                 raise BadRequest(str(e.args[1]))
         row = cursor.fetchone()
         l = Log
         x = True
         x = l.register(request.headers.get('Authorization'),
                        'Add User:%s' % args['UserName'], True)
         if x == True:
             db.commit()
         message = {
             'message': 'adduser',
             'data': {
                 "UserName": args['UserName'],
                 "Role": args['Role']
             }
         }
         return (message)
     except InterfaceError as e:
         CreateApi.reAssignDb()
         print(e)
     except Exception as e:
         print(e)
Beispiel #18
0
 def get(self):
     try:
         access_token = authenticator(request.headers.get('Authorization'))
         message = []
         query = "Select NOREX, LOCATION, ASTRO, KEYMARK, EASCO, WINSYS, DESCRIPTION, MODEL, LBFT, SH, CAVITY, LASTDATE, LASTUSER, IMAGE from rawvalues where "
         COUNT = request.args.get('COUNT')
         COUNT = int(COUNT)
         COLUMN = request.args.get('COLUMN')
         VALUE = request.args.get('VALUE')
         if COUNT >= 1:
             COLUMN = COLUMN.split(',')
             VALUE = VALUE.split(',')
             for i in range(0, COUNT):
                 if i == COUNT - 1:
                     query = query + COLUMN[COUNT -
                                            1] + '= \'' + VALUE[COUNT -
                                                                1] + '\''
                     break
                 query = query + COLUMN[i] + '= \'' + VALUE[i] + '\' AND '
         else:
             query = query + COLUMN + ' 1'
         print('QUERY :' + query)
         cursor = db.cursor()
         row_count = cursor.execute(query)
         if (row_count == 0):
             return {"message": "norex does not exists"}, 404
         row = cursor.fetchall()
         for i in range(0, row_count):
             m = {
                 "NOREX": row[i][0],
                 "LOCATION": row[i][1],
                 "ASTRO": row[i][2],
                 "KEYMARK": row[i][3],
                 "EASCO": row[i][4],
                 "WINSYS": row[i][5],
                 "DESCRIPTION": row[i][6],
                 "MODEL": row[i][7],
                 "LBFT": row[i][8],
                 "SH": row[i][9],
                 "CAVITY": row[i][10],
                 "LASTDATE": row[i][11],
                 "LASTUSER": row[i][12],
                 "IMAGE": row[i][13],
             }
             message.append(m)
         return (flask.jsonify(message))
     except InterfaceError as e:
         CreateApi.reAssignDb()
         print(e)
     except Exception as e:
         print(e)
Beispiel #19
0
 def put(self):
     try:
         Data = flask.request.get_json()
         message={}
         cursor = db.cursor()
         row = cursor.execute("SELECT SHIPMENTDATE,PROJECTID,PROJECTNAME,NBP,ASTRO,KEYMARK,DESCRIPTION,FINISHID,FINISHNAME,LENGTH,QTY,LBFT,NETWEIGHT,NOREX,LOCATION,LOCATIONGRID,MODEL,EASCO,EXTRUDER,NAtoLOC,TAGSTATUS,LASTDATE,LASTUSER,TICKET FROM inventorystorage where LASTDATE between"+Data['startDate']+"AND"+Data['endDate'])
         rowCount = cursor.fetchall()
         if(rowCount>0):
             for i in range (0,rowCount):
                 model_count = cursor.execute(
                     'SELECT IMAGE from rawvalues where NOREX = %s and LOCATION = %s'+(rowCount[i][13], rowCount[i][14]))
                 model = cursor.one()
                 if (model_count > 0):
                     message.append({
                         "SHIPMENTDATE": row[i][0],
                         "PROJECTID": row[i][1],
                         "PROJECTNAME": row[i][2],
                         "NBP": row[i][3],
                         "ASTRO": row[i][4],
                         "KEYMARK": row[i][5],
                         "DESCRIPTION": row[i][6],
                         "FINISHID": row[i][7],
                         "FINISHNAME": row[i][8],
                         "LENGTH": row[i][9],
                         "QTY": row[i][10],
                         "LBFT": row[i][11],
                         "NETWEIGHT": row[i][12],
                         "NOREX": row[i][13],
                         "LOCATION": row[i][14],
                         "LOCATIONGRID": row[i][15],
                         "MODEL": row[i][16],
                         "EASCO": row[i][17],
                         "EXTRUDER": row[i][18],
                         "NAtoLOC": row[i][19],
                         "TAGSTATUS": row[i][20],
                         "LASTDATE": row[i][21],
                         "LASTUSER": row[i][22],
                         "TICKET": row[i][23],
                         "IMAGE": model[0]
                     })
                     print(message)
                 else:
                     return {"message": "image does not exist"}, 500
         else:
             return {"message": "No record exists"}, 500
     except InterfaceError as e:
          CreateApi.reAssignDb()
          print(e)
     except Exception as e:
         return {"message": str(e)}, 500
def get_from_buffer_manifest(cursor, user, replacement):
    try:
        if replacement:
            row_count = cursor.execute(
                'select NO,UPLOADDATE,SHIPMENTDATE,EXTRUDER,PROJECTID,PROJECTNAME,NBP,BL,MANIFEST,TICKET,SO,ITEM,ASTRO,KEYMARK,DESCRIPTION,FINISHID,FINISHNAME,LENGTH,QTY,LBFT,NETWEIGHTexcel,NETWEIGHTnorex,NOREX,LOCATION,MODEL,USER,LASTDATE,LASTUSER,REPLACEMENT from bufferpurchasingmanifest where REPLACEMENT = 1 AND USER = %s',
                user)
        else:
            row_count = cursor.execute(
                'select NO,UPLOADDATE,SHIPMENTDATE,EXTRUDER,PROJECTID,PROJECTNAME,NBP,BL,MANIFEST,TICKET,SO,ITEM,ASTRO,KEYMARK,DESCRIPTION,FINISHID,FINISHNAME,LENGTH,QTY,LBFT,NETWEIGHTexcel,NETWEIGHTnorex,NOREX,LOCATION,MODEL,USER,LASTDATE,LASTUSER,REPLACEMENT from bufferpurchasingmanifest where USER = %s',
                user)
        row = cursor.fetchall()
        response = []
        for i in range(0, row_count):
            response.append({
                "NO": row[i][0],
                "UPLOADDATE": row[i][1],
                "SHIPMENTDATE": row[i][2],
                "EXTRUDER": row[i][3],
                "PROJECTID": row[i][4],
                "PROJECTNAME": row[i][5],
                "NBP": row[i][6],
                "BL": row[i][7],
                "MANIFEST": row[i][8],
                "TICKET": row[i][9],
                "SO": row[i][10],
                "ITEM": row[i][11],
                "ASTRO": row[i][12],
                "KEYMARK": row[i][13],
                "DESCRIPTION": row[i][14],
                "FINISHID": row[i][15],
                "FINISHNAME": row[i][16],
                "LENGTH": row[i][17],
                "QTY": row[i][18],
                "LBFT": row[i][19],
                "NETWEIGHTexcel": row[i][20],
                "NETWEIGHTnorex": row[i][21],
                "NOREX": row[i][22],
                "LOCATION": row[i][23],
                "MODEL": row[i][24],
                "USER": row[i][25],
                "LASTDATE": row[i][26],
                "LASTUSER": row[i][27],
                "REPLACEMENT": row[i][28]
            })
        return response
    except InterfaceError as e:
        CreateApi.reAssignDb()
        print(e)
    except Exception as e:
        print(e)
Beispiel #21
0
 def get(self):
     try:
         access_token = authenticator(request.headers.get('Authorization'))
         Data = request.args.get('status')
         cursor = db.cursor()
         if Data == "norex":
             return flask.jsonify(get_max_norex(cursor))
         elif Data == "project":
             return flask.jsonify(get_max_project(cursor))
     except InterfaceError as e:
         CreateApi.reAssignDb()
         print(e)
     except Exception as e:
         return {"message": str(e)}, 500
def update_project(cursor, project_id, table, key_name, key, user, Role):
    # cursor is db.cursor
    # project_ id is new project id
    # table is table name
    # key_name is primary key's name
    # key is primary key value
    # user is person who called the function
    try:
        key_count = cursor.execute(
            'SELECT FINISHNAME,FINISHID from ' + table + ' where ' + key_name +
            ' = %s', (key))
        finish_name = cursor.fetchone()
        if finish_name[0] == 'MILL FINISH' or finish_name[
                0] == 'CLEAR ANODIZE' or project_id == '9999':
            project_count = cursor.execute(
                "SELECT PROJECTNAME from projects where PROJECTID = %s",
                (project_id))
            if project_count == 0:
                raise ProjectNotFound('Project not found')
            project = cursor.fetchone()
            row_count = cursor.execute(
                'UPDATE ' + table +
                ' SET PROJECTID = %s , PROJECTNAME = %s ,LASTDATE = %s ,LASTUSER = %s where '
                + key_name + ' = %s',
                (project_id, project[0], datetime.datetime.now(), user, key))
            if row_count == 0:
                return False
        else:
            project_count = cursor.execute(
                "SELECT PROJECTNAME, FINISHID, FINISHNAME from projects where PROJECTID = %s",
                (project_id))
            if project_count == 0:
                raise ProjectNotFound('Project not found')
            project = cursor.fetchone()
            if finish_name[1] == project[1] or Role == 'admin':
                row_count = cursor.execute(
                    'UPDATE ' + table +
                    ' SET PROJECTID = %s, PROJECTNAME = %s, FINISHID = %s, FINISHNAME = %s,LASTDATE = %s ,LASTUSER = %s where '
                    + key_name + ' = %s',
                    (project_id, project[0], project[1], project[2],
                     datetime.datetime.now(), user, key))
                if row_count == 0:
                    return False
            else:
                raise InvalidProjectUpdate(
                    "Finish of current project and new project is not same")
        return True
    except InterfaceError as e:
        CreateApi.reAssignDb()
        print(e)
 def put(self):
     try:
         access_token = authenticator(
             flask.request.headers.get('Authorization'))
         Data = flask.request.get_json()
         cursor = db.cursor()
         cursor.execute(
             "select QTY from inventorystorage where BARCODE = %s",
             (Data['BARCODE']))
         prev_qty = cursor.fetchone()
         if prev_qty[0] - Data['QTY'] >= 0:
             if cursor.execute(
                     'UPDATE inventorystorage set TAGSTATUS = 1, QTY = QTY - %s where BARCODE = %s',
                 (Data['QTY'], Data['BARCODE'])) == 0:
                 db.rollback()
                 return {
                     'message': 'Error - Could not find the BARCODE'
                 }, 404
             row_count = cursor.execute(
                 "select QTY from inventorystorage where BARCODE = %s",
                 (Data['BARCODE']))
             if row_count > 0:
                 row = cursor.fetchone()
                 if row[0] == 0:
                     count = move_to_empty_storage(cursor, Data['BARCODE'],
                                                   access_token['UserName'])
                     if count > 0:
                         if Log.register(
                                 request.headers.get('Authorization'),
                                 'Completed cutting all the items of barcode:%s and moved to empty storage'
                                 % Data['BARCODE'], True):
                             db.commit()
                     else:
                         return {'message': 'please try again'}, 404
                 else:
                     if Log.register(
                             request.headers.get('Authorization'),
                             'Operated on %s items of Barcode %s, remaining Quantity is %s '
                             % (Data['QTY'], str(Data['BARCODE']), row[0]),
                             True):
                         db.commit()
             return "success"
         else:
             return "contact superior", 500
     except InterfaceError as e:
         CreateApi.reAssignDb()
         print(e)
     except Exception as e:
         return {"message": str(e)}, 500
def get_project(cursor, project_id):
    try:
        row_count = cursor.execute(
            'select PROJECTNAME,FINISHID,FINISHNAME from projects where PROJECTID = %s',
            project_id)
        if row_count == 0:
            raise ProjectNotFound("Can not find PROJECT: %s" % project_id)
        fetchedProject = cursor.fetchone()
        if fetchedProject[1] == "" or fetchedProject[2] == "":
            raise ColorNotFound("Please enter finish for PROJECT ID:%s" %
                                project_id)
        return fetchedProject
    except InterfaceError as e:
        CreateApi.reAssignDb()
        print(e)
def get_max_project(cursor):
    try:
        row_count = cursor.execute(
            "select MAX(PROJECTID) from projects WHERE PROJECTID != '9999'")
        max = cursor.fetchone()
        row_count = cursor.execute(
            "select max(PROJECTID) from projects WHERE PROJECTID LIKE '" +
            str(max[0]) + "%'")
        max = cursor.fetchone()
        return {"PROJECT": max[0]}
    except InterfaceError as e:
        CreateApi.reAssignDb()
        print(e)
    except Exception as e:
        raise Exception(e)
def get_rejection_for_replacement(cursor, replacementProject,
                                  replacementNorex):
    try:
        rejection = []
        rejectionQuery = ""
        for i in range(0, len(replacementProject) - 1):
            rejectionQuery += '(NOREX = "' + replacementNorex[
                i] + '" AND PROJECTID = "' + replacementProject[i] + '") OR '
        rejectionQuery += '(NOREX = "' + replacementNorex[len(replacementProject) - 1] + '" AND PROJECTID = "' + \
                          replacementProject[len(replacementProject) - 1] + '")'
        row_count = cursor.execute(
            'select REJECTIONDATE,BARCODE,TAG,SHIPMENTDATE,PROJECTID,PROJECTNAME,NBP,ASTRO,KEYMARK,DESCRIPTION,FINISHID,FINISHNAME,LENGTH,QTY,LBFT,NETWEIGHT,NOREX,LOCATION,LOCATIONGRID,MODEL,EASCO,EXTRUDER,TAGSTATUS,LASTDATE,LASTUSER from rejection where '
            + rejectionQuery)
        row = cursor.fetchall()
        for i in range(0, row_count):
            rejection.append({
                "REJECTIONDATE": row[i][0],
                "BARCODE": row[i][1],
                "TAG": row[i][2],
                "SHIPMENTDATE": row[i][3],
                "PROJECTID": row[i][4],
                "PROJECTNAME": row[i][5],
                "NBP": row[i][6],
                "ASTRO": row[i][7],
                "KEYMARK": row[i][8],
                "DESCRIPTION": row[i][9],
                "FINISHID": row[i][10],
                "FINISHNAME": row[i][11],
                "LENGTH": row[i][12],
                "QTY": row[i][13],
                "LBFT": row[i][14],
                "NETWEIGHT": row[i][15],
                "NOREX": row[i][16],
                "LOCATION": row[i][17],
                "LOCATIONGRID": row[i][18],
                "MODEL": row[i][19],
                "EASCO": row[i][20],
                "EXTRUDER": row[i][21],
                "TAGSTATUS": row[i][22],
                "LASTDATE": row[i][23],
                "LASTUSER": row[i][24]
            })
        return rejection
    except InterfaceError as e:
        CreateApi.reAssignDb()
        print(e)
    except Exception as e:
        print(e)
Beispiel #27
0
 def post(self):
     try:
         access_token = authenticator(request.headers.get('Authorization'))
         parser = reqparse.RequestParser()
         parser.add_argument('PROJECTID')
         parser.add_argument('PROJECTNAME')
         parser.add_argument('FINISHID')
         parser.add_argument('FINISHNAME')
         args = parser.parse_args()
         cursor = db.cursor()
         row_count = cursor.execute(
             "insert into projects (PROJECTID,PROJECTNAME,FINISHID,FINISHNAME,LASTDATE,LASTUSER) values(%s,%s,%s,%s,%s,%s)",
             (args['PROJECTID'],
              args['PROJECTNAME'], args['FINISHID'], args['FINISHNAME'],
              datetime.datetime.now(), access_token['UserName']))
         if row_count > 0:
             if Log.register(
                     request.headers.get('Authorization'),
                     'New Project added with PID:%s ,PNAME:%s, FID:%s ,FNAME:%s'
                     % (args['PROJECTID'], args['PROJECTNAME'],
                        args['FINISHID'], args['FINISHNAME']), True):
                 db.commit()
                 return ({
                     'PROJECTID': args['PROJECTID'],
                     'PROJECTNAME': args['PROJECTNAME'],
                     'FINISHID': args['FINISHID'],
                     'FINISHNAME': args['FINISHNAME']
                 })
             else:
                 db.rollback()
                 return ({'message': 'Error - Try Again'}), 500
         else:
             db.rollback()
             return ({'message': 'Error - Try Again'}), 500
     except InterfaceError as e:
         CreateApi.reAssignDb()
         print(e)
     except Exception as e:
         if "Duplicate entry" in str(e):
             message = {
                 'message': "Project %s already exists." % args['PROJECTID']
             }
         else:
             message = {"message": str(e)}
         db.rollback()
         return message, 500
 def post(self):
     access_token = authenticator(
         flask.request.headers.get('Authorization'))
     try:
         data = flask.request.get_json()
         cursor = db.cursor()
         rep = data['replacement']
         for i in range(0, len(rep)):
             if (int(rep[i]['rejection'])) > 0:
                 if cursor.execute(
                         'DELETE FROM rejection WHERE BARCODE = %s',
                         rep[i]['rejection']) > 0:
                     if cursor.execute(
                             'select TICKET from bufferpurchasingmanifest where NO = %s',
                             rep[i]['replacement']) > 0:
                         ticket = cursor.fetchone()
                         cursor.execute(
                             'UPDATE bufferpurchasingmanifest SET REPLACEMENT = 0 WHERE NO = %s',
                             (rep[i]['replacement']))
                         cursor.execute(
                             'UPDATE inventorystorage SET DESCRIPTION = %s WHERE BARCODE = %s',
                             ("replaced with " + str(ticket[0]),
                              rep[i]['rejection']))
                         if not Log.register(
                                 flask.request.headers.get('Authorization'),
                                 "Replace item " +
                                 str(rep[i]['replacement']), True):
                             db.rollback()
                             return {'message': 'try again'}, 500
                     else:
                         db.rollback()
                         return {'message': 'try again'}, 500
                 else:
                     db.rollback()
                     return {'message': 'try again'}, 500
         db.commit()
         return flask.jsonify(
             get_from_buffer_manifest(cursor, access_token['UserName'],
                                      False))
     except InterfaceError as e:
         CreateApi.reAssignDb()
         print(e)
     except Exception as e:
         db.rollback()
         return {'message': 'try again'}, 500
Beispiel #29
0
 def get(self):
     try:
         access_token = authenticator(request.headers.get('Authorization'))
         message = []
         COUNT = int(request.args.get('COUNT'))
         COLUMN = request.args.get('COLUMN')
         VALUE = request.args.get('VALUE')
         print(request.args.get('ACTIVE'))
         if request.args.get('ACTIVE') == 'true':
             query = "Select DISTINCT PROJECTID, PROJECTNAME, FINISHID, FINISHNAME " \
                     "from inventorystorage " \
                     "where FINISHID != '' AND "
         else:
             query = "Select PROJECTID, PROJECTNAME, FINISHID, FINISHNAME from projects where "
         print(query)
         if COUNT >= 1:
             COLUMN = COLUMN.split(',')
             VALUE = VALUE.split(',')
             for i in range(0, COUNT):
                 if i == COUNT - 1:
                     query = query + COLUMN[
                         COUNT - 1] + ' LIKE \'%' + VALUE[COUNT - 1] + '%\''
                     break
                 query = query + COLUMN[i] + ' LIKE \'%' + VALUE[
                     i] + '%\' AND '
         else:
             query = query + COLUMN + ' 1'
         cursor = db.cursor()
         row_count = cursor.execute(query)
         if row_count == 0:
             return {"message": "project not found"}, 400
         row = cursor.fetchall()
         for i in range(0, row_count):
             message.append({
                 "PROJECTID": row[i][0],
                 "PROJECTNAME": row[i][1],
                 "FINISHID": row[i][2],
                 "FINISHNAME": row[i][3]
             })
         return flask.jsonify(message)
     except InterfaceError as e:
         CreateApi.reAssignDb()
         print(e)
     except Exception as e:
         return ({'message': str(e)}), 500
 def put(self):
     try:
         x = request.headers.get('Authorization')
         try:
             x = x[2:-1]
         except TypeError:
             print(x)
         access_token = jwt.decode(x,
                                   'secret',
                                   algorithms='HS256',
                                   verify=False)
         parser = reqparse.RequestParser()
         parser.add_argument('Role')
         parser.add_argument('UserName')
         args = parser.parse_args()
         cursor = db.cursor()
         row_count = cursor.execute(
             'UPDATE users SET Role = %s ,LASTDATE = %s ,LASTUSER = %s WHERE UserName = %s',
             (args['Role'], datetime.datetime.now(),
              access_token['UserName'], args['UserName']))
         if row_count > 0:
             l = Log
             x = l.register(
                 request.headers.get('Authorization'),
                 'UPDATE Role: %s of User: %s' %
                 (args['Role'], args['UserName']), True)
             if x == True:
                 db.commit()
                 return ({
                     'message': 'updateuser',
                     'data': {
                         "UserName": args['UserName'],
                         "Role": args['Role']
                     }
                 })
             else:
                 raise BadRequest("Try Again")
         else:
             raise BadRequest("Try Again")
     except InterfaceError as e:
         CreateApi.reAssignDb()
         print(e)
     except Exception as e:
         print(e)