Esempio n. 1
0
def Entry_Goods_Receive_GA(request):
    if request.method == 'POST':
        form = NA_Goods_Receive_GA_Form(request.POST)
        if form.is_valid():
            try:
                result = form.save(request=request)
            except NAError as e:
                result = NAErrorHandler.handle(err=e)
        else:
            result = NAErrorHandler.handle_form_error(form_error=form.errors)
        return commonFunct.response_default(result)

    elif request.method == 'GET':
        statusForm = request.GET['statusForm']
        if statusForm == 'Edit' or statusForm == 'Open':
            idapp = request.GET['idapp']
            data, result = NAGaReceive.objects.retrieveData(idapp)
            if data == Data.Success:
                # result = [i for i in result][0]
                # if isinstance(result['datereceived'], datetime):
                #     result['datereceived'] = result['datereceived'].strftime(
                #         '%d/%m/%Y')

                # if isinstance(result['year_made'], date):
                #     result['year_made'] = result['year_made'].strftime('%Y')
                form = NA_Goods_Receive_GA_Form(initial=result)
            elif data == Data.Lost:
                return commonFunct.response_default((data, result))
        else:
            form = NA_Goods_Receive_GA_Form()
        return render(request,
                      'app/Transactions/NA_Entry_Goods_Receive_GA.html',
                      {'form': form})
Esempio n. 2
0
def Entry_Goods_Receive_other(request):
    if request.method == 'POST':
        form = NA_Goods_Receive_other_Form(request.POST)
        statusForm = request.POST['statusForm']
        if form.is_valid():
            data = getFormData(form)
            if statusForm == 'Add':
                data['createddate'] = datetime.now()
                data['createdby'] = request.user.username
            elif statusForm == 'Edit':
                data['modifieddate'] = datetime.now()
                data['modifiedby'] = request.user.username
            result = NAGoodsReceive_other.objects.SaveData(
                StatusForm.Input, **data)
            return commonFunct.response_default(result)

    elif request.method == 'GET':
        statusForm = request.GET['statusForm']
        if statusForm == 'Edit' or statusForm == 'Open':
            idapp = request.GET['idapp']
            data, result = NAGoodsReceive_other.objects.retrieveData(idapp)
            if data == Data.Success:
                if isinstance(result['datereceived'], datetime):
                    result['datereceived'] = result['datereceived'].strftime(
                        '%d/%m/%Y')
                form = NA_Goods_Receive_other_Form(initial=result)
            elif data == Data.Lost:
                return commonFunct.response_default((data, result))
        else:
            form = NA_Goods_Receive_other_Form()
        return render(request,
                      'app/Transactions/NA_Entry_Goods_Receive_other.html',
                      {'form': form})
Esempio n. 3
0
def EntryEmployee(request):
    if request.method == 'POST':
        form = NA_Employee_form(request.POST)
        if form.is_valid():
            try:
                result = form.save(user=request.user.username)
            except NAError as e:
                # error kalau user salah input, ada form yang tidak di isi
                result = NAErrorHandler.handle(err=e)
        else:
            result = NAErrorHandler.handle_form_error(form_error=form.errors)
        return commonFunct.response_default(result)
    elif request.method == 'GET':
        idapp = request.GET['idapp']
        mode = request.GET['mode']
        employee = Employee()
        if mode == 'Edit' or mode == 'Open':
            try:
                result = Employee.objects.get(idapp=idapp)
            except employee.DoesNotExist:
                result = NAErrorHandler.handle_data_lost(model=Employee,
                                                         pk=idapp)
                return commonFunct.response_default(result)
            else:
                form = NA_Employee_form(initial=forms.model_to_dict(result))
                form.fields['nik'].widget.attrs['disabled'] = 'disabled'
        else:
            form = NA_Employee_form()
            del form.fields['inactive']
        return render(request, 'app/MasterData/NA_Entry_Employee.html',
                      {'form': form})
Esempio n. 4
0
def getLastTrans(request):
    serialnumber = request.GET['serialnumber']
    result = ''
    try:
        result = NAGoodsReturn.objects.getLastTrans(serialnumber)
        if len(result) > 0:
            return commonFunct.response_default(result)
        else:
            return commonFunct.response_default((Data.Empty, ))
    except Exception as e:
        return commonFunct.response_default((Data.Empty, e))
Esempio n. 5
0
def Entry_Privilege(request):
    if request.method == 'POST':
        form = NAPrivilegeForm(request.POST)
        if form.is_valid():
            try:
                result = form.save(user=request.user.username)
            except NAError as e:
                result = NAErrorHandler.handle(err=e)
        else:
            result = NAErrorHandler.handle_form_error(form_error=form.errors)
        return commonFunct.response_default(result)
    elif request.method == 'GET':
        statusForm = request.GET['statusForm']
        if statusForm == 'Edit' or statusForm == 'Open':
            idapp = request.GET['idapp']
            data = NAPrivilege.objects.retrieveData(idapp)
            form = NAPrivilegeForm(initial=data)
            if int(data['role']) == NAPrivilege.GUEST:
                form.fields['divisi'].widget.attrs['disabled'] = ''
        else:
            form = NAPrivilegeForm()
            form.fields['password'].widget.attrs['required'] = ''
            form.fields['confirm_password'].widget.attrs['required'] = ''
            form.fields['divisi'].widget.attrs['disabled'] = ''
        return render(request, 'app/MasterData/NA_Entry_Privilege.html', {'form': form})
 def post(self, request):
     form = NAEquipmentForm(request.POST)
     if form.is_valid():
         result = form.save(request=request)
         return commonFunct.response_default(result)
     else:
         raise forms.ValidationError(form.errors)
Esempio n. 7
0
 def post(self, request):
     form = NAExtendGaVnHistoryForm(request.POST)
     if form.is_valid():
         result = form.save()
     else:
         result = NAErrorHandler.handle_form_error(form_error=form.errors)
     return commonFunct.response_default(result)
def NA_Priviledge_change_picture(request, email):
    if request.user.email != email:
        return commonFunct.permision_denied('<h1>403 Forbidden</h1>')
    user = NAPriviledge.objects.get(idapp=request.user.idapp)
    picture = request.FILES['picture']
    user.picture = picture
    user.save()
    return commonFunct.response_default((Data.Success, user.get_picture_name()))
def ChangeRole(request, email):
    user = NAPriviledge.objects.get(email=email)
    role = request.POST['role']
    divisi = request.POST['divisi']
    user.role = role
    user.divisi = divisi
    user.save()
    return commonFunct.response_default((Data.Success,))
Esempio n. 10
0
def NA_Employee_delete(request):
    idapp = request.POST.get('idapp')
    try:
        employee = Employee.objects.get(idapp=idapp)
    except employee.DoesNotExist:
        result = NAErrorHandler.handle_data_lost(pk=idapp, model=Employee)
    else:
        if Employee.objects.hasRef(idapp=idapp):
            message = Message.HasRef_del.value
            return commonFunct.response_default((Data.HasRef, message))
        with transaction.atomic():
            log = LogActivity(models=Employee,
                              activity=LogActivity.DELETED,
                              user=request.user.username,
                              data=employee)
            log.record_activity()
            employee.delete()
            result = Data.Success,
    return commonFunct.response_default(result)
def EntryEmployee(request):
    if request.method == 'POST':
        form = NA_Employee_form(request.POST)
        if form.is_valid():
            mode = request.POST['mode']
            data = getData(request, form)
            if mode == 'Add':
                data['createddate'] = datetime.datetime.now()
                data['createdby'] = getCurrentUser(request)
                result = Employee.objects.SaveData(**data)
                return commonFunct.response_default(result)
            elif mode == 'Edit':
                getIdapp = request.POST['idapp']
                data['idapp'] = getIdapp
                data['modifieddate'] = datetime.datetime.now()
                data['modifiedby'] = getCurrentUser(request)
                result = Employee.objects.SaveData(StatusForm.Edit, **data)
                return commonFunct.response_default(result)
            elif mode == 'Open':
                if request.POST['employee_name']:
                    return HttpResponse(json.dumps({
                        'messages':
                        'You\'re try to Edit this Data \
                            with Open Mode\nWith technic inspect element\n Lol :D'
                    }),
                                        status=403,
                                        content_type='application/json')
    elif request.method == 'GET':
        idapp = request.GET['idapp']
        mode = request.GET['mode']
        if mode == 'Edit' or mode == 'Open':
            result = Employee.objects.retriveData(idapp)
            if result[0] == Data.Lost:
                return HttpResponse(json.dumps({'message': result[0]}),
                                    status=404,
                                    content_type='application/json')
            form = NA_Employee_form(initial=result[1])
            form.fields['nik'].widget.attrs['disabled'] = 'disabled'
        else:
            form = NA_Employee_form()
            del form.fields['inactive']
        return render(request, 'app/MasterData/NA_Entry_Employee.html',
                      {'form': form})
Esempio n. 12
0
def Entry_Goods_Receive_GA(request):
    if request.method == 'POST':
        form = NA_Goods_Receive_GA_Form(request.POST)
        statusForm = request.POST['statusForm']
        if form.is_valid():
            data = form.cleaned_data
            if statusForm == 'Add':
                data['createddate'] = datetime.now()
                data['createdby'] = request.user.username
                result = form.save(request=request)
            elif statusForm == 'Edit':
                data['modifieddate'] = datetime.now()
                data['modifiedby'] = request.user.username
                result = form.save(request=request)
            return commonFunct.response_default(result)
        else:
            raise forms.ValidationError(form.errors)

    elif request.method == 'GET':
        statusForm = request.GET['statusForm']
        if statusForm == 'Edit' or statusForm == 'Open':
            idapp = request.GET['idapp']
            data, result = NAGaReceive.objects.retrieveData(idapp)
            if data == Data.Success:
                # result = [i for i in result][0]
                # if isinstance(result['datereceived'], datetime):
                #     result['datereceived'] = result['datereceived'].strftime(
                #         '%d/%m/%Y')

                # if isinstance(result['year_made'], date):
                #     result['year_made'] = result['year_made'].strftime('%Y')
                form = NA_Goods_Receive_GA_Form(initial=result)
            elif data == Data.Lost:
                return commonFunct.response_default((data, result))
        else:
            form = NA_Goods_Receive_GA_Form()
        return render(
            request,
            'app/Transactions/NA_Entry_Goods_Receive_GA.html',
            {'form': form}
        )
Esempio n. 13
0
def EntryAcc(request):
    form = NA_Acc_Form(request.POST)
    if form.is_valid():
        idapp_detail_receive = form.cleaned_data.get('idapp_detail_receive')
        if request.POST['mode'] == 'Add':
            idapp = idapp_detail_receive.split(',')
            worker = NATaskWorker(func=NATask.task_generate_fix_asset,
                                  args=[idapp, request.user.username])
            worker.run()
            return commonFunct.response_default((Data.Success, ))
    else:
        raise forms.ValidationError(form.errors)
Esempio n. 14
0
def na_privilege_add_permission(request, email):
    if request.method == 'POST':
        form = NA_Permission_Form(request.POST)
        if form.is_valid():
            result = form.save(request)
            if isinstance(result, HttpResponse):
                return result
            return commonFunct.response_default(result)
        raise forms.ValidationError(form.errors)
    elif request.method == 'GET':
        form = NA_Permission_Form()
        return render(request, 'app/MasterData/NA_Entry_Permission.html', {'form': form})
Esempio n. 15
0
def Entry_Goods_Outwards_GA(request):
    if request.method == 'POST':
        data = request.POST.copy()
        data['equipment'] = data.getlist('equipment[]')
        data['add_equipment'] = data.getlist('add_equipment[]')
        form = NAGaOutwardsForm(data)
        statusForm = request.POST['statusForm']
        if form.is_valid():
            data = form.cleaned_data
            result = form.save(user=request.user.username)
            return commonFunct.response_default(result)
        else:
            raise forms.ValidationError(form.errors)

    elif request.method == 'GET':
        statusForm = request.GET['statusForm']
        if statusForm == 'Edit' or statusForm == 'Open':
            idapp = request.GET['idapp']
            data, result = NAGaOutwards.objects.retrieve_data(idapp)
            if data == Data.Success:
                result.update({
                    'daterequest':
                    result.get('daterequest').strftime('%d/%m/%Y'),
                    'datereleased':
                    result.get('datereleased').strftime('%d/%m/%Y')
                })

                if isinstance(result['year_made'], date):
                    result.update(
                        {'year_made': result.get('year_made').strftime('%Y')})
                form = NAGaOutwardsForm(initial=result)
            elif data == Data.Lost:
                return commonFunct.response_default((data, result))
        else:
            form = NAGaOutwardsForm()
        return render(request,
                      'app/Transactions/NA_Entry_Goods_Outwards_GA.html', {
                          'form': form,
                          'equipments': NAGoodsEquipment.get_equipment(request)
                      })
Esempio n. 16
0
def change_role(request, email):
    try:
        user = NAPrivilege.objects.get(email=email)
        result = Data.Success,
    except NAPrivilege.DoesNotExist:
        result = NAErrorHandler.handle_data_lost(
            model=NAPrivilege,
            email=email
        )
    else:
        role = request.POST['role']
        divisi = request.POST['divisi']
        user.role = role
        user.divisi = divisi
        user.save()
    return commonFunct.response_default(result)
Esempio n. 17
0
def EntrySuplier(request):
    if request.method == 'POST':
        form = NA_Suplier_form(request.POST)
        if form.is_valid():
            mode = request.POST['mode']
            data = getData(request, form)
            result = None
            if mode == 'Add':
                data['createddate'] = datetime.datetime.now()
                data['createdby'] = getCurrentUser(request)
                result = NASuplier.objects.SaveData(StatusForm.Input, **data)
            elif mode == 'Edit':
                data['modifieddate'] = datetime.datetime.now()
                data['modifiedby'] = getCurrentUser(request)
                result = NASuplier.objects.SaveData(StatusForm.Edit, **data)
            elif mode == 'Open':
                if request.POST['supliername']:
                    return HttpResponse(json.dumps({
                        'message':
                        'Cannot Edit Data with inspect element .. .'
                    }),
                                        status=403,
                                        content_type='application/json')
            return commonFunct.response_default(result)
    elif request.method == 'GET':
        getSupCode = request.GET['supliercode']
        mode = request.GET['mode']
        if mode == 'Edit' or mode == 'Open':
            result = NASuplier.objects.retriveData(getSupCode)  #return tuple
            if result[0] == Data.Success:
                form = NA_Suplier_form(initial=result[1][0])
                form.fields['supliercode'].widget.attrs[
                    'disabled'] = 'disabled'
                return render(request, 'app/MasterData/NA_Entry_Suplier.html',
                              {'form': form})
            elif result[0] == Data.Lost:
                return HttpResponse(json.dumps({
                    'message':
                    Message.get_lost_info(pk=getSupCode, table='suplier')
                }),
                                    status=404,
                                    content_type='application/json')
        else:
            form = NA_Suplier_form()
            return render(request, 'app/MasterData/NA_Entry_Suplier.html',
                          {'form': form})
Esempio n. 18
0
def EntryAcc(request):
    form = NA_Acc_Form(request.POST)
    if form.is_valid():
        idapp_detail_receive = form.cleaned_data.get('idapp_detail_receive')
        if request.POST['mode'] == 'Add':
            idapp = idapp_detail_receive.split(',')
            try:
                generate_acc_fa.delay(
                    idapp,
                    request.user.username
                )
            except Exception as e:
                raise e
            else:
                return commonFunct.response_default((Data.Success,))
    else:
        raise forms.ValidationError(form.errors)
Esempio n. 19
0
def delete_acc_fa(request):
    parent = request.POST.get('parent')
    children = request.POST.get('children')
    lookup = {}
    if parent:
        serial_number = request.POST.get('serial_number')
        lookup.update({
            'serialnumber': serial_number,
        })
    elif children:
        idapp = request.POST.get('idapp')
        lookup.clear()
        lookup.update({'idapp': idapp})
    else:
        raise ValueError('Please choose parent or children')
    result = NAAccFa.objects.delete_data(**lookup)
    return commonFunct.response_default(result)
Esempio n. 20
0
def Entry_GoodsReturn(request):
    getUser = str(request.user.username)
    if request.method == 'POST':
        form = NA_Goods_Return_Form(request.POST)
        if form.is_valid():
            data = getFormData(request, form)
            statusForm = request.POST['statusForm']
            result = None
            if statusForm == 'Add':
                data['createddate'] = datetime.now()
                data['createdby'] = getUser
                result = NAGoodsReturn.objects.SaveData(
                    StatusForm.Input, **data)
            elif statusForm == 'Edit':
                idapp = request.POST['idapp']
                data['idapp'] = idapp
                data['modifieddate'] = datetime.now()
                data['modifiedby'] = getUser
                result = NAGoodsReturn.objects.SaveData(
                    StatusForm.Edit, **data)
            return commonFunct.response_default(result)
    elif request.method == 'GET':
        statusForm = request.GET['statusForm']
        if statusForm == 'Edit' or statusForm == 'Open':
            idapp = request.GET['idapp']
            data = NAGoodsReturn.objects.retrieveData(idapp)  #tuple data
            iscompleted = data['iscompleted']
            if iscompleted == 1:
                data['iscompleted'] = True
            else:
                data['iscompleted'] = False
            isaccepted = data['isaccepted']
            if isaccepted == 1:
                data['isaccepted'] = True
            else:
                data['isaccepted'] = False
            data['datereturn'] = data['datereturn'].strftime('%d/%m/%Y')
            form = NA_Goods_Return_Form(initial=data)
            return render(request,
                          'app/Transactions/NA_Entry_Goods_Return.html',
                          {'form': form})
        else:
            form = NA_Goods_Return_Form()
        return render(request, 'app/Transactions/NA_Entry_Goods_Return.html',
                      {'form': form})
Esempio n. 21
0
def edit_profile(request: HttpRequest):
    if request.method == "GET":
        init_data = forms.model_to_dict(instance=request.user)
        form = EditProfileForm(initial=init_data)
        return render(
            request,
            'app/NA_User/NA_User_Profile.html',
            {
                'form': form
            }
        )
    else:
        data = request.POST.copy()
        data.update({
            'idapp': request.user.idapp
        })
        form = EditProfileForm(data, request.FILES or None)
        if form.is_valid():
            form.save()
            return commonFunct.response_default((Data.Success,))
Esempio n. 22
0
def Delete_user(request):
    idapp = request.POST['idapp']
    try:
        user = NAPrivilege.objects.get(idapp=idapp)
    except NAPrivilege.DoesNotExist:
        result = NAErrorHandler.handle_data_lost(
            pk=idapp, model=NAPrivilege
        )
    else:
        with transaction.atomic():
            log = LogActivity(
                models=NAPrivilege,
                activity=LogActivity.DELETED,
                user=request.user.username,
                data=user
            )
            log.record_activity()
            user.delete()
            result = Data.Success,
    return commonFunct.response_default(result)
def EntryMaintenance(request):
    getUser = str(request.user.username)
    if request.method == 'POST':
        form = NA_Maintenance_Form(request.POST)
        if form.is_valid():
            data = getFormData(request,form)
            statusForm = request.POST['statusForm']
            result = None
            if statusForm == 'Add':
                data['createddate'] = datetime.now()
                data['createdby'] = getUser
                result = NAMaintenance.objects.SaveData(StatusForm.Input,**data)
            elif statusForm == 'Edit':
                idapp = request.POST['idapp']
                data['idapp'] = idapp
                #data['issucced'] = 1 if data['issucced'] == 'true' else 0
                data['modifieddate'] = datetime.now()
                data['modifiedby'] = getUser
                result = NAMaintenance.objects.SaveData(StatusForm.Edit,**data)
            return commonFunct.response_default(result)
    elif request.method == 'GET':
        statusForm = request.GET['statusForm']
        if statusForm == 'Edit' or statusForm == 'Open':
            idapp = request.GET['idapp']
            data = NAMaintenance.objects.retriveData(idapp) #tuple data
            statusResp = 200
            if data[0] == Data.Lost:
                statusResp = 404
                return HttpResponse('Lost',status=statusResp)
            if statusResp == 200:
                data[1][0]['issucced'] = True if data[1][0]['issucced'] == 1 else False
                data[1][0]['requestdate'] = data[1][0]['requestdate'].strftime('%d/%m/%Y')
                data[1][0]['startdate'] = data[1][0]['startdate'].strftime('%d/%m/%Y')
                data[1][0]['enddate'] = data[1][0]['enddate'].strftime('%d/%m/%Y')
                form = NA_Maintenance_Form(initial=data[1][0])
                return render(request,'app/MasterData/NA_Entry_Maintenance.html',{'form':form})
        else:
            form = NA_Maintenance_Form()
        return render(request,'app/MasterData/NA_Entry_Maintenance.html',{'form':form})
Esempio n. 24
0
 def get(self, request):
     idapp = request.GET.get('idapp')
     try:
         ga_history = NAGaVnHistory.objects.get(idapp=idapp)
     except NAGaVnHistory.DoesNotExist:
         result = NAErrorHandler.handle_data_lost(model=NAGaVnHistory,
                                                  pk=idapp)
         return commonFunct.response_default(result)
     else:
         data = {
             'idapp': ga_history.idapp,
             'reg_no': ga_history.reg_no,
             'old_date_reg': ga_history.date_reg.strftime('%d/%m/%Y'),
             'old_expired_reg': ga_history.expired_reg.strftime('%d/%m/%Y'),
             'goods_name': ga_history.fk_app.fk_goods.goodsname,
             'brand': ga_history.fk_app.brand,
             'type_app': ga_history.fk_app.typeapp,
             'colour': ga_history.fk_app.colour,
             'invoice_no': ga_history.fk_app.invoice_no
         }
         form = NAExtendGaVnHistoryForm(initial=data)
     return render(request, 'app/Transactions/NA_Extend_GA_History.html',
                   {'form': form})
def NA_Employee_delete(request):
    if request.user.is_authenticated():
        get_idapp = request.POST.get('idapp')
        result = Employee.objects.delete_employee(
            idapp=get_idapp, NA_User=request.user.username)
        return commonFunct.response_default(result)
def Set_InActive(request):
    idapp = request.POST['idapp']
    inactive = request.POST['inactive']
    result = Employee.objects.setInActive(idapp,
                                          commonFunct.str2bool(inactive))
    return commonFunct.response_default(result)
Esempio n. 27
0
def get_GoodsData(request):
    idapp = request.GET['idapp']
    fromgoods = request.GET['fromgoods']
    result = NAGoodsReturn.objects.getGoods_data(idapp, fromgoods)
    return commonFunct.response_default(result)
Esempio n. 28
0
def Delete_data(request):
    idapp = request.POST['idapp']
    result = NAGaReceive.objects.DeleteData(idapp)
    return commonFunct.response_default(result)
Esempio n. 29
0
def get_GoodsData(request):
    if request.method == 'GET':
        idapp = request.GET['idapp']
        serialnumber = request.GET['serialnumber']
        result = NAMaintenance.objects.getGoods_data(idapp, serialnumber)
        return commonFunct.response_default(result)
Esempio n. 30
0
def Delete_M_data(request):
    if request.user.is_authenticated() and request.method == 'POST':
        idapp = request.POST['idapp']
        result = NAMaintenance.objects.DeleteData(idapp)
        return commonFunct.response_default(result)