Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File Preview #140

Merged
merged 16 commits into from
Sep 7, 2023
Merged
7 changes: 7 additions & 0 deletions check_run/check_run/doctype/check_run/check_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from frappe.utils.file_manager import save_file, remove_all
from frappe.utils.password import get_decrypted_password
from frappe.contacts.doctype.address.address import get_default_address
from frappe.desk.form.load import get_attachments

from erpnext.accounts.utils import get_balance_on

Expand Down Expand Up @@ -605,6 +606,12 @@ def get_entries(doc):
as_dict=True,
)
for transaction in transactions:
doc_name = transaction.ref_number if transaction.ref_number else transaction.name
transaction.attachments = [
attachment for attachment in get_attachments(transaction.doctype, doc_name)
if attachment.file_url.endswith('.pdf')
] or [{'file_name': doc_name, 'file_url': f'/app/Form/{transaction.doctype}/{doc_name}'}]

if settings and settings.pre_check_overdue_items:
if transaction.due_date < doc.posting_date:
transaction.pay = 1
Expand Down
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) 2023, AgriTheory and contributors
// For license information, please see license.txt
/* eslint-disable */

frappe.query_reports['Payables Attachments'] = {
filters: [],
}

frappe.ui.addFilePreviewWrapper()

function pdf_preview(file_url) {
frappe.ui.pdfPreview(cur_frm, file_url)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"add_total_row": 0,
"columns": [],
"creation": "2023-08-11 10:09:28.938669",
"disable_prepared_report": 0,
"disabled": 0,
"docstatus": 0,
"doctype": "Report",
"filters": [],
"idx": 0,
"is_standard": "Yes",
"modified": "2023-08-11 10:09:28.938669",
"modified_by": "Administrator",
"module": "Check Run",
"name": "Payables Attachments",
"owner": "Administrator",
"prepared_report": 0,
"ref_doctype": "Purchase Invoice",
"report_name": "Payables Attachments",
"report_type": "Script Report",
"roles": [
{
"role": "Accounts User"
},
{
"role": "Purchase User"
},
{
"role": "Accounts Manager"
},
{
"role": "Auditor"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# Copyright (c) 2022, AgriTheory and contributors
# For license information, please see license.txt

import frappe
from frappe.desk.form.load import get_attachments


def execute(filters=None):
return get_columns(filters), get_data(filters)


def get_data(filters):
data = frappe.db.sql("""
SELECT
pi.name AS purchase_invoice_name,
pi.title,
pi.supplier,
pi.company,
pi.posting_date,
pi.grand_total,
pi.status,
pi.currency,
pi.supplier_name,
pi.grand_total,
pi.outstanding_amount,
pi.due_date,
pi.is_return,
pi.release_date,
pi.represents_company,
pi.is_internal_supplier
FROM `tabPurchase Invoice` AS pi
ORDER BY pi.modified DESC
""",
as_dict=True,
)

for row in data:
row['attachments'] = " ".join([
f"""<a data-pdf-preview="{attachment.file_url}" onclick="pdf_preview('{attachment.file_url}')">{attachment.file_name}</a>"""
for attachment in get_attachments('Purchase Invoice', row['purchase_invoice_name']) if attachment.file_url.endswith('.pdf')
])
return data

def get_columns(filters):
return [

{
"label": frappe._("Name"),
"fieldname": "purchase_invoice_name",
"fieldtype": "Link",
"options": "Purchase Invoice",
"width": "150px",
},
{
"label": frappe._("Title"),
"fieldname": "title",
"fieldtype": "Data",
"width": "200px",
},
{
"label": frappe._("Supplier"),
"fieldname": "supplier",
"fieldtype": "Link",
"options": "Supplier",
"width": "200px",
},
{
"label": frappe._("Supplier Name"),
"fieldname": "supplier_name",
"fieldtype": "Data",
"width": "200px",
},
{
"label": frappe._("Company"),
"fieldname": "company",
"fieldtype": "Link",
"options": "Company",
"width": "200px",
},
{
"label": frappe._("Date"),
"fieldname": "posting_date",
"fieldtype": "Date",
"width": "200px",
},
{
"label": frappe._("Grand Total"),
"fieldname": "grand_total",
"fieldtype": "Currency",
"width": "200px",
},
{
"label": frappe._("Status"),
"fieldname": "status",
"fieldtype": "Data",
"width": "200px",
},
{
"label": frappe._("Currency"),
"fieldname": "currency",
"fieldtype": "Link",
"options": "Currency",
"width": "200px",
},
{
"label": frappe._("Grand Total (Company Currency)"),
"fieldname": "grand_total",
"fieldtype": "Currency",
"width": "200px",
},
{
"label": frappe._("Outstanding Amount"),
"fieldname": "outstanding_amount",
"fieldtype": "Currency",
"width": "200px",
},
{
"label": frappe._("Due Date"),
"fieldname": "due_date",
"fieldtype": "Date",
"width": "200px",
},
{
"label": frappe._("Is Return (Debit Note)"),
"fieldname": "is_return",
"fieldtype": "Check",
"width": "200px",
},
{
"label": frappe._("Release Date"),
"fieldname": "release_date",
"fieldtype": "Date",
"width": "200px",
},
{
"label": frappe._("Represents Company"),
"fieldname": "represents_company",
"fieldtype": "Link",
"options": "Company",
"width": "200px",
},
{
"label": frappe._("Is Internal Supplier"),
"fieldname": "is_internal_supplier",
"fieldtype": "Check",
"width": "200px",
},
{
"label": frappe._("Attachments"),
"fieldname": "attachments",
"fieldtype": "Data",
"width": "400px",
},
]

2 changes: 1 addition & 1 deletion check_run/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# ------------------

# include js, css files in header of desk.html
# app_include_css = "/assets/check_run/css/check_run.css"
app_include_css = "/assets/check_run/css/file_preview.css"
app_include_js = ["/assets/js/check_run.min.js"]

# include js, css files in header of web template
Expand Down
6 changes: 5 additions & 1 deletion check_run/public/build.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"js/check_run.min.js": ["public/js/check_run/check_run.js", "public/js/check_run/check_run_quick_entry.js"]
"js/check_run.min.js": [
"public/js/check_run/check_run.js",
"public/js/check_run/check_run_quick_entry.js",
"public/js/custom/file_preview.js"
]
}
61 changes: 61 additions & 0 deletions check_run/public/css/file_preview.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
.fa-file-pdf-o {
font-size: 120%;
padding-left: 0.5ch;
color: var(--brand-secondary);
}
#close-pdf-button {
position: absolute;
top: 10px;
right: 10px;
}
#pdf-preview-wrapper {
position: fixed;
width: calc(1290px / 2);
height: calc(100vh - 135px);
top: 135px;
right: calc((100vw - 1290px) / 2);
display: none;
}
#pdf-preview-wrapper.pdf-preview-wrapper-fw {
width: calc(90vw / 2);
height: calc(100vh - 135px);
right: calc(10vw / 2);
}
#pdf-preview-wrapper.pdf-preview-wrapper-fw #pdf-preview {
width: calc(90vw / 2);
}
.page-body.show-pdf-preview #pdf-preview-wrapper {
display: block;
}
#pdf-preview {
position: absolute;
top: 50px;
left: 0;
right: 0;
bottom: 0;
width: calc(1290px / 2);
height: calc(100vh - 135px - 20px);
}
.page-body.show-pdf-preview .page-wrapper .page-content {
width: calc(50% - 10px);
}

.portal-widget {
position: absolute;
top: 5px;
right:5px;
bottom:5px;
left:5px;
border-radius: 5px;
box-shadow: 0px 1px 2px rgba(25, 39, 52, 0.05), 0px 0px 4px rgba(25, 39, 52, 0.1);
}
a.portal-widget-col {
position: relative;
padding: 20px;
text-decoration: none;
}

.widget-row {
margin-top: 10px;
margin-bottom: 20px;
}
23 changes: 20 additions & 3 deletions check_run/public/js/check_run/CheckRun.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
>&#11021;</span
>
</th>
<th v-if="state.status == 'Draft'" style="min-width: 200px; text-align: left">
<th v-if="state.status == 'Draft'" class="col col-sm-1" style="text-align: left">
<input
type="checkbox"
autocomplete="off"
Expand All @@ -50,7 +50,7 @@
id="select-all"
v-model="selectAll" /><span>Select All</span>
</th>
<th v-else class="col col-sm-2">Check Number | Reference</th>
<th v-else class="col col-sm-1">Check Number | Reference</th>
</tr>
</thead>
<tbody>
Expand All @@ -63,10 +63,22 @@
tabindex="1"
@click="state.selectedRow = i">
<td style="text-align: left">{{ item.party_name || item.party }}</td>
<td>
<td style="text-align: left;white-space: nowrap;">
<a :href="transactionUrl(item)" target="_blank">
{{ item.ref_number || item.name }}
</a>
<div v-if="item.attachments.length > 1" style="float: right;" class="dropdown show">
<a class="btn btn-default btn-xs dropdown-toggle" href="#" role="button" :id="item.name" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fa fa-search"></i>
</a>
<div class="dropdown-menu" :aria-labelledby="item.name">
<a v-for="attachment in item.attachments" class="dropdown-item" href="javascript:;" @click="showPreview(attachment.file_url)" data-pdf-preview="item">{{ attachment.file_name }}</a>
</div>
</div>

<button v-if="item.attachments.length == 1" style="float: right;" type="button" class="btn btn-secondary btn-xs" @click="showPreview(item.attachments)" data-pdf-preview="item">
<i @click="showPreview(item.attachments)" data-pdf-preview="item" class="fa fa-search"></i>
</button>
</td>
<td>{{ item.posting_date }}</td>
<td class="mop-onclick" :data-mop-index="i">
Expand Down Expand Up @@ -193,6 +205,11 @@ export default {
}
this.$refs.dropdowns[this.state.selectedRow].openWithSearch()
},
showPreview(attachment) {
var file_url = typeof attachment == 'string' ? attachment : attachment[0].file_url
frappe.ui.addFilePreviewWrapper()
frappe.ui.pdfPreview(cur_frm, file_url)
}
},
beforeMount() {
this.moment = moment
Expand Down
Loading