def in73_add(request, fk, ook, template='ui/form_default.html'): prev_url = get_prev_url(request, '/purchasing-v1/in73/%s/list' % fk) perm = check_permission(request, 'purchasing.add_tmin73', prev_url) if perm: return perm fk_not_related = check_fk(request, ook, TMIN72, prev_url, True) if fk_not_related: return fk_not_related try: obj = TMIN73.objects.get(f_in72__pk=ook) except: obj = None judul = 'IN73 Add' form = FMIN73(request.POST or None, action='add', fk=fk, ook=ook, instance=obj) if form.is_valid(): obj = form.save(commit=False) obj.d_create = datetime.now() obj.c_nik = request.user.get_username() obj.save() messages.add_message(request, messages.SUCCESS, '%s berhasil ditambahkan' % obj) return redirect(request.path) ctx = { 'judul': judul, 'mnactive': default_mnactive, 'form': form, 'prev_url': prev_url, 'datepickerScript': True, 'submit': True, } return render(request, template, ctx)
def in71_in72_in73_prn_get(request, template='ui/form_default.html'): prev_url = get_prev_url(request, '/purchasing-v1/in71/list') perm = check_permission(request, 'purchasing.add_tmin73', prev_url, True) if perm: return perm import zipfile judul = 'IN71 IN72 IN73 PRN Download' form = RangeDateForm(request.POST or None) if form.is_valid(): zip_filename = "IN71_IN72_IN73" b = form.cleaned_data['begin_date'] e = form.cleaned_data['end_date'] io_zip = io.BytesIO() myzip = zipfile.ZipFile(io_zip, 'w') myzip.writestr('in71.txt', in71_export_prn(b, e)) myzip.writestr('in72.txt', in72_export_prn(b, e)) myzip.writestr('in73.txt', in73_export_prn(b, e)) myzip.close() resp = HttpResponse(io_zip.getvalue(), content_type="application/x-zip-compressed") resp['Content-Disposition'] = 'attachment; filename=%s_%s-%s.zip' % ( zip_filename, b.strftime("%y%m%d"), e.strftime("%y%m%d")) return resp ctx = { 'judul': judul, 'mnactive': default_mnactive, 'form': form, 'prev_url': prev_url, 'datepickerScript': True, 'submit': True, } return render(request, template, ctx)
def in72_change(request, fk, pk, template='ui/form_default.html'): prev_url = get_prev_url(request, '/purchasing-v1/in72/%s/list' % fk) perm = check_permission(request, 'purchasing.change_tmin72', prev_url) if perm: return perm try: obj = TMIN72.objects.get(pk=pk) except: return redirect(prev_url) judul = 'IN72 Change' form = FMIN72(request.POST or None, instance=obj, action='change', fk=fk) if form.is_valid(): obj = form.save(commit=False) obj.c_nik = request.user.get_username() obj.save() messages.add_message(request, messages.SUCCESS, '%s berhasil diubah' % obj) return redirect(request.path) ctx = { 'judul': judul, 'mnactive': default_mnactive, 'form': form, 'prev_url': prev_url, 'datepickerScript': True, 'submit': True, } return render(request, template, ctx)
def in72_add(request, fk, template='ui/form_default.html'): prev_url = get_prev_url(request, '/purchasing-v1/in72/%s/list' % fk) perm = check_permission(request, 'purchasing.add_tmin72', prev_url) if perm: return perm judul = 'IN72 Add' form = FMIN72(request.POST or None, action='add', fk=fk) if form.is_valid(): obj = form.save(commit=False) obj.d_create = datetime.now() obj.c_nik = request.user.get_username() obj.f_in71 = form.robj obj.save() messages.add_message( request, messages.SUCCESS, '%s berhasil ditambahkan, silahkan tambah item selanjutnya' % obj) return redirect(request.path) ctx = { 'judul': judul, 'mnactive': default_mnactive, 'form': form, 'prev_url': prev_url, 'datepickerScript': True, 'submit': True, } return render(request, template, ctx)
def in71_print(request, pk, template='purchasing/in71_print.html'): from weasyprint import HTML, CSS from io import StringIO, BytesIO from django.template.loader import get_template now = datetime.now() judul = 'IN71 Print' prev_url = get_prev_url(request, '/purchasing-v1/in71/list') perm = check_permission(request, 'purchasing.print_tmin71', prev_url, True) if perm: return perm # prev_url = request.META.get('HTTP_REFERER') or '/purchasing-v1/in71/list' try: obj = TMIN71.objects.prefetch_related( Prefetch( 'tmin72_set', queryset=TMIN72.objects.select_related('tmin73').all())).get( pk=pk) ivr = IVR7020H.objects.filter(master=obj.c_po)[0] except: return redirect(prev_url) for in72 in obj.tmin72_set.all(): in72.ivr = IVR7020H.objects.get(master=obj.c_po, itm=in72.i_itemno) ctx = { 'judul': judul, 'mnactive': default_mnactive, 'obj': obj, 'ivr': ivr, 'prev_url': prev_url, 'datepickerScript': True, } tpl = get_template(template) html = tpl.render(ctx) css = CSS( string=""" @page { size: A4; margin-top: 2cm; margin-bottom: 2cm; @bottom{ font-size:10pt; } @bottom-left{ content: "FORM NO. PRO3-2"; } @bottom-center{ content: "PRINTED: %s BY: %s"; } @bottom-right{ content: "Page " counter(page) " of " counter(pages); } } """ % (now.strftime("%d%b%y %H:%M").upper(), request.user.get_username())) # fonts = CSS(settings.STATICFILES_DIRS[0] + '/struk_gaji/fonts/font.css', font_config=font_config) pdf_file = HTML( string=html, base_url=request.build_absolute_uri()).write_pdf(stylesheets=[css]) response = HttpResponse(pdf_file, content_type='application/pdf') response['Content-Disposition'] = 'filename="IN71.pdf"' return response
def in72_delete(request, fk, pk): prev_url = get_prev_url(request, '/purchasing-v1/in72/%s/list' % fk) perm = check_permission(request, 'purchasing.delete_tmin72', prev_url) if perm: return perm try: obj = TMIN72.objects.get(pk=pk) obj.delete() messages.add_message(request, messages.SUCCESS, 'Successfully Deleted') except: messages.add_message(request, messages.ERROR, 'Opertaion Failed') return redirect(prev_url)
def in72_approve(request, fk, pk): prev_url = get_prev_url(request, '/purchasing-v1/in72/%s/list' % fk) perm = check_permission(request, 'purchasing.approve_tmin72', prev_url) if perm: return perm try: obj = TMIN72.objects.get(pk=pk) obj.c_nikappr = request.user.get_username() obj.d_appr = datetime.now() obj.save() messages.add_message(request, messages.SUCCESS, 'Successfully Approved') except: messages.add_message(request, messages.ERROR, 'Opertaion Failed') return redirect(prev_url)
def in71_add(request, template='ui/form_default.html'): prev_url = get_prev_url(request, '/purchasing-v1/in71/list') perm = check_permission(request, 'purchasing.add_tmin71', prev_url, True) if perm: return perm judul = 'IN71 Add' form = FMIN71(request.POST or None, action='add') if form.is_valid(): obj = form.save(commit=False) # return HttpResponse(obj.d_received) obj.d_create = datetime.now() obj.save() messages.add_message(request, messages.SUCCESS, 'kedatangan %s berhasil ditambahkan' % obj) return redirect(request.path) ctx = { 'judul': judul, 'mnactive': default_mnactive, 'form': form, 'prev_url': prev_url, 'datepickerScript': True, 'submit': True, } return render(request, template, ctx)