[Fixes] UX fixes

This commit is contained in:
Saurabh 2016-05-16 12:27:01 +05:30
parent bb95d36218
commit 9ca9f2d551
3 changed files with 273 additions and 120 deletions

View File

@ -6,14 +6,15 @@ frappe.provide("erpnext.cheque_print");
frappe.ui.form.on('Cheque Print Template', {
refresh: function(frm) {
if(!frm.doc.__islocal) {
frm.add_custom_button(__("Cheque Print Preview"), function() {
frm.add_custom_button(frm.doc.has_print_format?__("Update Print Format"):__("Create Print Format"),
function() {
erpnext.cheque_print.view_cheque_print(frm);
});
}).addClass("btn-primary");
$(frm.fields_dict.cheque_print_preview.wrapper).empty()
$("<div style='position: relative; overflow-x: scroll;'>\
<div style='width:"+ frm.doc.cheque_width + "cm; \
<div id='cheque_preview' style='width:"+ frm.doc.cheque_width + "cm; \
height: "+ frm.doc.cheque_height +"cm;\
background-image: url("+frm.doc.scanned_cheque+");\
background-repeat: no-repeat;\
@ -48,43 +49,19 @@ frappe.ui.form.on('Cheque Print Template', {
erpnext.cheque_print.view_cheque_print = function(frm) {
var dialog = new frappe.ui.Dialog({
title: 'Cheque Print Preview'
});
dialog.show();
var body = dialog.body;
console.log(frm.doc.cheque_width)
dialog.$wrapper.find('.modal-dialog').css("width", "790px");
$(body).html("<div style='width:"+ frm.doc.cheque_width + "cm; \
height: "+ frm.doc.cheque_height +"cm;\
background-image: url("+frm.doc.cheque_scan+");\
background-repeat: no-repeat;\
background-size: cover;\
border: 1px solid black;'>\
<span style='top: "+frm.doc.data_7+"cm;\
left: "+ flt(frm.doc.data_8) +"cm;\
position: absolute;'> "+ frappe.datetime.obj_to_user() +" </span>\
<span style='top: "+frm.doc.acc_no_ps+"cm;\
left: "+ frm.doc.str_loc_acc_no +"cm;\
position: absolute;'> 1234567890 </span>\
<span style='top:"+ frm.doc.data_9 +"cm;\
left: "+ flt(frm.doc.data_10) +"cm;\
position: absolute;'> Saurabh Palande </span>\
<span style='top:"+ frm.doc.data_11 +"cm;\
left: "+ flt(frm.doc.data_13) +"cm;\
position: absolute;\
display: block;\
width: "+frm.doc.ln_width+"cm;\
line-height: "+frm.doc.ln_spacing+"cm;\
word-wrap: break-word;'>One Crore One Lakh Forty One Thousand Six hundred And Sixty Six Only </span>\
<span style='top:"+ frm.doc.data_15 +"cm;\
left: "+ flt(frm.doc.data_16) +"cm;\
position: absolute;'> 1,01,41666.00 </span>\
<span style='top:"+ frm.doc.data_17 +"cm;\
left: "+ flt(frm.doc.data_18) +"cm;\
position: absolute;'> Frappe Technologies Pvt Ltd </span>\
</div>")
}
frappe.call({
method: "erpnext.accounts.doctype.cheque_print_template.cheque_print_template.create_or_update_cheque_print_format",
args:{
"template_name": frm.doc.name
},
callback: function(r) {
if (!r.exe && !frm.doc.has_print_format) {
var doc = frappe.model.sync(r.message);
frappe.set_route("Form", r.message.doctype, r.message.name);
}
else {
frappe.msgprint(__("Print settings updated in respective print format"))
}
}
})
}

View File

@ -25,7 +25,7 @@
"label": "",
"length": 0,
"no_copy": 0,
"options": "<div>\n<h1> All dimensions in CM only </h1>\n</div>",
"options": "<div>\n<h3> All dimensions in centimeter only </h3>\n</div>",
"permlevel": 0,
"precision": "",
"print_hide": 0,
@ -41,14 +41,39 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "cheque_details",
"fieldname": "has_print_format",
"fieldtype": "Check",
"hidden": 1,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Has Print Format",
"length": 0,
"no_copy": 1,
"permlevel": 0,
"precision": "",
"print_hide": 1,
"print_hide_if_no_value": 0,
"read_only": 1,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "primary_settings",
"fieldtype": "Section Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Cheque Details",
"label": "Primary Settings",
"length": 0,
"no_copy": 0,
"permlevel": 0,
@ -75,7 +100,33 @@
"in_list_view": 0,
"label": "Bank Name",
"length": 0,
"no_copy": 1,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "cheque_size",
"fieldtype": "Select",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Cheque Size",
"length": 0,
"no_copy": 0,
"options": "\nRegular\nA4",
"permlevel": 0,
"precision": "",
"print_hide": 0,
@ -91,42 +142,19 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "scanned_cheque",
"fieldtype": "Attach",
"depends_on": "eval:doc.cheque_size==\"A4\"",
"fieldname": "starting_position_from_top_edge",
"fieldtype": "Float",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Scanned Cheque",
"label": "Starting position from top edge",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "column_break_5",
"fieldtype": "Column Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"precision": "2",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
@ -190,16 +218,91 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "date_settings",
"fieldname": "column_break_5",
"fieldtype": "Column Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "scanned_cheque",
"fieldtype": "Attach",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Scanned Cheque",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "date_and_payer_settings",
"fieldtype": "Section Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "date_settings",
"fieldtype": "HTML",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Date Settings",
"length": 0,
"no_copy": 0,
"options": "<label class=\"control-label\" style=\"margin-bottom: 0px;\">Date Settings</label>",
"permlevel": 0,
"precision": "",
"print_hide": 0,
@ -266,7 +369,7 @@
"bold": 0,
"collapsible": 0,
"fieldname": "payer_settings",
"fieldtype": "Section Break",
"fieldtype": "Column Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
@ -340,14 +443,14 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "amount_in_words",
"fieldname": "amount_in_words_and_figure_settings",
"fieldtype": "Section Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Amount In Words",
"label": "",
"length": 0,
"no_copy": 0,
"permlevel": 0,
@ -361,6 +464,31 @@
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "html_19",
"fieldtype": "HTML",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"length": 0,
"no_copy": 0,
"options": "<label class=\"control-label\" style=\"margin-bottom: 0px;\">Amount In Words</label>",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
@ -466,7 +594,7 @@
"bold": 0,
"collapsible": 0,
"fieldname": "amount_in_figure",
"fieldtype": "Section Break",
"fieldtype": "Column Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
@ -540,14 +668,14 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "account_number_dimensions",
"fieldname": "account_number_and_signatory_settings",
"fieldtype": "Section Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Account Number Dimensions",
"label": "",
"length": 0,
"no_copy": 0,
"permlevel": 0,
@ -561,6 +689,31 @@
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "account_no_settings",
"fieldtype": "HTML",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"length": 0,
"no_copy": 0,
"options": "<label class=\"control-label\" style=\"margin-bottom: 0px;\">Account Number Settings</label>",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
@ -616,7 +769,7 @@
"bold": 0,
"collapsible": 0,
"fieldname": "signatory_position",
"fieldtype": "Section Break",
"fieldtype": "Column Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
@ -745,7 +898,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 1,
"modified": "2016-05-11 19:50:25.554911",
"modified": "2016-05-16 12:32:26.649060",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Cheque Print Template",

View File

@ -5,54 +5,77 @@
from __future__ import unicode_literals
import frappe
from frappe.model.document import Document
from frappe.utils import flt, cstr
class ChequePrintTemplate(Document):
def on_update(self):
if not frappe.db.exists("Print Format", self.name):
cheque_print = frappe.new_doc("Print Format")
cheque_print.update({
"doc_type": "Journal Entry",
"standard": "Yes",
"custom_format": 1,
"print_format_type": "Server",
"name": self.name
})
else:
cheque_print = frappe.get_doc("Print Format", self.name)
cheque_print.html = """
<div style="position: relative">
<div style="width:%scm;height:%scm;">
<span style="top:%s cm; left:%scm;position: absolute;">
pass
@frappe.whitelist()
def create_or_update_cheque_print_format(template_name):
if not frappe.db.exists("Print Format", template_name):
cheque_print = frappe.new_doc("Print Format")
cheque_print.update({
"doc_type": "Journal Entry",
"standard": "No",
"custom_format": 1,
"print_format_type": "Server",
"name": template_name
})
else:
cheque_print = frappe.get_doc("Print Format", template_name)
doc = frappe.get_doc("Cheque Print Template", template_name)
cheque_print.html = """
<div style="position: relative; top:%(starting_position_from_top_edge)scm">
<div style="width:%(cheque_width)scm;height:%(cheque_height)scm;">
<span style="top:%(date_dist_from_top_edge)s cm; left:%(date_dist_from_left_edge)scm;
position: absolute;">
{{doc.cheque_date or '' }}
</span>
<span style="top:%scm;left:%scm;position: absolute;">
1234567890
<span style="top:%(acc_no_dist_from_top_edge)scm;left:%(acc_no_dist_from_left_edge)scm;
position: absolute;">
{{ doc.account_no or "Account No" }}
</span>
<span style="top:%scm;left: %scm; position: absolute;">
<span style="top:%(payer_name_from_top_edge)scm;left: %(payer_name_from_left_edge)scm;
position: absolute;">
{{doc.pay_to_recd_from}}
</span>
<span style="top:%scm; left:%scm; position: absolute; display: block;
width: %scm; line-height:%scm; word-wrap: break-word;">
<span style="top:%(amt_in_words_from_top_edge)scm; left:%(amt_in_words_from_left_edge)scm;
position: absolute; display: block; width: %(amt_in_word_width)scm;
line-height:%(amt_in_words_line_spacing)scm; word-wrap: break-word;">
{{doc.total_amount_in_words}}
</span>
<span style="top:%scm;left: %scm;position: absolute;">
<span style="top:%(amt_in_figures_from_top_edge)scm;left: %(amt_in_figures_from_left_edge)scm;
position: absolute;">
{{doc.get_formatted("total_amount")}}
</span>
<span style="top:%scm;left: %scm; position: absolute;">
<span style="top:%(signatory_from_top_edge)scm;left: %(signatory_from_left_edge)scm;
position: absolute;">
{{doc.company}}
</span>
</div>"""%(self.cheque_width, self.cheque_height,
self.date_dist_from_top_edge, self.date_dist_from_left_edge,
self.acc_no_dist_from_top_edge, self.acc_no_dist_from_left_edge,
self.payer_name_from_top_edge, self.payer_name_from_left_edge,
self.amt_in_words_from_top_edge, self.amt_in_words_from_left_edge,
self.amt_in_word_width, self.amt_in_words_line_spacing,
self.amt_in_figures_from_top_edge, self.amt_in_figures_from_left_edge,
self.signatory_from_top_edge, self.signatory_from_left_edge)
cheque_print.save(ignore_permissions=True)
</div>
</div>"""%{
"starting_position_from_top_edge": doc.starting_position_from_top_edge \
if doc.cheque_size == "A4" else 0.0,
"cheque_width": doc.cheque_width, "cheque_height": doc.cheque_height,
"date_dist_from_top_edge": doc.date_dist_from_top_edge,
"date_dist_from_left_edge": doc.date_dist_from_left_edge,
"acc_no_dist_from_top_edge": doc.acc_no_dist_from_top_edge,
"acc_no_dist_from_left_edge": doc.acc_no_dist_from_left_edge,
"payer_name_from_top_edge": doc.payer_name_from_top_edge,
"payer_name_from_left_edge": doc.payer_name_from_left_edge,
"amt_in_words_from_top_edge": doc.amt_in_words_from_top_edge,
"amt_in_words_from_left_edge": doc.amt_in_words_from_left_edge,
"amt_in_word_width": doc.amt_in_word_width,
"amt_in_words_line_spacing": doc.amt_in_words_line_spacing,
"amt_in_figures_from_top_edge": doc.amt_in_figures_from_top_edge,
"amt_in_figures_from_left_edge": doc.amt_in_figures_from_left_edge,
"signatory_from_top_edge": doc.signatory_from_top_edge,
"signatory_from_left_edge": doc.signatory_from_left_edge
}
cheque_print.save(ignore_permissions=True)
frappe.db.set_value("Cheque Print Template", template_name, "has_print_format", 1)
return cheque_print