Pembuatan API Document Submission menggunakan
bahasa Python (Flask/Django) yang terkoneksi dengan interface Android
dan server Nextcloud:
API dibuat menggunakan Python (Flask/Django) untuk menerima JSON tersebut untuk kemudian melakukan proses-proses berikut ini:
A. 1st submission
B. submission draft to document
C. submission document to approval
D. submission draft to revise
E. submission draft to reject
F. submission document to revise
G. submission document to reject
Perhatikan! Jika terdapat baris coding pada bagian berikut ini hanyalah pseudocode atau hanya logika pemrograman dan belum tentu syntax yang cukup dicopy-paste, Anda harus memikirkan dan membuat syntax yang benar untuk menghasilkan program sesuai yang diinginkan.
A. 1st submission
· Sistem menerima JSON:
ü co id (mandatory)
ü app id (mandatory)
ü doc type (mandatory)
ü doc no (mandatory)
ü doc date (mandatory)
ü status (mandatory) = “draft”
ü created by (mandatory) as document writer
ü to reviewer (mandatory)
ü lead time reviewed (default blank)
ü notes (optional)
ü doc link (mandatory)
ü doc trx id (default blank jika not blank artinya ada revisi dari reviewer atau approver)
ü to approver 1..max sequence (array) à parameter (sequence; siapa & perannya apa: memeriksa, mengetahui, menyetujui; lead time approved)
Catatan: jika lead time diisi maka gunakan value ini yg di table diabaikan. Syarat lead time yang di-array tidak boleh < dari master
·
Validasi isi JSON, apakah sudah sesuai jika
tipe data dan/atau isi JSON tidak sesuai maka harus mengembalikan error message
“Format data not valid! – 1st submission” dan
transaksi tidak dapat dilanjutkan (return false)
· Jika lolos validasi di atas maka lakukan validasi status draft, jika JSON.status bukan “draft” maka harus mengembalikan error message “Document status not valid! – 1st submission” dan transaksi tidak dapat dilanjutkan (return false)
· Jika JSON.doc trx id kosong (artinya pertama kali kirim draft):
ü Lakukan validasi
exists in [table approval history]
where company_id = JSON.co id
and application_id = JSON.app id
and document_type = JSON.doc type
and document_number = JSON.docno
ü Jika record ditemukan maka harus mengembalikan error message “Document transaction id not valid! – 1st submission” dan transaksi tidak dapat dilanjutkan (return false)
ü Jika lolos validasi maka:
1. Insert into table draft:
2. Simpan parameter document_transaction_id dari [table draft]
3. Simpan parameter document_company_id dari [table draft]
4. Insert into table approver (ulangi sebanyak baris dan kolom array JSON.to_approver):
PK,FK |
document_transaction_id |
[parameter document_transaction_id] |
PK |
approver_id |
select user_id from [table user] where JSON.to_approver baris ke-n kolom ke-n approver id |
sequence |
JSON.to_approver baris ke-n kolom ke-n sequence |
|
approver_role |
JSON.to_approver baris ke-n kolom ke-n approval role |
|
lead_time_approved |
if JSON.to approver baris ke-n kolom ke-n lead_time_approved not empty then JSON.lead_time_approved else select lead_time_approved from [table document type by company] where document_company_id = [parameter document_company_id] |
|
create_date |
generate by system |
|
create_by |
“system” |
5. Insert into table approval history:
PK |
history_id |
generate by system |
UQ,FK |
document_transaction_id |
[parameter document_transaction_id] |
UQ |
history_number |
“00” |
document_status |
JSON.status (draft) |
|
document_link |
JSON.doc link |
|
user_type |
“document writer” |
|
|
company id |
JSON.co id |
|
application id |
JSON.app id |
|
document type |
JSON.doc type |
|
document number |
JSON.doc no |
|
document date |
JSON.doc date |
create_date |
generate by system |
|
create_by |
JSON.created by |
6. API Notifikasi ke reviewer “document needs your review” (reviewer akan membuka melalui aplikasi mobile page My Documents atau klik notifikasi untuk membuka page Document Review)
· Jika JSON.doc trx id tidak kosong (artinya ada revisi dari reviewer atau approver):
ü Lakukan validasi
exists in [table approval history]
where company_id = JSON.co id
and application_id = JSON.app id
and document_type = JSON.doc type
and document_number = JSON.docno
and document_transaction_id = JSON.doc trx id
ü Jika record tidak ditemukan maka harus mengembalikan error message “Document transaction id not valid! – 1st submission” dan transaksi tidak dapat dilanjutkan (return false)
ü Jika lolos validasi maka:
1. Update table draft where document_transaction_id = JSON.doc trx id
|
last_status |
JSON.status (draft) |
|
update_date |
generate by system |
|
update_by |
JSON.created by |
2. Simpan parameter document_transaction_id dari [table draft]
3. Insert into table approval history:
4. API Notifikasi ke reviewer “document needs your review” (reviewer akan membuka melalui aplikasi mobile page My Documents atau klik notifikasi untuk membuka page Document Review)
B. submission draft to document
· Sistem menerima JSON:
ü co id (mandatory)
ü app id (mandatory)
ü doc type (mandatory)
ü doc no (mandatory)
ü doc date (mandatory)
ü status (mandatory) = “document”
ü created by (mandatory) user login as reviewer
ü to reviewer (mandatory)
ü lead time reviewed (default blank)
ü notes (optional)
ü doc link (mandatory)
ü doc trx id (default blank jika not blank artinya ada revisi dari reviewer atau approver)
ü to approver 1..max sequence (array) --> parameter (sequence; siapa & perannya apa: memeriksa, mengetahui, menyetujui; lead time approved)
Catatan: jika lead time diisi maka gunakan value ini yg di table diabaikan. Syarat lead time yang di-array tidak boleh < dari master
·
Validasi isi JSON, apakah sudah sesuai jika
tipe data dan/atau isi JSON tidak sesuai maka harus mengembalikan error message
“Format data not valid! - submission draft to document” dan
transaksi tidak dapat dilanjutkan (return false)
· Jika lolos validasi di atas maka lakukan validasi status, jika JSON.status bukan “document” maka harus mengembalikan error message “Document status not valid! - submission draft to document” dan transaksi tidak dapat dilanjutkan (return false)
· Jika JSON.doc trx id tidak kosong (artinya approved oleh reviewer):
ü Lakukan validasi
exists in [table approval history]
where company_id = JSON.co id
and application_id = JSON.app id
and document_type = JSON.doc type
and document_number = JSON.doc no
and document_transaction_id = JSON.doc trx id
ü Jika record tidak ditemukan maka harus mengembalikan error message “Document transaction id not valid! - submission draft to document” dan transaksi tidak dapat dilanjutkan (return false)
ü Jika lolos validasi maka:
1. Insert table document
PK |
document_transaction_id |
JSON.doc trx id |
UQ,FK |
document_company_id |
select document_company_id from [table document type by company] where company_id = JSON.co id and document_id = (select document_id from [table document type] where application_id = JSON.app id and document_type = JSON.doc type) |
UQ |
document_number |
JSON.doc no |
|
document_date |
JSON.doc date |
|
notes |
JSON.notes |
|
to_reviewer |
JSON.to reviewer |
|
current_sequence |
1 |
|
max_sequence |
max baris array JSON.to approver |
|
last_status |
JSON.status (document) |
|
create_date |
generate by system |
|
create_by |
JSON.created by |
|
update_date |
generate by system |
|
update_by |
JSON.created by |
2. Simpan parameter document_transaction_id dari [table document]
3. Insert into table approval history:
PK |
history_id |
generate by system |
UQ,FK |
document_transaction_id |
[parameter document_transaction_id] |
UQ |
history_number |
max+1 |
document_status |
JSON.status (document) |
|
document_link |
JSON.doc link |
|
user_type |
“reviewer” |
|
|
company id |
JSON.co id |
|
application id |
JSON.app id |
|
document type |
JSON.doc type |
|
document number |
JSON.doc no |
|
document date |
JSON.doc date |
create_date |
generate by system |
|
create_by |
JSON.created by |
4. API Notifikasi ke writer “confirm draft to document”
5. API Notifikasi ke approver 1st “document needs your approval” (approver 1st akan membuka melalui aplikasi mobile page My Documents atau klik notifikasi untuk membuka page Document Review)
· Jika JSON.doc trx id kosong (artinya pertama kali kirim dokumen tanpa melalui Draft Review):
ü Lakukan validasi
exists in [table approval history]
where company_id = JSON.co id
and application_id = JSON.app id
and document_type = JSON.doc type
and document_number = JSON.doc no
ü Jika record ditemukan maka harus mengembalikan error message “Document transaction id not valid! - submission draft to document” dan transaksi tidak dapat dilanjutkan (return false)
ü Jika lolos validasi maka:
1. Insert into table document:
PK |
document_transaction_id |
generate by system (incremental) |
UQ,FK |
document_company_id |
select document_company_id from [table document type by company] where company_id = JSON.co id and document_id = (select document_id from [table document type] where application_id = JSON.app id and document_type = JSON.doc type) |
UQ |
document_number |
JSON.doc no |
|
document_date |
JSON.doc date |
notes |
JSON.notes |
|
to_reviewer |
JSON.to reviewer |
|
lead_time_reviewed |
if lead_time_reviewed not empty then JSON.lead_time_reviewed else select lead_time_reviewed from [table document type by company] where document_company_id = [parameter document_company_id] |
|
|
current_sequence |
1 |
max_sequence |
max baris array JSON.to approver |
|
|
last_status |
JSON.status (document) |
create_date |
generate by system |
|
create_by |
JSON.created by |
|
|
update_date |
generate by system |
|
update_by |
JSON.created by |
2. Simpan parameter document_transaction_id dari [table document]
3. Simpan parameter document_company_id dari [table document]
4. Insert into table approver (ulangi sebanyak baris dan kolom array JSON.to_approver):
PK,FK |
document_transaction_id |
[parameter document_transaction_id] |
PK |
approver_id |
select user_id from [table user] where JSON.to_approver baris ke-n kolom ke-n approver id |
sequence |
JSON.to_approver baris ke-n kolom ke-n sequence |
|
approver_role |
JSON.to_approver baris ke-n kolom ke-n approval role |
|
lead_time_approved |
if JSON.to approver baris ke-n kolom ke-n lead_time_approved not empty then JSON.lead_time_approved else select lead_time_approved from [table document type by company] where document_company_id = [parameter document_company_id] |
|
create_date |
generate by system |
|