From e9c2f6d6f1051d7c3b74a0d82fe7a12dbcac80a9 Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Mon, 5 Feb 2024 11:05:45 +0530 Subject: [PATCH 001/192] fix: message for subscription when no current inv --- erpnext/accounts/doctype/subscription/subscription.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/subscription/subscription.py b/erpnext/accounts/doctype/subscription/subscription.py index 9dab4e91fbae..836043d1cd40 100644 --- a/erpnext/accounts/doctype/subscription/subscription.py +++ b/erpnext/accounts/doctype/subscription/subscription.py @@ -594,7 +594,7 @@ def process_for_past_due_date(self): """ current_invoice = self.get_current_invoice() if not current_invoice: - frappe.throw(_("Current invoice {0} is missing").format(current_invoice.invoice)) + frappe.throw(_("Subscription {0}: Current invoice is missing.").format(frappe.bold(self.name))) else: if not self.has_outstanding_invoice(): self.status = "Active" From 02cd8c4b9898f053016b902d59fd47d08131958b Mon Sep 17 00:00:00 2001 From: Govind S Menokee Date: Wed, 21 Feb 2024 19:46:44 +0530 Subject: [PATCH 002/192] fix: UAE tax computation fix --- erpnext/regional/united_arab_emirates/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/regional/united_arab_emirates/utils.py b/erpnext/regional/united_arab_emirates/utils.py index efeaeed324c6..634a152147d5 100644 --- a/erpnext/regional/united_arab_emirates/utils.py +++ b/erpnext/regional/united_arab_emirates/utils.py @@ -25,7 +25,7 @@ def update_itemised_tax_data(doc): # dont even bother checking in item tax template as it contains both input and output accounts - double the tax rate item_code = row.item_code or row.item_name if itemised_tax.get(item_code): - for tax in itemised_tax.get(row.item_code).values(): + for tax in itemised_tax.get(item_code).values(): _tax_rate = flt(tax.get("tax_rate", 0), row.precision("tax_rate")) tax_amount += flt((row.net_amount * _tax_rate) / 100, row.precision("tax_amount")) tax_rate += _tax_rate From 2450a73c6f41c7ec880acf8f5825f7306a2940ba Mon Sep 17 00:00:00 2001 From: Samuel Danieli <23150094+scdanieli@users.noreply.github.com> Date: Thu, 25 Aug 2022 07:53:38 +0200 Subject: [PATCH 003/192] chore: german translations (#31463) (cherry picked from commit 915102a40040e38239024acb2647f54fe350809b) # Conflicts: # erpnext/translations/de.csv --- erpnext/translations/de.csv | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/erpnext/translations/de.csv b/erpnext/translations/de.csv index 3a8b7fe1a4ae..e0589c833d96 100644 --- a/erpnext/translations/de.csv +++ b/erpnext/translations/de.csv @@ -189,6 +189,10 @@ All other ITC,Alle anderen ITC, All the mandatory Task for employee creation hasn't been done yet.,Alle obligatorischen Aufgaben zur Mitarbeitererstellung wurden noch nicht erledigt., Allocate Payment Amount,Zahlungsbetrag zuweisen, Allocated Amount,Zugewiesene Menge, +<<<<<<< HEAD +======= +Allocated Leaves,Zugewiesene Urlaubstage, +>>>>>>> 915102a400 (chore: german translations (#31463)) Allocating leaves...,Blätter zuordnen..., Already record exists for the item {0},Es existiert bereits ein Datensatz für den Artikel {0}, "Already set default in pos profile {0} for user {1}, kindly disabled default","Im Standardprofil {0} für den Benutzer {1} ist der Standard bereits festgelegt, standardmäßig deaktiviert", @@ -7873,8 +7877,8 @@ Material Request Warehouse,Materialanforderungslager, Select warehouse for material requests,Wählen Sie Lager für Materialanfragen, Transfer Materials For Warehouse {0},Material für Lager übertragen {0}, Production Plan Material Request Warehouse,Produktionsplan Materialanforderungslager, -Sets 'Source Warehouse' in each row of the items table.,Legt 'Source Warehouse' in jeder Zeile der Artikeltabelle fest., -Sets 'Target Warehouse' in each row of the items table.,"Füllt das Feld ""Ziel Lager"" in allen Positionen der folgenden Tabelle.", +Sets 'Source Warehouse' in each row of the items table.,Legt in jeder Zeile der Artikeltabelle das „Ausgangslager“ fest., +Sets 'Target Warehouse' in each row of the items table.,Legt in jeder Zeile der Artikeltabelle das „Eingangslager“ fest., Show Cancelled Entries,Abgebrochene Einträge anzeigen, Backdated Stock Entry,Backdated Stock Entry, Row #{}: Currency of {} - {} doesn't matches company currency.,Zeile # {}: Die Währung von {} - {} stimmt nicht mit der Firmenwährung überein., @@ -9060,6 +9064,14 @@ Leave Type Allocation,Zuordnung Abwesenheitsarten, From Lead,Aus Lead, From Opportunity,Aus Chance, Publish in Website,Auf Webseite veröffentlichen, +<<<<<<< HEAD +======= +Total Allocated Leave(s),Gesamte zugewiesene Urlaubstage, +Expired Leave(s),Verfallene Urlaubstage, +Used Leave(s),Verbrauchte Urlaubstage, +Leave(s) Pending Approval,Urlaubstage zur Genehmigung ausstehend, +Available Leave(s),Verfügbare Urlaubstage, +>>>>>>> 915102a400 (chore: german translations (#31463)) Party Specific Item,Parteispezifischer Artikel, Active Customers,Aktive Kunden, Annual Sales,Jährlicher Umsatz, @@ -9074,6 +9086,10 @@ Accounts Payable Ageing,Fälligkeit Verbindlichkeiten, Budget Variance,Budgetabweichung, Based On Value,Basierend auf Wert, Restrict Items Based On,Artikel einschränken auf Basis von, +<<<<<<< HEAD +======= +Earnings & Deductions,Erträge & Abzüge, +>>>>>>> 915102a400 (chore: german translations (#31463)) Is Process Loss,Ist Prozessverlust, Is Finished Item,Ist fertiger Artikel, Is Scrap Item,Ist Schrott, @@ -9082,6 +9098,7 @@ Show Remarks,Bemerkungen anzeigen, Website Item,Webseiten-Artikel, Update Property,Eigenschaft aktualisieren, Recurring Sales Invoice,Wiederkehrende Ausgangsrechnung, +<<<<<<< HEAD Total Asset,Aktiva, Total Liability,Verbindlichkeiten, Total Equity,Eigenkapital, @@ -9108,3 +9125,5 @@ Lost Quotations,Verlorene Angebote, Lost Quotations %,Verlorene Angebote %, Lost Value,Verlorener Wert, Lost Value %,Verlorener Wert %, +======= +>>>>>>> 915102a400 (chore: german translations (#31463)) From 2899d2bac1e0dd63d13b12c18564fc3382b19329 Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Sat, 24 Feb 2024 18:28:51 +0100 Subject: [PATCH 004/192] chore: resolve conflicts --- erpnext/translations/de.csv | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/erpnext/translations/de.csv b/erpnext/translations/de.csv index e0589c833d96..13aaa67c4890 100644 --- a/erpnext/translations/de.csv +++ b/erpnext/translations/de.csv @@ -189,10 +189,6 @@ All other ITC,Alle anderen ITC, All the mandatory Task for employee creation hasn't been done yet.,Alle obligatorischen Aufgaben zur Mitarbeitererstellung wurden noch nicht erledigt., Allocate Payment Amount,Zahlungsbetrag zuweisen, Allocated Amount,Zugewiesene Menge, -<<<<<<< HEAD -======= -Allocated Leaves,Zugewiesene Urlaubstage, ->>>>>>> 915102a400 (chore: german translations (#31463)) Allocating leaves...,Blätter zuordnen..., Already record exists for the item {0},Es existiert bereits ein Datensatz für den Artikel {0}, "Already set default in pos profile {0} for user {1}, kindly disabled default","Im Standardprofil {0} für den Benutzer {1} ist der Standard bereits festgelegt, standardmäßig deaktiviert", @@ -9064,14 +9060,6 @@ Leave Type Allocation,Zuordnung Abwesenheitsarten, From Lead,Aus Lead, From Opportunity,Aus Chance, Publish in Website,Auf Webseite veröffentlichen, -<<<<<<< HEAD -======= -Total Allocated Leave(s),Gesamte zugewiesene Urlaubstage, -Expired Leave(s),Verfallene Urlaubstage, -Used Leave(s),Verbrauchte Urlaubstage, -Leave(s) Pending Approval,Urlaubstage zur Genehmigung ausstehend, -Available Leave(s),Verfügbare Urlaubstage, ->>>>>>> 915102a400 (chore: german translations (#31463)) Party Specific Item,Parteispezifischer Artikel, Active Customers,Aktive Kunden, Annual Sales,Jährlicher Umsatz, @@ -9086,10 +9074,6 @@ Accounts Payable Ageing,Fälligkeit Verbindlichkeiten, Budget Variance,Budgetabweichung, Based On Value,Basierend auf Wert, Restrict Items Based On,Artikel einschränken auf Basis von, -<<<<<<< HEAD -======= -Earnings & Deductions,Erträge & Abzüge, ->>>>>>> 915102a400 (chore: german translations (#31463)) Is Process Loss,Ist Prozessverlust, Is Finished Item,Ist fertiger Artikel, Is Scrap Item,Ist Schrott, @@ -9098,7 +9082,6 @@ Show Remarks,Bemerkungen anzeigen, Website Item,Webseiten-Artikel, Update Property,Eigenschaft aktualisieren, Recurring Sales Invoice,Wiederkehrende Ausgangsrechnung, -<<<<<<< HEAD Total Asset,Aktiva, Total Liability,Verbindlichkeiten, Total Equity,Eigenkapital, @@ -9125,5 +9108,3 @@ Lost Quotations,Verlorene Angebote, Lost Quotations %,Verlorene Angebote %, Lost Value,Verlorener Wert, Lost Value %,Verlorener Wert %, -======= ->>>>>>> 915102a400 (chore: german translations (#31463)) From fe986989a9a9bc249bb07564a47b4c44df4db920 Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Sat, 24 Feb 2024 18:29:46 +0100 Subject: [PATCH 005/192] chore: remove duplicate german translations --- erpnext/translations/de.csv | 2 -- 1 file changed, 2 deletions(-) diff --git a/erpnext/translations/de.csv b/erpnext/translations/de.csv index 13aaa67c4890..2f714326ad99 100644 --- a/erpnext/translations/de.csv +++ b/erpnext/translations/de.csv @@ -9057,7 +9057,6 @@ Apply Putaway Rule,Einlagerungsregel anwenden, Default Discount Account,Standard-Rabattkonto, Default Provisional Account,Standard Provisorisches Konto, Leave Type Allocation,Zuordnung Abwesenheitsarten, -From Lead,Aus Lead, From Opportunity,Aus Chance, Publish in Website,Auf Webseite veröffentlichen, Party Specific Item,Parteispezifischer Artikel, @@ -9103,7 +9102,6 @@ Select Alternative Items for Sales Order,Alternativpositionen für Auftragsbest Select an item from each set to be used in the Sales Order.,"Wählen Sie aus den Alternativen jeweils einen Artikel aus, der in die Auftragsbestätigung übernommen werden soll.", Is Alternative,Ist Alternative, Alternative Items,Alternativpositionen, -Component Type,Komponententyp, Lost Quotations,Verlorene Angebote, Lost Quotations %,Verlorene Angebote %, Lost Value,Verlorener Wert, From 23e256aedf65c8ad9fb39a507772798a374a209a Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 26 Feb 2024 12:53:06 +0530 Subject: [PATCH 006/192] fix: Patch to remove cancelled asset capitalization from asset --- .../asset_capitalization/asset_capitalization.py | 4 ++++ erpnext/patches.txt | 1 + ...remove_cancelled_asset_capitalization_from_asset.py | 10 ++++++++++ 3 files changed, 15 insertions(+) create mode 100644 erpnext/patches/v14_0/remove_cancelled_asset_capitalization_from_asset.py diff --git a/erpnext/assets/doctype/asset_capitalization/asset_capitalization.py b/erpnext/assets/doctype/asset_capitalization/asset_capitalization.py index 2b5d8d0ffdd3..f3464e2aba1f 100644 --- a/erpnext/assets/doctype/asset_capitalization/asset_capitalization.py +++ b/erpnext/assets/doctype/asset_capitalization/asset_capitalization.py @@ -83,6 +83,10 @@ def on_cancel(self): self.update_stock_ledger() self.make_gl_entries() self.restore_consumed_asset_items() + + def on_trash(self): + frappe.db.set_value("Asset", self.target_asset, "capitalized_in", None) + super(AssetCapitalization, self).on_trash() def cancel_target_asset(self): if self.entry_type == "Capitalization" and self.target_asset: diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 125158a5add0..e0b8534f9fe2 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -359,3 +359,4 @@ erpnext.stock.doctype.delivery_note.patches.drop_unused_return_against_index # 2 erpnext.patches.v14_0.set_maintain_stock_for_bom_item execute:frappe.db.set_single_value('E Commerce Settings', 'show_actual_qty', 1) erpnext.patches.v14_0.delete_orphaned_asset_movement_item_records +erpnext.patches.v14_0.remove_cancelled_asset_capitalization_from_asset diff --git a/erpnext/patches/v14_0/remove_cancelled_asset_capitalization_from_asset.py b/erpnext/patches/v14_0/remove_cancelled_asset_capitalization_from_asset.py new file mode 100644 index 000000000000..82f3c2055827 --- /dev/null +++ b/erpnext/patches/v14_0/remove_cancelled_asset_capitalization_from_asset.py @@ -0,0 +1,10 @@ +import frappe + +def execute(): + cancelled_asset_capitalizations = frappe.get_all( + "Asset Capitalization", + filters={"docstatus": 2}, + fields=["name", "target_asset"], + ) + for asset_capitalization in cancelled_asset_capitalizations: + frappe.db.set_value("Asset", asset_capitalization.target_asset, "capitalized_in", None) From c7ed854850739d39442828019d6a813c5aa064fc Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 26 Feb 2024 14:49:32 +0530 Subject: [PATCH 007/192] fix: Reload document on cancel to avoid document modified error --- erpnext/assets/doctype/asset/asset.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/erpnext/assets/doctype/asset/asset.py b/erpnext/assets/doctype/asset/asset.py index 7f5e4debf299..555456101001 100644 --- a/erpnext/assets/doctype/asset/asset.py +++ b/erpnext/assets/doctype/asset/asset.py @@ -57,6 +57,7 @@ def on_submit(self): self.validate_in_use_date() self.set_status() self.make_asset_movement() + self.reload() if not self.booked_fixed_asset and self.validate_make_gl_entry(): self.make_gl_entries() @@ -64,6 +65,7 @@ def on_cancel(self): self.validate_cancellation() self.cancel_movement_entries() self.cancel_capitalization() + self.reload() self.delete_depreciation_entries() self.set_status() self.ignore_linked_doctypes = ("GL Entry", "Stock Ledger Entry") From d7b738ff61e0ebab62ff2c15247f90b79401e9a4 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 27 Feb 2024 14:40:15 +0530 Subject: [PATCH 008/192] perf: Optimization for providional gl entries --- .../purchase_invoice/purchase_invoice.py | 55 ++++++++++--------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index cfaaf7677869..35652b71c4de 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -720,7 +720,7 @@ def make_item_gl_entries(self, gl_entries): "Company", self.company, "enable_provisional_accounting_for_non_stock_items" ) ) - + provisional_enpenses_booked_in_pr = False purchase_receipt_doc_map = {} for item in self.get("items"): @@ -859,34 +859,37 @@ def make_item_gl_entries(self, gl_entries): if provisional_accounting_for_non_stock_items: if item.purchase_receipt: - provisional_account, pr_qty, pr_base_rate = frappe.get_cached_value( - "Purchase Receipt Item", - item.pr_detail, - ["provisional_expense_account", "qty", "base_rate"], - ) - provisional_account = provisional_account or self.get_company_default( - "default_provisional_account" - ) - purchase_receipt_doc = purchase_receipt_doc_map.get(item.purchase_receipt) + if not provisional_enpenses_booked_in_pr: + provisional_account, pr_qty, pr_base_rate = frappe.get_cached_value( + "Purchase Receipt Item", + item.pr_detail, + ["provisional_expense_account", "qty", "base_rate"], + ) + provisional_account = provisional_account or self.get_company_default( + "default_provisional_account" + ) + # Post reverse entry for Stock-Received-But-Not-Billed if it is booked in Purchase Receipt + provision_gle_against_pr = frappe.db.get_value( + "GL Entry", + { + "is_cancelled": 0, + "voucher_type": "Purchase Receipt", + "voucher_no": item.purchase_receipt, + "voucher_detail_no": item.pr_detail, + "account": provisional_account, + }, + ["name"], + ) + if provision_gle_against_pr: + provisional_enpenses_booked_in_pr = True - if not purchase_receipt_doc: - purchase_receipt_doc = frappe.get_doc("Purchase Receipt", item.purchase_receipt) - purchase_receipt_doc_map[item.purchase_receipt] = purchase_receipt_doc + if provisional_enpenses_booked_in_pr: + purchase_receipt_doc = purchase_receipt_doc_map.get(item.purchase_receipt) - # Post reverse entry for Stock-Received-But-Not-Billed if it is booked in Purchase Receipt - expense_booked_in_pr = frappe.db.get_value( - "GL Entry", - { - "is_cancelled": 0, - "voucher_type": "Purchase Receipt", - "voucher_no": item.purchase_receipt, - "voucher_detail_no": item.pr_detail, - "account": provisional_account, - }, - "name", - ) + if not purchase_receipt_doc: + purchase_receipt_doc = frappe.get_doc("Purchase Receipt", item.purchase_receipt) + purchase_receipt_doc_map[item.purchase_receipt] = purchase_receipt_doc - if expense_booked_in_pr: # Intentionally passing purchase invoice item to handle partial billing purchase_receipt_doc.add_provisional_gl_entry( item, From f204d810bba5a6fdb3137b780489907c30b650fc Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 4 Mar 2024 15:46:15 +0530 Subject: [PATCH 009/192] perf: Performance optimization for validating budget --- erpnext/accounts/doctype/budget/budget.py | 6 +- .../budget_account/budget_account.json | 124 +++++------------- 2 files changed, 40 insertions(+), 90 deletions(-) diff --git a/erpnext/accounts/doctype/budget/budget.py b/erpnext/accounts/doctype/budget/budget.py index 6cfd15d3ec82..2f3b9a4784e3 100644 --- a/erpnext/accounts/doctype/budget/budget.py +++ b/erpnext/accounts/doctype/budget/budget.py @@ -109,6 +109,8 @@ def before_naming(self): def validate_expense_against_budget(args, expense_amount=0): args = frappe._dict(args) + if not frappe.get_all("Budget", limit=1): + return if args.get("company") and not args.fiscal_year: args.fiscal_year = get_fiscal_year(args.get("posting_date"), company=args.get("company"))[0] @@ -142,13 +144,13 @@ def validate_expense_against_budget(args, expense_amount=0): if ( args.get(budget_against) and args.account - and frappe.db.get_value("Account", {"name": args.account, "root_type": "Expense"}) + and (frappe.get_cached_value("Account", args.account, "root_type") == "Expense") ): doctype = dimension.get("document_type") if frappe.get_cached_value("DocType", doctype, "is_tree"): - lft, rgt = frappe.db.get_value(doctype, args.get(budget_against), ["lft", "rgt"]) + lft, rgt = frappe.get_cached_value(doctype, args.get(budget_against), ["lft", "rgt"]) condition = """and exists(select name from `tab%s` where lft<=%s and rgt>=%s and name=b.%s)""" % ( doctype, diff --git a/erpnext/accounts/doctype/budget_account/budget_account.json b/erpnext/accounts/doctype/budget_account/budget_account.json index ead07614a7f6..c7d872647f15 100644 --- a/erpnext/accounts/doctype/budget_account/budget_account.json +++ b/erpnext/accounts/doctype/budget_account/budget_account.json @@ -1,94 +1,42 @@ { - "allow_copy": 0, - "allow_import": 0, - "allow_rename": 0, - "beta": 0, - "creation": "2016-05-16 11:54:09.286135", - "custom": 0, - "docstatus": 0, - "doctype": "DocType", - "document_type": "", - "editable_grid": 1, - "engine": "InnoDB", + "actions": [], + "creation": "2016-05-16 11:54:09.286135", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "account", + "budget_amount" + ], "fields": [ { - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "account", - "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_list_view": 1, - "label": "Account", - "length": 0, - "no_copy": 0, - "options": "Account", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 1, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, + "fieldname": "account", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Account", + "options": "Account", + "reqd": 1, + "search_index": 1 + }, { - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "budget_amount", - "fieldtype": "Currency", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_list_view": 1, - "label": "Budget Amount", - "length": 0, - "no_copy": 0, - "options": "Company:company:default_currency", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 1, - "search_index": 0, - "set_only_once": 0, - "unique": 0 + "fieldname": "budget_amount", + "fieldtype": "Currency", + "in_list_view": 1, + "label": "Budget Amount", + "options": "Company:company:default_currency", + "reqd": 1 } - ], - "hide_heading": 0, - "hide_toolbar": 0, - "idx": 0, - "image_view": 0, - "in_create": 0, - - "is_submittable": 0, - "issingle": 0, - "istable": 1, - "max_attachments": 0, - "modified": "2017-01-02 17:02:53.339420", - "modified_by": "Administrator", - "module": "Accounts", - "name": "Budget Account", - "name_case": "", - "owner": "Administrator", - "permissions": [], - "quick_entry": 1, - "read_only": 0, - "read_only_onload": 0, - "sort_field": "modified", - "sort_order": "DESC", - "track_seen": 0 + ], + "istable": 1, + "links": [], + "modified": "2024-03-04 15:43:27.016947", + "modified_by": "Administrator", + "module": "Accounts", + "name": "Budget Account", + "owner": "Administrator", + "permissions": [], + "quick_entry": 1, + "sort_field": "modified", + "sort_order": "DESC", + "states": [] } \ No newline at end of file From 8cd8b8f885419fac8297b171e90be7657357a0e3 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 4 Mar 2024 15:47:09 +0530 Subject: [PATCH 010/192] perf: Cached accounting dimensions details --- .../accounting_dimension/accounting_dimension.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py index 8afd313322ec..52dda51708fd 100644 --- a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py +++ b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py @@ -236,14 +236,15 @@ def get_accounting_dimensions(as_list=True, filters=None): def get_checks_for_pl_and_bs_accounts(): - dimensions = frappe.db.sql( - """SELECT p.label, p.disabled, p.fieldname, c.default_dimension, c.company, c.mandatory_for_pl, c.mandatory_for_bs - FROM `tabAccounting Dimension`p ,`tabAccounting Dimension Detail` c - WHERE p.name = c.parent""", - as_dict=1, - ) + if frappe.flags.accounting_dimensions_details is None: + frappe.flags.accounting_dimensions_details = frappe.db.sql( + """SELECT p.label, p.disabled, p.fieldname, c.default_dimension, c.company, c.mandatory_for_pl, c.mandatory_for_bs + FROM `tabAccounting Dimension`p ,`tabAccounting Dimension Detail` c + WHERE p.name = c.parent""", + as_dict=1, + ) - return dimensions + return frappe.flags.accounting_dimensions_details def get_dimension_with_children(doctype, dimensions): From aa75a6014264853668acd15e996e8fd0af8e7ebe Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 4 Mar 2024 15:47:56 +0530 Subject: [PATCH 011/192] perf: Optimzed code for merging similar gl entries --- erpnext/accounts/doctype/gl_entry/gl_entry.py | 4 +- erpnext/accounts/general_ledger.py | 41 +++++++++---------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/erpnext/accounts/doctype/gl_entry/gl_entry.py b/erpnext/accounts/doctype/gl_entry/gl_entry.py index 6e07b0ec430c..c0f6502910e3 100644 --- a/erpnext/accounts/doctype/gl_entry/gl_entry.py +++ b/erpnext/accounts/doctype/gl_entry/gl_entry.py @@ -127,7 +127,7 @@ def pl_must_have_cost_center(self): frappe.throw(msg, title=_("Missing Cost Center")) def validate_dimensions_for_pl_and_bs(self): - account_type = frappe.db.get_value("Account", self.account, "report_type") + account_type = frappe.get_cached_value("Account", self.account, "report_type") for dimension in get_checks_for_pl_and_bs_accounts(): if ( @@ -252,7 +252,7 @@ def on_cancel(self): def validate_balance_type(account, adv_adj=False): if not adv_adj and account: - balance_must_be = frappe.db.get_value("Account", account, "balance_must_be") + balance_must_be = frappe.get_cached_value("Account", account, "balance_must_be") if balance_must_be: balance = frappe.db.sql( """select sum(debit) - sum(credit) diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py index 38fcd976ad4a..b1223b271f57 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -234,11 +234,13 @@ def get_cost_center_allocation_data(company, posting_date): def merge_similar_entries(gl_map, precision=None): merged_gl_map = [] accounting_dimensions = get_accounting_dimensions() + merge_properties = get_merge_properties(accounting_dimensions) for entry in gl_map: + entry.merge_key = get_merge_key(entry, merge_properties) # if there is already an entry in this account then just add it # to that entry - same_head = check_if_in_list(entry, merged_gl_map, accounting_dimensions) + same_head = check_if_in_list(entry, merged_gl_map) if same_head: same_head.debit = flt(same_head.debit) + flt(entry.debit) same_head.debit_in_account_currency = flt(same_head.debit_in_account_currency) + flt( @@ -272,37 +274,34 @@ def merge_similar_entries(gl_map, precision=None): return merged_gl_map - -def check_if_in_list(gle, gl_map, dimensions=None): - account_head_fieldnames = [ - "voucher_detail_no", +def get_merge_properties(dimensions=None): + merge_properties = [ + "account", + "cost_center", "party", + "party_type", + "voucher_detail_no", "against_voucher", - "cost_center", "against_voucher_type", - "party_type", "project", "finance_book", ] - if dimensions: - account_head_fieldnames = account_head_fieldnames + dimensions - - for e in gl_map: - same_head = True - if e.account != gle.account: - same_head = False - continue + merge_properties.extend(dimensions) + return merge_properties - for fieldname in account_head_fieldnames: - if cstr(e.get(fieldname)) != cstr(gle.get(fieldname)): - same_head = False - break +def get_merge_key(entry, merge_properties): + merge_key = [] + for fieldname in merge_properties: + merge_key.append(entry.get(fieldname, '')) + + return tuple(merge_key) - if same_head: +def check_if_in_list(gle, gl_map): + for e in gl_map: + if e.merge_key == gle.merge_key: return e - def toggle_debit_credit_if_negative(gl_map): for entry in gl_map: # toggle debit, credit if negative entry From acc0b2faf82c2b352cc2caf14ef26e6e55f34230 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 6 Mar 2024 17:43:27 +0530 Subject: [PATCH 012/192] fix: linter issues --- erpnext/accounts/general_ledger.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py index b1223b271f57..432abc250b12 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -7,7 +7,7 @@ import frappe from frappe import _ from frappe.model.meta import get_field_precision -from frappe.utils import cint, cstr, flt, formatdate, getdate, now +from frappe.utils import cint, flt, formatdate, getdate, now import erpnext from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import ( @@ -274,6 +274,7 @@ def merge_similar_entries(gl_map, precision=None): return merged_gl_map + def get_merge_properties(dimensions=None): merge_properties = [ "account", @@ -290,18 +291,21 @@ def get_merge_properties(dimensions=None): merge_properties.extend(dimensions) return merge_properties + def get_merge_key(entry, merge_properties): merge_key = [] for fieldname in merge_properties: - merge_key.append(entry.get(fieldname, '')) - + merge_key.append(entry.get(fieldname, "")) + return tuple(merge_key) + def check_if_in_list(gle, gl_map): for e in gl_map: if e.merge_key == gle.merge_key: return e + def toggle_debit_credit_if_negative(gl_map): for entry in gl_map: # toggle debit, credit if negative entry From e4bd1738752896e9a50231561c8ca5f3a2ee15c5 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 6 Mar 2024 20:32:47 +0530 Subject: [PATCH 013/192] perf: Cache accounting dimension filter map --- .../accounting_dimension_filter.py | 57 ++++++++++--------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.py b/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.py index 80f736fa5bbe..56f2eb71393f 100644 --- a/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.py +++ b/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.py @@ -38,37 +38,40 @@ def validate_applicable_accounts(self): def get_dimension_filter_map(): - filters = frappe.db.sql( - """ - SELECT - a.applicable_on_account, d.dimension_value, p.accounting_dimension, - p.allow_or_restrict, a.is_mandatory - FROM - `tabApplicable On Account` a, `tabAllowed Dimension` d, - `tabAccounting Dimension Filter` p - WHERE - p.name = a.parent - AND p.disabled = 0 - AND p.name = d.parent - """, - as_dict=1, - ) + if not frappe.flags.get("dimension_filter_map"): + filters = frappe.db.sql( + """ + SELECT + a.applicable_on_account, d.dimension_value, p.accounting_dimension, + p.allow_or_restrict, a.is_mandatory + FROM + `tabApplicable On Account` a, `tabAllowed Dimension` d, + `tabAccounting Dimension Filter` p + WHERE + p.name = a.parent + AND p.disabled = 0 + AND p.name = d.parent + """, + as_dict=1, + ) - dimension_filter_map = {} + dimension_filter_map = {} - for f in filters: - f.fieldname = scrub(f.accounting_dimension) + for f in filters: + f.fieldname = scrub(f.accounting_dimension) - build_map( - dimension_filter_map, - f.fieldname, - f.applicable_on_account, - f.dimension_value, - f.allow_or_restrict, - f.is_mandatory, - ) + build_map( + dimension_filter_map, + f.fieldname, + f.applicable_on_account, + f.dimension_value, + f.allow_or_restrict, + f.is_mandatory, + ) + + frappe.flags.dimension_filter_map = dimension_filter_map - return dimension_filter_map + return frappe.flags.dimension_filter_map def build_map(map_object, dimension, account, filter_value, allow_or_restrict, is_mandatory): From 5cd9bf3bda1c63fc04b6b4db8ddfdb2f9c7b456e Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 6 Mar 2024 21:04:07 +0530 Subject: [PATCH 014/192] fix: minor fixes --- .../doctype/accounting_dimension/accounting_dimension.py | 1 + .../doctype/accounting_dimension/test_accounting_dimension.py | 1 + .../accounting_dimension_filter/accounting_dimension_filter.py | 1 + 3 files changed, 3 insertions(+) diff --git a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py index 52dda51708fd..c6c5f207a6a1 100644 --- a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py +++ b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py @@ -237,6 +237,7 @@ def get_accounting_dimensions(as_list=True, filters=None): def get_checks_for_pl_and_bs_accounts(): if frappe.flags.accounting_dimensions_details is None: + # nosemgrep frappe.flags.accounting_dimensions_details = frappe.db.sql( """SELECT p.label, p.disabled, p.fieldname, c.default_dimension, c.company, c.mandatory_for_pl, c.mandatory_for_bs FROM `tabAccounting Dimension`p ,`tabAccounting Dimension Detail` c diff --git a/erpnext/accounts/doctype/accounting_dimension/test_accounting_dimension.py b/erpnext/accounts/doctype/accounting_dimension/test_accounting_dimension.py index 25ef2ea5c2c2..6de3215cc596 100644 --- a/erpnext/accounts/doctype/accounting_dimension/test_accounting_dimension.py +++ b/erpnext/accounts/doctype/accounting_dimension/test_accounting_dimension.py @@ -78,6 +78,7 @@ def test_mandatory(self): def tearDown(self): disable_dimension() + frappe.flags.accounting_dimensions_details = None def create_dimension(): diff --git a/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.py b/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.py index 56f2eb71393f..652627642949 100644 --- a/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.py +++ b/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.py @@ -39,6 +39,7 @@ def validate_applicable_accounts(self): def get_dimension_filter_map(): if not frappe.flags.get("dimension_filter_map"): + # nosemgrep filters = frappe.db.sql( """ SELECT From 05385e4acb0f3af7e9cd19c752df8d7287f73401 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 6 Mar 2024 22:33:36 +0530 Subject: [PATCH 015/192] perf: skip unnecessary validation while transaction cancellation --- .../accounting_dimension/test_accounting_dimension.py | 1 + .../test_accounting_dimension_filter.py | 2 ++ .../doctype/payment_ledger_entry/payment_ledger_entry.py | 9 +++++---- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/doctype/accounting_dimension/test_accounting_dimension.py b/erpnext/accounts/doctype/accounting_dimension/test_accounting_dimension.py index 6de3215cc596..2ceaffc4e252 100644 --- a/erpnext/accounts/doctype/accounting_dimension/test_accounting_dimension.py +++ b/erpnext/accounts/doctype/accounting_dimension/test_accounting_dimension.py @@ -79,6 +79,7 @@ def test_mandatory(self): def tearDown(self): disable_dimension() frappe.flags.accounting_dimensions_details = None + frappe.flags.dimension_filter_map = None def create_dimension(): diff --git a/erpnext/accounts/doctype/accounting_dimension_filter/test_accounting_dimension_filter.py b/erpnext/accounts/doctype/accounting_dimension_filter/test_accounting_dimension_filter.py index f13f2f9f2791..3dc87bb4e386 100644 --- a/erpnext/accounts/doctype/accounting_dimension_filter/test_accounting_dimension_filter.py +++ b/erpnext/accounts/doctype/accounting_dimension_filter/test_accounting_dimension_filter.py @@ -47,6 +47,8 @@ def test_mandatory_dimension_validation(self): def tearDown(self): disable_dimension_filter() disable_dimension() + frappe.flags.accounting_dimensions_details = None + frappe.flags.dimension_filter_map = None for si in self.invoice_list: si.load_from_db() diff --git a/erpnext/accounts/doctype/payment_ledger_entry/payment_ledger_entry.py b/erpnext/accounts/doctype/payment_ledger_entry/payment_ledger_entry.py index bcbcb670faf2..bd438ee76063 100644 --- a/erpnext/accounts/doctype/payment_ledger_entry/payment_ledger_entry.py +++ b/erpnext/accounts/doctype/payment_ledger_entry/payment_ledger_entry.py @@ -132,11 +132,12 @@ def validate(self): def on_update(self): adv_adj = self.flags.adv_adj if not self.flags.from_repost: - self.validate_account_details() - self.validate_dimensions_for_pl_and_bs() - self.validate_allowed_dimensions() - validate_balance_type(self.account, adv_adj) validate_frozen_account(self.account, adv_adj) + if not self.delinked: + self.validate_account_details() + self.validate_dimensions_for_pl_and_bs() + self.validate_allowed_dimensions() + validate_balance_type(self.account, adv_adj) # update outstanding amount if ( From 911a582941ec2a63aeb642b43d2af91c7e543b6a Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Wed, 6 Mar 2024 16:52:19 +0100 Subject: [PATCH 016/192] fix(Shipment Parcel): make length, width and height non-mandatory It's tedious to enter all these values and some shipping providers only need to know the weigth and quantity. Companies can alwas cutomize the values to be mandatory, but the reverse is not possible. I'll make sure that the erpnext-shipping app does not break because of this (or fix any problems). (cherry picked from commit 898c6e30eb44ece8869b5bb354239631407ef578) --- .../doctype/shipment_parcel/shipment_parcel.json | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/erpnext/stock/doctype/shipment_parcel/shipment_parcel.json b/erpnext/stock/doctype/shipment_parcel/shipment_parcel.json index 6943edcdc91f..0dc4fd113fc8 100644 --- a/erpnext/stock/doctype/shipment_parcel/shipment_parcel.json +++ b/erpnext/stock/doctype/shipment_parcel/shipment_parcel.json @@ -16,22 +16,19 @@ "fieldname": "length", "fieldtype": "Int", "in_list_view": 1, - "label": "Length (cm)", - "reqd": 1 + "label": "Length (cm)" }, { "fieldname": "width", "fieldtype": "Int", "in_list_view": 1, - "label": "Width (cm)", - "reqd": 1 + "label": "Width (cm)" }, { "fieldname": "height", "fieldtype": "Int", "in_list_view": 1, - "label": "Height (cm)", - "reqd": 1 + "label": "Height (cm)" }, { "fieldname": "weight", @@ -52,7 +49,7 @@ ], "istable": 1, "links": [], - "modified": "2020-07-09 12:54:14.847170", + "modified": "2024-03-06 16:48:57.355757", "modified_by": "Administrator", "module": "Stock", "name": "Shipment Parcel", @@ -61,5 +58,6 @@ "quick_entry": 1, "sort_field": "modified", "sort_order": "DESC", + "states": [], "track_changes": 1 } \ No newline at end of file From 411157c258a94a1c162d081b3a4fb2bfb3afe12e Mon Sep 17 00:00:00 2001 From: "Nihantra C. Patel" <141945075+Nihantra-Patel@users.noreply.github.com> Date: Thu, 7 Mar 2024 17:43:00 +0530 Subject: [PATCH 017/192] fix: load ignored doctype and include Mode of Payment Account (#40334) (cherry picked from commit 68baa3612abfe70465adb869279a706a3e60c355) --- .../transaction_deletion_record/transaction_deletion_record.js | 2 +- .../transaction_deletion_record/transaction_deletion_record.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/erpnext/setup/doctype/transaction_deletion_record/transaction_deletion_record.js b/erpnext/setup/doctype/transaction_deletion_record/transaction_deletion_record.js index 6a50ef8bbd90..a7b0709b3da2 100644 --- a/erpnext/setup/doctype/transaction_deletion_record/transaction_deletion_record.js +++ b/erpnext/setup/doctype/transaction_deletion_record/transaction_deletion_record.js @@ -29,7 +29,7 @@ frappe.ui.form.on('Transaction Deletion Record', { }); function populate_doctypes_to_be_ignored(doctypes_to_be_ignored_array, frm) { - if (!(frm.doc.doctypes_to_be_ignored)) { + if (frm.doc.doctypes_to_be_ignored.length === 0) { var i; for (i = 0; i < doctypes_to_be_ignored_array.length; i++) { frm.add_child('doctypes_to_be_ignored', { diff --git a/erpnext/setup/doctype/transaction_deletion_record/transaction_deletion_record.py b/erpnext/setup/doctype/transaction_deletion_record/transaction_deletion_record.py index d266285b29a3..649b43b5e914 100644 --- a/erpnext/setup/doctype/transaction_deletion_record/transaction_deletion_record.py +++ b/erpnext/setup/doctype/transaction_deletion_record/transaction_deletion_record.py @@ -267,6 +267,7 @@ def get_doctypes_to_be_ignored(): "Bank Account", "Item Tax Template", "Mode of Payment", + "Mode of Payment Account", "Item Default", "Customer", "Supplier", From 8d63d19d451de4b9ff50d1c34e8d3cd911af94c3 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Thu, 7 Mar 2024 09:14:56 +0530 Subject: [PATCH 018/192] fix: Filter for projects in Sales Cycle (cherry picked from commit d0e0b66b2f0586e93a3e3cc640036c8e311d2070) --- erpnext/controllers/queries.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/erpnext/controllers/queries.py b/erpnext/controllers/queries.py index 303548cca426..59060925025f 100644 --- a/erpnext/controllers/queries.py +++ b/erpnext/controllers/queries.py @@ -338,7 +338,9 @@ def get_project_name(doctype, txt, searchfield, start, page_len, filters): ifelse = CustomFunction("IF", ["condition", "then", "else"]) if filters and filters.get("customer"): - qb_filter_and_conditions.append(proj.customer == filters.get("customer")) + qb_filter_and_conditions.append( + (proj.customer == filters.get("customer")) | proj.customer.isnull() | proj.customer == "" + ) qb_filter_and_conditions.append(proj.status.notin(["Completed", "Cancelled"])) From ea605e76a33c4014ec25e791ee8c9504ec515683 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Thu, 7 Mar 2024 10:08:51 +0530 Subject: [PATCH 019/192] fix: Sender email in process statements of accounts (cherry picked from commit 65a2f3d12c0e813ca6af3d2ebe1e1734c8d8acc7) --- .../process_statement_of_accounts.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py index 222c9628018c..9c0bedd243fa 100644 --- a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py +++ b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py @@ -397,11 +397,16 @@ def send_emails(document_name, from_scheduler=False, posting_date=None): subject = frappe.render_template(doc.subject, context) message = frappe.render_template(doc.body, context) + if doc.sender: + sender_email = frappe.db.get_value("Email Account", doc.sender, "email_id") + else: + sender_email = frappe.session.user + frappe.enqueue( queue="short", method=frappe.sendmail, recipients=recipients, - sender=doc.sender or frappe.session.user, + sender=sender_email, cc=cc, subject=subject, message=message, From e0d1b4b15f0064bc7488848e21ea44991564f553 Mon Sep 17 00:00:00 2001 From: Devin Slauenwhite Date: Fri, 8 Mar 2024 18:09:11 -0500 Subject: [PATCH 020/192] fix: get_user_default_as_list args order (cherry picked from commit ac1961b687f76987cb8095d76d4b3e1cb67d766c) --- erpnext/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/__init__.py b/erpnext/__init__.py index 96f8ec27ec17..497416b12aba 100644 --- a/erpnext/__init__.py +++ b/erpnext/__init__.py @@ -13,7 +13,7 @@ def get_default_company(user=None): if not user: user = frappe.session.user - companies = get_user_default_as_list(user, "company") + companies = get_user_default_as_list("company", user) if companies: default_company = companies[0] else: From c46be27e9e0b1bfee837ddb53215e3b8403b557f Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Thu, 29 Feb 2024 17:08:25 +0100 Subject: [PATCH 021/192] ci: add prettier to pre-commit (cherry picked from commit 2c16036ef3f2ebf6a707b5ae8fa486fa102bc1dc) --- .editorconfig | 9 ++++++++- .eslintrc | 3 ++- .pre-commit-config.yaml | 45 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/.editorconfig b/.editorconfig index 24f122a8d43b..e7d5cfeddcbf 100644 --- a/.editorconfig +++ b/.editorconfig @@ -9,6 +9,13 @@ trim_trailing_whitespace = true charset = utf-8 # python, js indentation settings -[{*.py,*.js}] +[{*.py,*.js,*.vue,*.css,*.scss,*.html}] indent_style = tab indent_size = 4 +max_line_length = 110 + +# JSON files - mostly doctype schema files +[{*.json}] +insert_final_newline = false +indent_style = space +indent_size = 2 diff --git a/.eslintrc b/.eslintrc index 276d6ff37252..4a5f87171e8e 100644 --- a/.eslintrc +++ b/.eslintrc @@ -156,6 +156,7 @@ "onScan": true, "html2canvas": true, "extend_cscript": true, - "localforage": true + "localforage": true, + "Plaid": true } } diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fba2f74a5b96..b95b32d7ddb9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -20,6 +20,51 @@ repos: - id: check-yaml - id: debug-statements + - repo: https://github.com/pre-commit/mirrors-prettier + rev: v2.7.1 + hooks: + - id: prettier + types_or: [javascript, vue, scss] + # Ignore any files that might contain jinja / bundles + exclude: | + (?x)^( + erpnext/public/dist/.*| + cypress/.*| + .*node_modules.*| + .*boilerplate.*| + erpnext/public/js/controllers/.*| + erpnext/templates/pages/order.js| + erpnext/templates/includes/.*| + .*/supplier_quotation.js| + .*/sales_taxes_and_charges_template.js| + .*/purchase_taxes_and_charges_template.js| + .*/subcontracting_order.js| + .*/landed_cost_voucher.js| + .*/payment_entry.js| + .*/loan_interest_accrual.js| + .*/loan_disbursement.js| + .*/loan_application.js| + .*/italy.js| + .*/sales_invoice.js| + .*/subcontracting_receipt.js| + .*/request_for_quotation.js| + .*/pos_profile.js| + .*/opportunity.js| + .*/quotation.js| + .*/sales_common.js| + .*/sales_order.js| + .*/pos_invoice.js| + .*/purchase_invoice.js| + .*/loan_repayment.js| + .*/material_request.js| + .*/purchase_receipt.js| + .*/delivery_note.js| + .*/loan.js| + .*/stock_entry.js| + .*/purchase_order.js| + .*/loan_write_off.js + )$ + - repo: https://github.com/PyCQA/flake8 rev: 5.0.4 hooks: From 4c629d31c6e3f88af449c2ec98680922f88d4b5b Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Mon, 11 Mar 2024 10:58:48 +0530 Subject: [PATCH 022/192] style: format js files --- commitlint.config.js | 26 +- .../account_balance_timeline.js | 8 +- erpnext/accounts/doctype/account/account.js | 214 +- .../accounts/doctype/account/account_tree.js | 304 +- .../accounting_dimension.js | 72 +- .../accounting_dimension_filter.js | 56 +- .../accounting_period/accounting_period.js | 23 +- .../accounts_settings/accounts_settings.js | 6 +- .../regional/united_states.js | 13 +- erpnext/accounts/doctype/bank/bank.js | 75 +- .../doctype/bank_account/bank_account.js | 44 +- .../bank_account_subtype.js | 6 +- .../bank_account_type/bank_account_type.js | 3 +- .../doctype/bank_clearance/bank_clearance.js | 56 +- .../doctype/bank_guarantee/bank_guarantee.js | 53 +- .../bank_reconciliation_tool.js | 130 +- .../bank_statement_import.js | 146 +- .../bank_statement_import_list.js | 34 +- .../bank_transaction/bank_transaction.js | 25 +- .../bank_transaction/bank_transaction_list.js | 12 +- erpnext/accounts/doctype/budget/budget.js | 42 +- .../cash_flow_mapper/cash_flow_mapper.js | 4 +- .../cash_flow_mapping/cash_flow_mapping.js | 34 +- .../cash_flow_mapping_template.js | 4 +- .../cash_flow_mapping_template_details.js | 4 +- .../cashier_closing/cashier_closing.js | 7 +- .../chart_of_accounts_importer.js | 161 +- .../cheque_print_template.js | 48 +- .../doctype/cost_center/cost_center.js | 115 +- .../doctype/cost_center/cost_center_tree.js | 106 +- .../cost_center_allocation.js | 18 +- .../doctype/coupon_code/coupon_code.js | 43 +- .../currency_exchange_settings.js | 25 +- erpnext/accounts/doctype/dunning/dunning.js | 63 +- .../doctype/dunning_type/dunning_type.js | 3 +- .../exchange_rate_revaluation.js | 98 +- .../doctype/finance_book/finance_book.js | 6 +- .../doctype/fiscal_year/fiscal_year.js | 20 +- erpnext/accounts/doctype/gl_entry/gl_entry.js | 8 +- .../invoice_discounting.js | 148 +- .../invoice_discounting_list.js | 21 +- .../item_tax_template/item_tax_template.js | 52 +- .../doctype/journal_entry/journal_entry.js | 506 +- .../journal_entry/journal_entry_list.js | 16 +- .../journal_entry_template.js | 52 +- .../doctype/ledger_merge/ledger_merge.js | 98 +- .../loyalty_point_entry.js | 6 +- .../loyalty_program/loyalty_program.js | 47 +- .../mode_of_payment/mode_of_payment.js | 14 +- .../monthly_distribution.js | 12 +- .../opening_invoice_creation_tool.js | 112 +- .../accounts/doctype/party_link/party_link.js | 29 +- .../payment_entry/payment_entry_list.js | 15 +- .../payment_gateway_account.js | 8 +- .../payment_ledger_entry.js | 3 +- .../doctype/payment_order/payment_order.js | 121 +- .../payment_reconciliation.js | 335 +- .../payment_request/payment_request.js | 84 +- .../payment_request/payment_request_list.js | 24 +- .../doctype/payment_term/payment_term.js | 16 +- .../payment_terms_template.js | 18 +- .../period_closing_voucher.js | 55 +- .../pos_closing_entry/pos_closing_entry.js | 131 +- .../pos_closing_entry_list.js | 19 +- .../doctype/pos_invoice/pos_invoice_list.js | 43 +- .../pos_invoice_merge_log.js | 24 +- .../pos_opening_entry/pos_opening_entry.js | 49 +- .../pos_opening_entry_list.js | 17 +- .../pos_profile_user/pos_profile_user.js | 4 +- .../doctype/pos_settings/pos_settings.js | 88 +- .../doctype/pricing_rule/pricing_rule.js | 94 +- .../process_deferred_accounting.js | 47 +- .../process_payment_reconciliation.js | 111 +- .../process_payment_reconciliation_list.js | 18 +- .../process_payment_reconciliation_log.js | 9 +- ...process_payment_reconciliation_log_list.js | 18 +- .../process_statement_of_accounts.js | 175 +- .../promotional_scheme/promotional_scheme.js | 39 +- .../purchase_invoice/purchase_invoice_list.js | 35 +- .../repost_accounting_ledger.js | 38 +- .../repost_payment_ledger.js | 52 +- .../repost_payment_ledger_list.js | 10 +- .../sales_invoice/sales_invoice_list.js | 38 +- .../doctype/share_transfer/share_transfer.js | 85 +- .../accounts/doctype/share_type/share_type.js | 6 +- .../doctype/shareholder/shareholder.js | 39 +- .../doctype/shipping_rule/shipping_rule.js | 34 +- .../doctype/subscription/subscription.js | 101 +- .../doctype/subscription/subscription_list.js | 20 +- .../subscription_plan/subscription_plan.js | 8 +- .../doctype/tax_category/tax_category.js | 6 +- erpnext/accounts/doctype/tax_rule/tax_rule.js | 36 +- .../tax_withholding_category.js | 14 +- .../unreconcile_payment.js | 35 +- .../report/account_balance/account_balance.js | 72 +- .../accounts_payable/accounts_payable.js | 233 +- .../accounts_payable_summary.js | 179 +- .../accounts_receivable.js | 274 +- .../accounts_receivable_summary.js | 215 +- .../asset_depreciation_ledger.js | 78 +- .../asset_depreciations_and_balances.js | 48 +- .../report/balance_sheet/balance_sheet.js | 44 +- .../bank_clearance_summary.js | 55 +- .../bank_reconciliation_statement.js | 71 +- .../billed_items_to_be_received.js | 38 +- .../budget_variance_report.js | 57 +- .../accounts/report/cash_flow/cash_flow.js | 21 +- .../consolidated_financial_statement.js | 212 +- .../customer_ledger_summary.js | 126 +- .../deferred_revenue_and_expense.js | 152 +- .../delivered_items_to_be_billed.js | 6 +- .../dimension_wise_accounts_balance_report.js | 102 +- .../general_and_payment_ledger_comparison.js | 60 +- .../report/general_ledger/general_ledger.js | 238 +- .../gross_and_net_profit_report.js | 23 +- .../report/gross_profit/gross_profit.js | 81 +- .../inactive_sales_items.js | 12 +- .../item_wise_purchase_register.js | 73 +- .../item_wise_sales_register.js | 89 +- .../report/payment_ledger/payment_ledger.js | 113 +- .../payment_period_based_on_invoice_date.js | 50 +- .../report/pos_register/pos_register.js | 91 +- .../profit_and_loss_statement.js | 48 +- .../profitability_analysis.js | 123 +- .../purchase_invoice_trends.js | 6 +- .../purchase_register/purchase_register.js | 86 +- .../received_items_to_be_billed.js | 6 +- .../sales_invoice_trends.js | 6 +- .../sales_payment_summary.js | 58 +- .../report/sales_register/sales_register.js | 102 +- .../report/share_balance/share_balance.js | 26 +- .../report/share_ledger/share_ledger.js | 24 +- .../supplier_ledger_summary.js | 102 +- .../accounts/report/tax_detail/tax_detail.js | 432 +- .../tds_computation_summary.js | 82 +- .../tds_payable_monthly.js | 82 +- .../report/trial_balance/trial_balance.js | 152 +- .../trial_balance_for_party.js | 114 +- .../voucher_wise_balance.js | 44 +- erpnext/assets/doctype/asset/asset.js | 711 +- erpnext/assets/doctype/asset/asset_list.js | 26 +- .../asset_capitalization.js | 159 +- .../doctype/asset_category/asset_category.js | 71 +- .../asset_maintenance/asset_maintenance.js | 73 +- .../asset_maintenance_log.js | 10 +- .../asset_maintenance_log_calendar.js | 24 +- .../asset_maintenance_log_list.js | 14 +- .../asset_maintenance_team.js | 6 +- .../doctype/asset_movement/asset_movement.js | 91 +- .../doctype/asset_repair/asset_repair.js | 76 +- .../doctype/asset_repair/asset_repair_list.js | 12 +- .../asset_shift_allocation.js | 10 +- .../asset_shift_factor/asset_shift_factor.js | 3 +- .../asset_value_adjustment.js | 42 +- erpnext/assets/doctype/location/location.js | 15 +- .../assets/doctype/location/location_tree.js | 14 +- .../maintenance_team_member.js | 6 +- .../fixed_asset_register.js | 104 +- .../bulk_transaction_log.js | 30 +- .../buying_settings/buying_settings.js | 23 +- .../purchase_order/purchase_order_list.js | 50 +- erpnext/buying/doctype/supplier/supplier.js | 183 +- .../buying/doctype/supplier/supplier_list.js | 8 +- .../supplier_quotation_list.js | 18 +- .../supplier_scorecard/supplier_scorecard.js | 62 +- .../supplier_scorecard_list.js | 4 +- .../supplier_scorecard_criteria.js | 2 +- .../supplier_scorecard_period.js | 5 +- .../supplier_scorecard_standing.js | 4 +- .../supplier_scorecard_variable.js | 4 +- .../procurement_tracker.js | 8 +- .../purchase_analytics/purchase_analytics.js | 85 +- .../purchase_order_analysis.js | 110 +- .../purchase_order_trends.js | 6 +- .../requested_items_to_order_and_receive.js | 96 +- .../subcontract_order_summary.js | 18 +- .../subcontracted_item_to_be_received.js | 16 +- ...tracted_raw_materials_to_be_transferred.js | 18 +- .../supplier_quotation_comparison.js | 128 +- .../crm/doctype/appointment/appointment.js | 24 +- .../appointment_booking_settings.js | 12 +- erpnext/crm/doctype/campaign/campaign.js | 24 +- erpnext/crm/doctype/competitor/competitor.js | 3 +- erpnext/crm/doctype/contract/contract.js | 12 +- erpnext/crm/doctype/contract/contract_list.js | 2 +- .../contract_fulfilment_checklist.js | 6 +- .../contract_template/contract_template.js | 6 +- .../crm/doctype/crm_settings/crm_settings.js | 3 +- .../doctype/email_campaign/email_campaign.js | 8 +- .../email_campaign/email_campaign_list.js | 12 +- erpnext/crm/doctype/lead/lead.js | 199 +- erpnext/crm/doctype/lead/lead_list.js | 54 +- .../crm/doctype/lead_source/lead_source.js | 3 +- .../linkedin_settings/linkedin_settings.js | 65 +- .../lost_reason_detail/lost_reason_detail.js | 6 +- .../doctype/market_segment/market_segment.js | 6 +- .../doctype/opportunity/opportunity_list.js | 28 +- .../opportunity_lost_reason.js | 6 +- .../opportunity_type/opportunity_type.js | 6 +- erpnext/crm/doctype/prospect/prospect.js | 43 +- .../crm/doctype/sales_stage/sales_stage.js | 6 +- .../social_media_post/social_media_post.js | 93 +- .../social_media_post_list.js | 23 +- .../twitter_settings/twitter_settings.js | 61 +- .../campaign_efficiency.js | 22 +- .../first_response_time_for_opportunity.js | 46 +- .../lead_conversion_time.js | 24 +- .../crm/report/lead_details/lead_details.js | 70 +- .../lead_owner_efficiency.js | 31 +- .../lost_opportunity/lost_opportunity.js | 80 +- .../opportunity_summary_by_sales_stage.js | 27 +- .../prospects_engaged_but_not_converted.js | 30 +- .../sales_pipeline_analytics.js | 24 +- .../e_commerce_settings.js | 51 +- .../doctype/item_review/item_review.js | 3 +- .../doctype/website_item/website_item.js | 42 +- .../doctype/website_item/website_item_list.js | 12 +- .../e_commerce/doctype/wishlist/wishlist.js | 3 +- erpnext/e_commerce/product_ui/grid.js | 59 +- erpnext/e_commerce/product_ui/list.js | 69 +- erpnext/e_commerce/product_ui/search.js | 63 +- erpnext/e_commerce/product_ui/views.js | 208 +- .../gocardless_mandate/gocardless_mandate.js | 3 +- .../gocardless_settings.js | 6 +- .../doctype/mpesa_settings/mpesa_settings.js | 21 +- .../doctype/plaid_settings/plaid_settings.js | 103 +- .../quickbooks_migrator.js | 70 +- .../tally_migration/tally_migration.js | 161 +- .../taxjar_settings/taxjar_settings.js | 20 +- .../woocommerce_settings.js | 44 +- .../top_10_pledged_loan_securities.js | 8 +- .../loan_management/doctype/loan/loan_list.js | 14 +- .../loan_balance_adjustment.js | 3 +- .../doctype/loan_refund/loan_refund.js | 3 +- .../doctype/loan_security/loan_security.js | 3 +- .../loan_security_pledge.js | 33 +- .../loan_security_pledge_list.js | 14 +- .../loan_security_price.js | 3 +- .../loan_security_shortfall.js | 18 +- .../loan_security_type/loan_security_type.js | 3 +- .../loan_security_unpledge.js | 11 +- .../loan_security_unpledge_list.js | 12 +- .../doctype/loan_type/loan_type.js | 26 +- .../loan_management/doctype/pledge/pledge.js | 3 +- .../process_loan_interest_accrual.js | 3 +- .../process_loan_security_shortfall.js | 8 +- .../sanctioned_loan_amount.js | 3 +- erpnext/loan_management/loan_common.js | 47 +- .../applicant_wise_loan_security_exposure.js | 18 +- .../loan_interest_report.js | 62 +- .../loan_repayment_and_closure.js | 51 +- .../loan_security_exposure.js | 18 +- .../loan_security_status.js | 58 +- .../maintenance_schedule.js | 182 +- .../maintenance_visit/maintenance_visit.js | 109 +- .../maintenance_visit_list.js | 20 +- .../doctype/blanket_order/blanket_order.js | 106 +- erpnext/manufacturing/doctype/bom/bom.js | 477 +- erpnext/manufacturing/doctype/bom/bom_list.js | 14 +- erpnext/manufacturing/doctype/bom/bom_tree.js | 47 +- .../doctype/bom_update_log/bom_update_log.js | 3 +- .../bom_update_log/bom_update_log_list.js | 18 +- .../bom_update_tool/bom_update_tool.js | 40 +- .../doctype/downtime_entry/downtime_entry.js | 3 +- .../doctype/job_card/job_card.js | 341 +- .../doctype/job_card/job_card_calendar.js | 42 +- .../doctype/job_card/job_card_list.js | 12 +- .../manufacturing_settings.js | 23 +- .../material_request_plan_item.js | 6 +- .../doctype/operation/operation.js | 24 +- .../production_plan/production_plan.js | 362 +- .../production_plan/production_plan_list.js | 24 +- ...duction_plan_material_request_warehouse.js | 3 +- .../manufacturing/doctype/routing/routing.js | 55 +- .../doctype/sub_operation/sub_operation.js | 3 +- .../doctype/work_order/work_order.js | 793 +- .../doctype/work_order/work_order_calendar.js | 56 +- .../doctype/work_order/work_order_list.js | 40 +- .../doctype/workstation/_test_workstation.js | 16 +- .../doctype/workstation/workstation.js | 41 +- .../doctype/workstation/workstation_list.js | 2 +- .../workstation_type/workstation_type.js | 3 +- .../bom_comparison_tool.js | 185 +- .../report/bom_explorer/bom_explorer.js | 6 +- .../bom_operations_time.js | 52 +- .../bom_stock_calculated.js | 44 +- .../bom_stock_report/bom_stock_report.js | 59 +- .../bom_variance_report.js | 36 +- .../cost_of_poor_quality_report.js | 64 +- .../downtime_analysis/downtime_analysis.js | 18 +- .../exponential_smoothing_forecasting.js | 130 +- .../job_card_summary/job_card_summary.js | 40 +- .../process_loss_report.js | 66 +- .../production_analytics.js | 26 +- .../production_plan_summary.js | 18 +- .../production_planning_report.js | 116 +- .../quality_inspection_summary.js | 18 +- .../work_order_consumed_materials.js | 34 +- .../work_order_stock_report.js | 16 +- .../work_order_summary/work_order_summary.js | 38 +- erpnext/portal/doctype/homepage/homepage.js | 32 +- .../homepage_section/homepage_section.js | 4 +- .../doctype/activity_cost/activity_cost.js | 2 +- .../doctype/activity_type/activity_type.js | 15 +- erpnext/projects/doctype/project/project.js | 188 +- .../projects/doctype/project/project_list.js | 10 +- .../doctype/project/project_timesheet.js | 142 +- .../project_template/project_template.js | 12 +- .../doctype/project_type/project_type.js | 4 +- .../doctype/project_update/project_update.js | 8 +- .../projects_settings/projects_settings.js | 6 +- erpnext/projects/doctype/task/task.js | 39 +- .../projects/doctype/task/task_calendar.js | 26 +- erpnext/projects/doctype/task/task_list.js | 40 +- erpnext/projects/doctype/task/task_tree.js | 70 +- .../projects/doctype/task_type/task_type.js | 3 +- .../projects/doctype/timesheet/timesheet.js | 278 +- .../doctype/timesheet/timesheet_calendar.js | 42 +- .../doctype/timesheet/timesheet_list.js | 18 +- .../daily_timesheet_summary.js | 22 +- .../delayed_tasks_summary.js | 36 +- .../employee_billing_summary.js | 18 +- .../project_billing_summary.js | 20 +- .../report/project_summary/project_summary.js | 54 +- .../project_wise_stock_tracking.js | 6 +- erpnext/projects/web_form/tasks/tasks.js | 4 +- erpnext/public/js/account_tree_grid.js | 193 +- erpnext/public/js/address.js | 27 +- erpnext/public/js/agriculture/ternary_plot.js | 219 +- .../data_table_manager.js | 63 +- .../dialog_manager.js | 103 +- .../bank_reconciliation_tool/number_card.js | 19 +- .../public/js/bulk_transaction_processing.js | 27 +- erpnext/public/js/call_popup/call_popup.js | 232 +- erpnext/public/js/communication.js | 136 +- erpnext/public/js/conf.js | 20 +- erpnext/public/js/contact.js | 8 +- erpnext/public/js/customer_reviews.js | 44 +- erpnext/public/js/erpnext-web.bundle.js | 2 +- erpnext/public/js/event.js | 62 +- erpnext/public/js/financial_statements.js | 261 +- erpnext/public/js/help_links.js | 140 +- .../hierarchy_chart_desktop.js | 334 +- .../hierarchy_chart/hierarchy_chart_mobile.js | 269 +- erpnext/public/js/leaflet/leaflet.draw.js | 1863 ++++- erpnext/public/js/leaflet/leaflet.js | 6379 +++++++++++++++-- erpnext/public/js/newsletter.js | 4 +- erpnext/public/js/payment/payments.js | 224 +- erpnext/public/js/projects/timer.js | 77 +- erpnext/public/js/purchase_trends_filters.js | 98 +- erpnext/public/js/queries.js | 156 +- erpnext/public/js/sales_trends_filters.js | 86 +- erpnext/public/js/setup_wizard.js | 178 +- erpnext/public/js/shopping_cart.js | 127 +- erpnext/public/js/sms_manager.js | 130 +- erpnext/public/js/stock_analytics.js | 162 +- erpnext/public/js/stock_grid_report.js | 53 +- erpnext/public/js/telephony.js | 31 +- erpnext/public/js/utils.js | 990 +-- erpnext/public/js/utils/barcode_scanner.js | 110 +- .../js/utils/contact_address_quick_entry.js | 142 +- erpnext/public/js/utils/crm_activities.js | 155 +- .../public/js/utils/customer_quick_entry.js | 2 +- .../public/js/utils/dimension_tree_filter.js | 62 +- erpnext/public/js/utils/item_quick_entry.js | 288 +- erpnext/public/js/utils/item_selector.js | 63 +- erpnext/public/js/utils/party.js | 201 +- .../js/utils/serial_no_batch_selector.js | 488 +- .../public/js/utils/supplier_quick_entry.js | 2 +- erpnext/public/js/utils/unreconcile.js | 137 +- erpnext/public/js/website_theme.js | 13 +- erpnext/public/js/website_utils.js | 14 +- erpnext/public/js/wishlist.js | 79 +- erpnext/public/scss/erpnext.scss | 72 +- erpnext/public/scss/hierarchy_chart.scss | 19 +- erpnext/public/scss/order-page.scss | 172 +- erpnext/public/scss/point-of-sale.scss | 13 +- erpnext/public/scss/shopping_cart.scss | 110 +- erpnext/public/scss/website.scss | 10 +- .../non_conformance/non_conformance.js | 3 +- .../doctype/quality_action/quality_action.js | 4 +- .../quality_feedback/quality_feedback.js | 8 +- .../quality_feedback_template.js | 3 +- .../doctype/quality_goal/quality_goal.js | 2 +- .../quality_meeting/quality_meeting.js | 4 +- .../quality_meeting/quality_meeting_list.js | 11 +- .../quality_meeting_agenda.js | 3 +- .../quality_procedure/quality_procedure.js | 18 +- .../quality_procedure_tree.js | 20 +- .../doctype/quality_review/quality_review.js | 12 +- .../quality_review/quality_review_list.js | 12 +- .../import_supplier_invoice.js | 29 +- .../ksa_vat_sales_account.js | 3 +- .../ksa_vat_setting/ksa_vat_setting.js | 6 +- .../ksa_vat_setting/ksa_vat_setting_list.js | 10 +- .../lower_deduction_certificate.js | 3 +- .../product_tax_category.js | 3 +- .../south_africa_vat_settings.js | 16 +- .../uae_vat_settings/uae_vat_settings.js | 12 +- .../electronic_invoice_register.js | 58 +- .../fichier_des_ecritures_comptables_[fec].js | 62 +- erpnext/regional/report/irs_1099/irs_1099.js | 53 +- erpnext/regional/report/ksa_vat/ksa_vat.js | 62 +- .../report/uae_vat_201/uae_vat_201.js | 45 +- .../vat_audit_report/vat_audit_report.js | 40 +- erpnext/selling/doctype/customer/customer.js | 236 +- .../selling/doctype/customer/customer_list.js | 2 +- .../doctype/industry_type/industry_type.js | 10 +- .../installation_note/installation_note.js | 49 +- .../party_specific_item.js | 3 +- .../doctype/quotation/quotation_list.js | 33 +- .../sales_order/sales_order_calendar.js | 49 +- .../doctype/sales_order/sales_order_list.js | 65 +- .../sales_partner_type/sales_partner_type.js | 6 +- .../selling_settings/selling_settings.js | 6 +- .../selling/doctype/sms_center/sms_center.js | 4 +- .../page/point_of_sale/point_of_sale.js | 12 +- .../page/point_of_sale/pos_controller.js | 361 +- .../page/point_of_sale/pos_item_cart.js | 645 +- .../page/point_of_sale/pos_item_details.js | 185 +- .../page/point_of_sale/pos_item_selector.js | 202 +- .../page/point_of_sale/pos_number_pad.js | 32 +- .../page/point_of_sale/pos_past_order_list.js | 56 +- .../point_of_sale/pos_past_order_summary.js | 207 +- .../selling/page/point_of_sale/pos_payment.js | 298 +- .../selling/page/sales_funnel/sales_funnel.js | 134 +- .../address_and_contacts.js | 44 +- .../available_stock_for_packing_items.js | 6 +- .../customer_acquisition_and_loyalty.js | 54 +- .../customer_credit_balance.js | 28 +- .../customer_wise_item_price.js | 34 +- .../inactive_customers/inactive_customers.js | 26 +- .../item_wise_sales_history.js | 32 +- .../payment_terms_status_for_sales_order.js | 189 +- .../pending_so_items_for_purchase_request.js | 3 +- .../quotation_trends/quotation_trends.js | 6 +- .../report/sales_analytics/sales_analytics.js | 70 +- .../sales_order_analysis.js | 102 +- .../sales_order_trends/sales_order_trends.js | 6 +- .../sales_partner_commission_summary.js | 24 +- ...ner_target_variance_based_on_item_group.js | 34 +- .../sales_partner_transaction_summary.js | 28 +- .../sales_person_commission_summary.js | 24 +- ...son_target_variance_based_on_item_group.js | 34 +- .../sales_person_wise_transaction_summary.js | 28 +- ...ory_target_variance_based_on_item_group.js | 34 +- .../territory_wise_sales.js | 16 +- .../authorization_rule/authorization_rule.js | 96 +- erpnext/setup/doctype/branch/branch.js | 6 +- erpnext/setup/doctype/brand/brand.js | 106 +- erpnext/setup/doctype/company/company.js | 354 +- erpnext/setup/doctype/company/company_list.js | 4 +- erpnext/setup/doctype/company/company_tree.js | 24 +- .../currency_exchange/currency_exchange.js | 21 +- .../doctype/customer_group/customer_group.js | 39 +- .../customer_group/customer_group_tree.js | 4 +- .../setup/doctype/department/department.js | 16 +- .../doctype/department/department_tree.js | 18 +- .../setup/doctype/designation/designation.js | 6 +- erpnext/setup/doctype/driver/driver.js | 24 +- .../doctype/email_digest/email_digest.js | 24 +- erpnext/setup/doctype/employee/employee.js | 85 +- .../setup/doctype/employee/employee_list.js | 12 +- .../setup/doctype/employee/employee_tree.js | 26 +- .../doctype/employee_group/employee_group.js | 4 +- .../global_defaults/global_defaults.js | 24 +- .../doctype/holiday_list/holiday_list.js | 18 +- .../holiday_list/holiday_list_calendar.js | 24 +- .../setup/doctype/item_group/item_group.js | 123 +- .../doctype/item_group/item_group_tree.js | 4 +- .../setup/doctype/party_type/party_type.js | 18 +- .../doctype/print_heading/print_heading.js | 10 +- .../quotation_lost_reason.js | 10 +- .../doctype/sales_partner/sales_partner.js | 33 +- .../doctype/sales_person/sales_person.js | 72 +- .../doctype/sales_person/sales_person_tree.js | 24 +- .../doctype/supplier_group/supplier_group.js | 26 +- .../supplier_group/supplier_group_tree.js | 2 +- erpnext/setup/doctype/territory/territory.js | 38 +- .../setup/doctype/territory/territory_tree.js | 4 +- .../transaction_deletion_record.js | 33 +- .../transaction_deletion_record_list.js | 6 +- erpnext/setup/doctype/uom/uom.js | 10 +- .../uom_conversion_factor.js | 6 +- erpnext/setup/doctype/vehicle/vehicle.js | 6 +- .../welcome_to_erpnext/welcome_to_erpnext.js | 21 +- erpnext/stock/dashboard/item_dashboard.js | 232 +- .../warehouse_wise_stock_value.js | 8 +- erpnext/stock/doctype/batch/batch.js | 176 +- erpnext/stock/doctype/batch/batch_list.js | 17 +- erpnext/stock/doctype/bin/bin.js | 6 +- .../closing_stock_balance.js | 14 +- .../customs_tariff_number.js | 6 +- .../delivery_note/delivery_note_list.js | 77 +- .../delivery_settings/delivery_settings.js | 6 +- .../doctype/delivery_trip/delivery_trip.js | 166 +- .../delivery_trip/delivery_trip_list.js | 4 +- .../inventory_dimension.js | 77 +- erpnext/stock/doctype/item/item.js | 863 ++- erpnext/stock/doctype/item/item_list.js | 30 +- .../item_alternative/item_alternative.js | 10 +- .../doctype/item_attribute/item_attribute.js | 4 +- .../item_manufacturer/item_manufacturer.js | 3 +- .../stock/doctype/item_price/item_price.js | 21 +- .../doctype/item_price/item_price_list.js | 2 +- .../item_variant_settings.js | 43 +- .../doctype/manufacturer/manufacturer.js | 15 +- .../material_request/material_request_list.js | 20 +- .../doctype/packing_slip/packing_slip.js | 52 +- erpnext/stock/doctype/pick_list/pick_list.js | 228 +- .../stock/doctype/pick_list/pick_list_list.js | 12 +- .../stock/doctype/price_list/price_list.js | 20 +- .../purchase_receipt/purchase_receipt_list.js | 27 +- .../doctype/putaway_rule/putaway_rule.js | 32 +- .../doctype/putaway_rule/putaway_rule_list.js | 12 +- .../quality_inspection/quality_inspection.js | 57 +- .../quality_inspection_parameter.js | 3 +- .../quality_inspection_parameter_group.js | 3 +- .../quality_inspection_template.js | 6 +- .../quick_stock_balance.js | 63 +- .../repost_item_valuation.js | 94 +- erpnext/stock/doctype/serial_no/serial_no.js | 20 +- .../stock/doctype/serial_no/serial_no_list.js | 15 +- erpnext/stock/doctype/shipment/shipment.js | 447 +- .../stock/doctype/shipment/shipment_list.js | 8 +- .../shipment_parcel_template.js | 3 +- .../doctype/stock_entry/stock_entry_list.js | 57 +- .../stock_entry_type/stock_entry_type.js | 3 +- .../stock_ledger_entry/stock_ledger_entry.js | 8 +- .../stock_reconciliation.js | 224 +- .../stock_reposting_settings.js | 22 +- .../doctype/stock_settings/stock_settings.js | 24 +- .../doctype/uom_category/uom_category.js | 6 +- .../doctype/variant_field/variant_field.js | 6 +- erpnext/stock/doctype/warehouse/warehouse.js | 30 +- .../stock/doctype/warehouse/warehouse_tree.js | 35 +- .../doctype/warehouse_type/warehouse_type.js | 3 +- .../stock/landed_taxes_and_charges_common.js | 53 +- .../stock/page/stock_balance/stock_balance.js | 98 +- .../warehouse_capacity_summary.js | 110 +- .../batch_item_expiry_status.js | 50 +- .../batch_wise_balance_history.js | 105 +- erpnext/stock/report/bom_search/bom_search.js | 16 +- .../cogs_by_item_group/cogs_by_item_group.js | 47 +- .../delayed_item_report.js | 28 +- .../delayed_order_report.js | 28 +- .../delivery_note_trends.js | 6 +- ...eue_vs_qty_after_transaction_comparison.js | 55 +- ...incorrect_balance_qty_after_transaction.js | 22 +- .../incorrect_serial_no_valuation.js | 40 +- .../incorrect_stock_value_report.js | 46 +- .../item_price_stock/item_price_stock.js | 16 +- .../stock/report/item_prices/item_prices.js | 22 +- .../item_shortage_report.js | 34 +- .../item_variant_details.js | 14 +- .../itemwise_recommended_reorder_level.js | 42 +- .../product_bundle_balance.js | 64 +- .../purchase_receipt_trends.js | 6 +- .../serial_no_ledger/serial_no_ledger.js | 62 +- .../stock/report/stock_ageing/stock_ageing.js | 98 +- .../report/stock_analytics/stock_analytics.js | 85 +- .../stock_and_account_value_comparison.js | 55 +- .../report/stock_balance/stock_balance.js | 141 +- .../stock/report/stock_ledger/stock_ledger.js | 133 +- .../stock_ledger_invariant_check.js | 70 +- .../stock_ledger_variance.js | 79 +- .../stock_projected_qty.js | 76 +- .../stock_qty_vs_serial_no_count.js | 39 +- .../supplier_wise_sales_analytics.js | 36 +- .../total_stock_summary.js | 36 +- ...rehouse_wise_item_balance_age_and_value.js | 92 +- .../warehouse_wise_stock_balance.js | 33 +- .../subcontracting_order_list.js | 14 +- .../subcontracting_receipt_list.js | 10 +- erpnext/support/doctype/issue/issue.js | 108 +- erpnext/support/doctype/issue/issue_list.js | 34 +- .../doctype/issue_priority/issue_priority.js | 3 +- .../support/doctype/issue_type/issue_type.js | 6 +- .../service_level_agreement.js | 142 +- .../support_settings/support_settings.js | 6 +- .../doctype/warranty_claim/warranty_claim.js | 5 +- .../warranty_claim/warranty_claim_list.js | 4 +- .../first_response_time_for_issues.js | 50 +- .../report/issue_analytics/issue_analytics.js | 85 +- .../report/issue_summary/issue_summary.js | 38 +- .../support_hour_distribution.js | 28 +- erpnext/support/web_form/issues/issues.js | 4 +- .../telephony/doctype/call_log/call_log.js | 16 +- .../incoming_call_settings.js | 28 +- .../telephony_call_type.js | 3 +- .../voice_call_settings.js | 3 +- .../generators/item/item_configure.js | 236 +- .../templates/generators/item/item_inquiry.js | 88 +- erpnext/templates/pages/cart.js | 137 +- erpnext/templates/pages/projects.js | 123 +- .../doctype/rename_tool/rename_tool.js | 21 +- erpnext/utilities/doctype/sms_log/sms_log.js | 6 +- erpnext/utilities/doctype/video/video.js | 6 +- erpnext/utilities/doctype/video/video_list.js | 8 +- .../doctype/video_settings/video_settings.js | 3 +- .../youtube_interactions.js | 8 +- .../utilities/web_form/addresses/addresses.js | 4 +- erpnext/www/all-products/index.js | 4 +- erpnext/www/book_appointment/index.js | 393 +- erpnext/www/shop-by-category/index.js | 6 +- 605 files changed, 27457 insertions(+), 18955 deletions(-) diff --git a/commitlint.config.js b/commitlint.config.js index 8847564e53c4..567020922147 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -1,25 +1,13 @@ module.exports = { - parserPreset: 'conventional-changelog-conventionalcommits', + parserPreset: "conventional-changelog-conventionalcommits", rules: { - 'subject-empty': [2, 'never'], - 'type-case': [2, 'always', 'lower-case'], - 'type-empty': [2, 'never'], - 'type-enum': [ + "subject-empty": [2, "never"], + "type-case": [2, "always", "lower-case"], + "type-empty": [2, "never"], + "type-enum": [ 2, - 'always', - [ - 'build', - 'chore', - 'ci', - 'docs', - 'feat', - 'fix', - 'perf', - 'refactor', - 'revert', - 'style', - 'test', - ], + "always", + ["build", "chore", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "style", "test"], ], }, }; diff --git a/erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.js b/erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.js index d8a83e53dc03..09846114ea24 100644 --- a/erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.js +++ b/erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.js @@ -1,4 +1,4 @@ -frappe.provide('frappe.dashboards.chart_sources'); +frappe.provide("frappe.dashboards.chart_sources"); frappe.dashboards.chart_sources["Account Balance Timeline"] = { method: "erpnext.accounts.dashboard_chart_source.account_balance_timeline.account_balance_timeline.get", @@ -9,14 +9,14 @@ frappe.dashboards.chart_sources["Account Balance Timeline"] = { fieldtype: "Link", options: "Company", default: frappe.defaults.get_user_default("Company"), - reqd: 1 + reqd: 1, }, { fieldname: "account", label: __("Account"), fieldtype: "Link", options: "Account", - reqd: 1 + reqd: 1, }, - ] + ], }; diff --git a/erpnext/accounts/doctype/account/account.js b/erpnext/accounts/doctype/account/account.js index 7d63b257faff..f26d1f82797a 100644 --- a/erpnext/accounts/doctype/account/account.js +++ b/erpnext/accounts/doctype/account/account.js @@ -1,33 +1,32 @@ // Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -frappe.ui.form.on('Account', { - setup: function(frm) { - frm.add_fetch('parent_account', 'report_type', 'report_type'); - frm.add_fetch('parent_account', 'root_type', 'root_type'); +frappe.ui.form.on("Account", { + setup: function (frm) { + frm.add_fetch("parent_account", "report_type", "report_type"); + frm.add_fetch("parent_account", "root_type", "root_type"); }, - onload: function(frm) { - frm.set_query('parent_account', function(doc) { + onload: function (frm) { + frm.set_query("parent_account", function (doc) { return { filters: { - "is_group": 1, - "company": doc.company - } + is_group: 1, + company: doc.company, + }, }; }); }, - refresh: function(frm) { - frm.toggle_display('account_name', frm.is_new()); + refresh: function (frm) { + frm.toggle_display("account_name", frm.is_new()); // hide fields if group - frm.toggle_display(['account_type', 'tax_rate'], cint(frm.doc.is_group) == 0); + frm.toggle_display(["account_type", "tax_rate"], cint(frm.doc.is_group) == 0); // disable fields - frm.toggle_enable(['is_group', 'company'], false); + frm.toggle_enable(["is_group", "company"], false); if (cint(frm.doc.is_group) == 0) { - frm.toggle_display('freeze_account', frm.doc.__onload - && frm.doc.__onload.can_freeze_account); + frm.toggle_display("freeze_account", frm.doc.__onload && frm.doc.__onload.can_freeze_account); } // read-only for root accounts @@ -38,79 +37,101 @@ frappe.ui.form.on('Account', { } else { // credit days and type if customer or supplier frm.set_intro(null); - frm.trigger('account_type'); + frm.trigger("account_type"); // show / hide convert buttons - frm.trigger('add_toolbar_buttons'); + frm.trigger("add_toolbar_buttons"); } - if (frm.has_perm('write')) { - frm.add_custom_button(__('Merge Account'), function () { - frm.trigger("merge_account"); - }, __('Actions')); - frm.add_custom_button(__('Update Account Name / Number'), function () { - frm.trigger("update_account_number"); - }, __('Actions')); + if (frm.has_perm("write")) { + frm.add_custom_button( + __("Merge Account"), + function () { + frm.trigger("merge_account"); + }, + __("Actions") + ); + frm.add_custom_button( + __("Update Account Name / Number"), + function () { + frm.trigger("update_account_number"); + }, + __("Actions") + ); } } }, account_type: function (frm) { if (frm.doc.is_group == 0) { - frm.toggle_display(['tax_rate'], frm.doc.account_type == 'Tax'); - frm.toggle_display('warehouse', frm.doc.account_type == 'Stock'); + frm.toggle_display(["tax_rate"], frm.doc.account_type == "Tax"); + frm.toggle_display("warehouse", frm.doc.account_type == "Stock"); } }, - add_toolbar_buttons: function(frm) { - frm.add_custom_button(__('Chart of Accounts'), () => { - frappe.set_route("Tree", "Account"); - }, __('View')); + add_toolbar_buttons: function (frm) { + frm.add_custom_button( + __("Chart of Accounts"), + () => { + frappe.set_route("Tree", "Account"); + }, + __("View") + ); if (frm.doc.is_group == 1) { - frm.add_custom_button(__('Convert to Non-Group'), function () { - return frappe.call({ - doc: frm.doc, - method: 'convert_group_to_ledger', - callback: function() { - frm.refresh(); - } - }); - }, __('Actions')); - - } else if (cint(frm.doc.is_group) == 0 - && frappe.boot.user.can_read.indexOf("GL Entry") !== -1) { - frm.add_custom_button(__('General Ledger'), function () { - frappe.route_options = { - "account": frm.doc.name, - "from_date": frappe.sys_defaults.year_start_date, - "to_date": frappe.sys_defaults.year_end_date, - "company": frm.doc.company - }; - frappe.set_route("query-report", "General Ledger"); - }, __('View')); + frm.add_custom_button( + __("Convert to Non-Group"), + function () { + return frappe.call({ + doc: frm.doc, + method: "convert_group_to_ledger", + callback: function () { + frm.refresh(); + }, + }); + }, + __("Actions") + ); + } else if (cint(frm.doc.is_group) == 0 && frappe.boot.user.can_read.indexOf("GL Entry") !== -1) { + frm.add_custom_button( + __("General Ledger"), + function () { + frappe.route_options = { + account: frm.doc.name, + from_date: frappe.sys_defaults.year_start_date, + to_date: frappe.sys_defaults.year_end_date, + company: frm.doc.company, + }; + frappe.set_route("query-report", "General Ledger"); + }, + __("View") + ); - frm.add_custom_button(__('Convert to Group'), function () { - return frappe.call({ - doc: frm.doc, - method: 'convert_ledger_to_group', - callback: function() { - frm.refresh(); - } - }); - }, __('Actions')); + frm.add_custom_button( + __("Convert to Group"), + function () { + return frappe.call({ + doc: frm.doc, + method: "convert_ledger_to_group", + callback: function () { + frm.refresh(); + }, + }); + }, + __("Actions") + ); } }, - merge_account: function(frm) { + merge_account: function (frm) { var d = new frappe.ui.Dialog({ - title: __('Merge with Existing Account'), + title: __("Merge with Existing Account"), fields: [ { - "label" : "Name", - "fieldname": "name", - "fieldtype": "Data", - "reqd": 1, - "default": frm.doc.name - } + label: "Name", + fieldname: "name", + fieldtype: "Data", + reqd: 1, + default: frm.doc.name, + }, ], - primary_action: function() { + primary_action: function () { var data = d.get_values(); frappe.call({ method: "erpnext.accounts.doctype.account.account.merge_account", @@ -118,42 +139,45 @@ frappe.ui.form.on('Account', { old: frm.doc.name, new: data.name, }, - callback: function(r) { - if(!r.exc) { - if(r.message) { + callback: function (r) { + if (!r.exc) { + if (r.message) { frappe.set_route("Form", "Account", r.message); } d.hide(); } - } + }, }); }, - primary_action_label: __('Merge') + primary_action_label: __("Merge"), }); d.show(); }, - update_account_number: function(frm) { + update_account_number: function (frm) { var d = new frappe.ui.Dialog({ - title: __('Update Account Number / Name'), + title: __("Update Account Number / Name"), fields: [ { - "label": "Account Name", - "fieldname": "account_name", - "fieldtype": "Data", - "reqd": 1, - "default": frm.doc.account_name + label: "Account Name", + fieldname: "account_name", + fieldtype: "Data", + reqd: 1, + default: frm.doc.account_name, }, { - "label": "Account Number", - "fieldname": "account_number", - "fieldtype": "Data", - "default": frm.doc.account_number - } + label: "Account Number", + fieldname: "account_number", + fieldtype: "Data", + default: frm.doc.account_number, + }, ], - primary_action: function() { + primary_action: function () { var data = d.get_values(); - if(data.account_number === frm.doc.account_number && data.account_name === frm.doc.account_name) { + if ( + data.account_number === frm.doc.account_number && + data.account_name === frm.doc.account_name + ) { d.hide(); return; } @@ -163,11 +187,11 @@ frappe.ui.form.on('Account', { args: { account_number: data.account_number, account_name: data.account_name, - name: frm.doc.name + name: frm.doc.name, }, - callback: function(r) { - if(!r.exc) { - if(r.message) { + callback: function (r) { + if (!r.exc) { + if (r.message) { frappe.set_route("Form", "Account", r.message); } else { frm.set_value("account_number", data.account_number); @@ -175,11 +199,11 @@ frappe.ui.form.on('Account', { } d.hide(); } - } + }, }); }, - primary_action_label: __('Update') + primary_action_label: __("Update"), }); d.show(); - } + }, }); diff --git a/erpnext/accounts/doctype/account/account_tree.js b/erpnext/accounts/doctype/account/account_tree.js index d537adfcbfdc..e0bfa6e902a2 100644 --- a/erpnext/accounts/doctype/account/account_tree.js +++ b/erpnext/accounts/doctype/account/account_tree.js @@ -1,4 +1,4 @@ -frappe.provide("frappe.treeview_settings") +frappe.provide("frappe.treeview_settings"); frappe.treeview_settings["Account"] = { breadcrumb: "Accounts", @@ -7,12 +7,12 @@ frappe.treeview_settings["Account"] = { filters: [ { fieldname: "company", - fieldtype:"Select", + fieldtype: "Select", options: erpnext.utils.get_tree_options("company"), label: __("Company"), default: erpnext.utils.get_tree_default("company"), - on_change: function() { - var me = frappe.treeview_settings['Account'].treeview; + on_change: function () { + var me = frappe.treeview_settings["Account"].treeview; var company = me.page.fields_dict.company.get_value(); if (!company) { frappe.throw(__("Please set a Company")); @@ -22,30 +22,36 @@ frappe.treeview_settings["Account"] = { args: { company: company, }, - callback: function(r) { - if(r.message) { + callback: function (r) { + if (r.message) { let root_company = r.message.length ? r.message[0] : ""; me.page.fields_dict.root_company.set_value(root_company); - frappe.db.get_value("Company", {"name": company}, "allow_account_creation_against_child_company", (r) => { - frappe.flags.ignore_root_company_validation = r.allow_account_creation_against_child_company; - }); + frappe.db.get_value( + "Company", + { name: company }, + "allow_account_creation_against_child_company", + (r) => { + frappe.flags.ignore_root_company_validation = + r.allow_account_creation_against_child_company; + } + ); } - } + }, }); - } + }, }, { fieldname: "root_company", - fieldtype:"Data", + fieldtype: "Data", label: __("Root Company"), hidden: true, - disable_onchange: true - } + disable_onchange: true, + }, ], root_label: "Accounts", - get_tree_nodes: 'erpnext.accounts.utils.get_children', - on_get_node: function(nodes, deep=false) { + get_tree_nodes: "erpnext.accounts.utils.get_children", + on_get_node: function (nodes, deep = false) { if (frappe.boot.user.can_read.indexOf("GL Entry") == -1) return; let accounts = []; @@ -57,151 +63,231 @@ frappe.treeview_settings["Account"] = { } frappe.db.get_single_value("Accounts Settings", "show_balance_in_coa").then((value) => { - if(value) { - + if (value) { const get_balances = frappe.call({ - method: 'erpnext.accounts.utils.get_account_balances', + method: "erpnext.accounts.utils.get_account_balances", args: { accounts: accounts, - company: cur_tree.args.company + company: cur_tree.args.company, }, }); - get_balances.then(r => { + get_balances.then((r) => { if (!r.message || r.message.length == 0) return; for (let account of r.message) { - const node = cur_tree.nodes && cur_tree.nodes[account.value]; if (!node || node.is_root) continue; // show Dr if positive since balance is calculated as debit - credit else show Cr const balance = account.balance_in_account_currency || account.balance; - const dr_or_cr = balance > 0 ? "Dr": "Cr"; + const dr_or_cr = balance > 0 ? "Dr" : "Cr"; const format = (value, currency) => format_currency(Math.abs(value), currency); - if (account.balance!==undefined) { - node.parent && node.parent.find('.balance-area').remove(); - $('' - + (account.balance_in_account_currency ? - (format(account.balance_in_account_currency, account.account_currency) + " / ") : "") - + format(account.balance, account.company_currency) - + " " + dr_or_cr - + '').insertBefore(node.$ul); + if (account.balance !== undefined) { + node.parent && node.parent.find(".balance-area").remove(); + $( + '' + + (account.balance_in_account_currency + ? format( + account.balance_in_account_currency, + account.account_currency + ) + " / " + : "") + + format(account.balance, account.company_currency) + + " " + + dr_or_cr + + "" + ).insertBefore(node.$ul); } } }); } }); }, - add_tree_node: 'erpnext.accounts.utils.add_ac', - menu_items:[ + add_tree_node: "erpnext.accounts.utils.add_ac", + menu_items: [ { - label: __('New Company'), - action: function() { frappe.new_doc("Company", true) }, - condition: 'frappe.boot.user.can_create.indexOf("Company") !== -1' - } + label: __("New Company"), + action: function () { + frappe.new_doc("Company", true); + }, + condition: 'frappe.boot.user.can_create.indexOf("Company") !== -1', + }, ], fields: [ - {fieldtype:'Data', fieldname:'account_name', label:__('New Account Name'), reqd:true, - description: __("Name of new Account. Note: Please don't create accounts for Customers and Suppliers")}, - {fieldtype:'Data', fieldname:'account_number', label:__('Account Number'), - description: __("Number of new Account, it will be included in the account name as a prefix")}, - {fieldtype:'Check', fieldname:'is_group', label:__('Is Group'), - description: __('Further accounts can be made under Groups, but entries can be made against non-Groups')}, - {fieldtype:'Select', fieldname:'root_type', label:__('Root Type'), - options: ['Asset', 'Liability', 'Equity', 'Income', 'Expense'].join('\n'), - depends_on: 'eval:doc.is_group && !doc.parent_account'}, - {fieldtype:'Select', fieldname:'account_type', label:__('Account Type'), - options: frappe.get_meta("Account").fields.filter(d => d.fieldname=='account_type')[0].options, - description: __("Optional. This setting will be used to filter in various transactions.") + { + fieldtype: "Data", + fieldname: "account_name", + label: __("New Account Name"), + reqd: true, + description: __( + "Name of new Account. Note: Please don't create accounts for Customers and Suppliers" + ), + }, + { + fieldtype: "Data", + fieldname: "account_number", + label: __("Account Number"), + description: __("Number of new Account, it will be included in the account name as a prefix"), + }, + { + fieldtype: "Check", + fieldname: "is_group", + label: __("Is Group"), + description: __( + "Further accounts can be made under Groups, but entries can be made against non-Groups" + ), + }, + { + fieldtype: "Select", + fieldname: "root_type", + label: __("Root Type"), + options: ["Asset", "Liability", "Equity", "Income", "Expense"].join("\n"), + depends_on: "eval:doc.is_group && !doc.parent_account", + }, + { + fieldtype: "Select", + fieldname: "account_type", + label: __("Account Type"), + options: frappe.get_meta("Account").fields.filter((d) => d.fieldname == "account_type")[0] + .options, + description: __("Optional. This setting will be used to filter in various transactions."), + }, + { + fieldtype: "Float", + fieldname: "tax_rate", + label: __("Tax Rate"), + depends_on: 'eval:doc.is_group==0&&doc.account_type=="Tax"', + }, + { + fieldtype: "Link", + fieldname: "account_currency", + label: __("Currency"), + options: "Currency", + description: __("Optional. Sets company's default currency, if not specified."), }, - {fieldtype:'Float', fieldname:'tax_rate', label:__('Tax Rate'), - depends_on: 'eval:doc.is_group==0&&doc.account_type=="Tax"'}, - {fieldtype:'Link', fieldname:'account_currency', label:__('Currency'), options:"Currency", - description: __("Optional. Sets company's default currency, if not specified.")} ], - ignore_fields:["parent_account"], - onload: function(treeview) { - frappe.treeview_settings['Account'].treeview = {}; - $.extend(frappe.treeview_settings['Account'].treeview, treeview); + ignore_fields: ["parent_account"], + onload: function (treeview) { + frappe.treeview_settings["Account"].treeview = {}; + $.extend(frappe.treeview_settings["Account"].treeview, treeview); function get_company() { return treeview.page.fields_dict.company.get_value(); } // tools - treeview.page.add_inner_button(__("Chart of Cost Centers"), function() { - frappe.set_route('Tree', 'Cost Center', {company: get_company()}); - }, __('View')); - - treeview.page.add_inner_button(__("Opening Invoice Creation Tool"), function() { - frappe.set_route('Form', 'Opening Invoice Creation Tool', {company: get_company()}); - }, __('View')); + treeview.page.add_inner_button( + __("Chart of Cost Centers"), + function () { + frappe.set_route("Tree", "Cost Center", { company: get_company() }); + }, + __("View") + ); - treeview.page.add_inner_button(__("Period Closing Voucher"), function() { - frappe.set_route('List', 'Period Closing Voucher', {company: get_company()}); - }, __('View')); + treeview.page.add_inner_button( + __("Opening Invoice Creation Tool"), + function () { + frappe.set_route("Form", "Opening Invoice Creation Tool", { company: get_company() }); + }, + __("View") + ); + treeview.page.add_inner_button( + __("Period Closing Voucher"), + function () { + frappe.set_route("List", "Period Closing Voucher", { company: get_company() }); + }, + __("View") + ); - treeview.page.add_inner_button(__("Journal Entry"), function() { - frappe.new_doc('Journal Entry', {company: get_company()}); - }, __('Create')); - treeview.page.add_inner_button(__("Company"), function() { - frappe.new_doc('Company'); - }, __('Create')); + treeview.page.add_inner_button( + __("Journal Entry"), + function () { + frappe.new_doc("Journal Entry", { company: get_company() }); + }, + __("Create") + ); + treeview.page.add_inner_button( + __("Company"), + function () { + frappe.new_doc("Company"); + }, + __("Create") + ); // financial statements - for (let report of ['Trial Balance', 'General Ledger', 'Balance Sheet', - 'Profit and Loss Statement', 'Cash Flow Statement', 'Accounts Payable', 'Accounts Receivable']) { - treeview.page.add_inner_button(__(report), function() { - frappe.set_route('query-report', report, {company: get_company()}); - }, __('Financial Statements')); + for (let report of [ + "Trial Balance", + "General Ledger", + "Balance Sheet", + "Profit and Loss Statement", + "Cash Flow Statement", + "Accounts Payable", + "Accounts Receivable", + ]) { + treeview.page.add_inner_button( + __(report), + function () { + frappe.set_route("query-report", report, { company: get_company() }); + }, + __("Financial Statements") + ); } - }, - post_render: function(treeview) { - frappe.treeview_settings['Account'].treeview["tree"] = treeview.tree; - treeview.page.set_primary_action(__("New"), function() { - let root_company = treeview.page.fields_dict.root_company.get_value(); + post_render: function (treeview) { + frappe.treeview_settings["Account"].treeview["tree"] = treeview.tree; + treeview.page.set_primary_action( + __("New"), + function () { + let root_company = treeview.page.fields_dict.root_company.get_value(); - if(root_company) { - frappe.throw(__("Please add the account to root level Company - {0}"), [root_company]); - } else { - treeview.new_node(); - } - }, "add"); + if (root_company) { + frappe.throw(__("Please add the account to root level Company - {0}"), [root_company]); + } else { + treeview.new_node(); + } + }, + "add" + ); }, toolbar: [ { - label:__("Add Child"), - condition: function(node) { - return frappe.boot.user.can_create.indexOf("Account") !== -1 - && (!frappe.treeview_settings['Account'].treeview.page.fields_dict.root_company.get_value() - || frappe.flags.ignore_root_company_validation) - && node.expandable && !node.hide_add; + label: __("Add Child"), + condition: function (node) { + return ( + frappe.boot.user.can_create.indexOf("Account") !== -1 && + (!frappe.treeview_settings[ + "Account" + ].treeview.page.fields_dict.root_company.get_value() || + frappe.flags.ignore_root_company_validation) && + node.expandable && + !node.hide_add + ); }, - click: function() { - var me = frappe.views.trees['Account']; + click: function () { + var me = frappe.views.trees["Account"]; me.new_node(); }, - btnClass: "hidden-xs" + btnClass: "hidden-xs", }, { - condition: function(node) { - return !node.root && frappe.boot.user.can_read.indexOf("GL Entry") !== -1 + condition: function (node) { + return !node.root && frappe.boot.user.can_read.indexOf("GL Entry") !== -1; }, label: __("View Ledger"), - click: function(node, btn) { + click: function (node, btn) { frappe.route_options = { - "account": node.label, - "from_date": frappe.sys_defaults.year_start_date, - "to_date": frappe.sys_defaults.year_end_date, - "company": frappe.treeview_settings['Account'].treeview.page.fields_dict.company.get_value() + account: node.label, + from_date: frappe.sys_defaults.year_start_date, + to_date: frappe.sys_defaults.year_end_date, + company: + frappe.treeview_settings["Account"].treeview.page.fields_dict.company.get_value(), }; frappe.set_route("query-report", "General Ledger"); }, - btnClass: "hidden-xs" - } + btnClass: "hidden-xs", + }, ], - extend_toolbar: true -} + extend_toolbar: true, +}; diff --git a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.js b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.js index 2f53f7b640d8..cd883e5bf72e 100644 --- a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.js +++ b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.js @@ -1,74 +1,86 @@ // Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Accounting Dimension', { - refresh: function(frm) { - frm.set_query('document_type', () => { +frappe.ui.form.on("Accounting Dimension", { + refresh: function (frm) { + frm.set_query("document_type", () => { let invalid_doctypes = frappe.model.core_doctypes_list; - invalid_doctypes.push('Accounting Dimension', 'Project', - 'Cost Center', 'Accounting Dimension Detail', 'Company'); + invalid_doctypes.push( + "Accounting Dimension", + "Project", + "Cost Center", + "Accounting Dimension Detail", + "Company" + ); return { filters: { - name: ['not in', invalid_doctypes] - } + name: ["not in", invalid_doctypes], + }, }; }); - frm.set_query("offsetting_account", "dimension_defaults", function(doc, cdt, cdn) { + frm.set_query("offsetting_account", "dimension_defaults", function (doc, cdt, cdn) { let d = locals[cdt][cdn]; return { filters: { company: d.company, root_type: ["in", ["Asset", "Liability"]], - is_group: 0 - } - } + is_group: 0, + }, + }; }); if (!frm.is_new()) { - frm.add_custom_button(__('Show {0}', [frm.doc.document_type]), function () { + frm.add_custom_button(__("Show {0}", [frm.doc.document_type]), function () { frappe.set_route("List", frm.doc.document_type); }); let button = frm.doc.disabled ? "Enable" : "Disable"; - frm.add_custom_button(__(button), function() { - - frm.set_value('disabled', 1 - frm.doc.disabled); + frm.add_custom_button(__(button), function () { + frm.set_value("disabled", 1 - frm.doc.disabled); frappe.call({ method: "erpnext.accounts.doctype.accounting_dimension.accounting_dimension.disable_dimension", args: { - doc: frm.doc + doc: frm.doc, }, freeze: true, - callback: function(r) { + callback: function (r) { let message = frm.doc.disabled ? "Dimension Disabled" : "Dimension Enabled"; frm.save(); - frappe.show_alert({message:__(message), indicator:'green'}); - } + frappe.show_alert({ message: __(message), indicator: "green" }); + }, }); }); } }, - document_type: function(frm) { - - frm.set_value('label', frm.doc.document_type); - frm.set_value('fieldname', frappe.model.scrub(frm.doc.document_type)); + document_type: function (frm) { + frm.set_value("label", frm.doc.document_type); + frm.set_value("fieldname", frappe.model.scrub(frm.doc.document_type)); - frappe.db.get_value('Accounting Dimension', {'document_type': frm.doc.document_type}, 'document_type', (r) => { - if (r && r.document_type) { - frm.set_df_property('document_type', 'description', "Document type is already set as dimension"); + frappe.db.get_value( + "Accounting Dimension", + { document_type: frm.doc.document_type }, + "document_type", + (r) => { + if (r && r.document_type) { + frm.set_df_property( + "document_type", + "description", + "Document type is already set as dimension" + ); + } } - }); + ); }, }); -frappe.ui.form.on('Accounting Dimension Detail', { - dimension_defaults_add: function(frm, cdt, cdn) { +frappe.ui.form.on("Accounting Dimension Detail", { + dimension_defaults_add: function (frm, cdt, cdn) { let row = locals[cdt][cdn]; row.reference_document = frm.doc.document_type; - } + }, }); diff --git a/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.js b/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.js index 8a6b021b8ad4..7f655967b8ed 100644 --- a/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.js +++ b/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.js @@ -1,10 +1,9 @@ // Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Accounting Dimension Filter', { - refresh: function(frm, cdt, cdn) { - let help_content = - ` +frappe.ui.form.on("Accounting Dimension Filter", { + refresh: function (frm, cdt, cdn) { + let help_content = `

@@ -13,67 +12,70 @@ frappe.ui.form.on('Accounting Dimension Filter', {

`; - frm.set_df_property('dimension_filter_help', 'options', help_content); + frm.set_df_property("dimension_filter_help", "options", help_content); }, - onload: function(frm) { - frm.set_query('applicable_on_account', 'accounts', function() { + onload: function (frm) { + frm.set_query("applicable_on_account", "accounts", function () { return { filters: { - 'company': frm.doc.company - } + company: frm.doc.company, + }, }; }); - frappe.db.get_list('Accounting Dimension', - {fields: ['document_type']}).then((res) => { - let options = ['Cost Center', 'Project']; + frappe.db.get_list("Accounting Dimension", { fields: ["document_type"] }).then((res) => { + let options = ["Cost Center", "Project"]; res.forEach((dimension) => { options.push(dimension.document_type); }); - frm.set_df_property('accounting_dimension', 'options', options); + frm.set_df_property("accounting_dimension", "options", options); }); - frm.trigger('setup_filters'); + frm.trigger("setup_filters"); }, - setup_filters: function(frm) { + setup_filters: function (frm) { let filters = {}; if (frm.doc.accounting_dimension) { - frappe.model.with_doctype(frm.doc.accounting_dimension, function() { + frappe.model.with_doctype(frm.doc.accounting_dimension, function () { if (frappe.model.is_tree(frm.doc.accounting_dimension)) { - filters['is_group'] = 0; + filters["is_group"] = 0; } - if (frappe.meta.has_field(frm.doc.accounting_dimension, 'company')) { - filters['company'] = frm.doc.company; + if (frappe.meta.has_field(frm.doc.accounting_dimension, "company")) { + filters["company"] = frm.doc.company; } - frm.set_query('dimension_value', 'dimensions', function() { + frm.set_query("dimension_value", "dimensions", function () { return { - filters: filters + filters: filters, }; }); }); } }, - accounting_dimension: function(frm) { + accounting_dimension: function (frm) { frm.clear_table("dimensions"); let row = frm.add_child("dimensions"); row.accounting_dimension = frm.doc.accounting_dimension; - frm.fields_dict["dimensions"].grid.update_docfield_property("dimension_value", "label", frm.doc.accounting_dimension); + frm.fields_dict["dimensions"].grid.update_docfield_property( + "dimension_value", + "label", + frm.doc.accounting_dimension + ); frm.refresh_field("dimensions"); - frm.trigger('setup_filters'); + frm.trigger("setup_filters"); }, }); -frappe.ui.form.on('Allowed Dimension', { - dimensions_add: function(frm, cdt, cdn) { +frappe.ui.form.on("Allowed Dimension", { + dimensions_add: function (frm, cdt, cdn) { let row = locals[cdt][cdn]; row.accounting_dimension = frm.doc.accounting_dimension; frm.refresh_field("dimensions"); - } + }, }); diff --git a/erpnext/accounts/doctype/accounting_period/accounting_period.js b/erpnext/accounts/doctype/accounting_period/accounting_period.js index f17b6f9c6954..441471f8c06b 100644 --- a/erpnext/accounts/doctype/accounting_period/accounting_period.js +++ b/erpnext/accounts/doctype/accounting_period/accounting_period.js @@ -1,30 +1,33 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Accounting Period', { - onload: function(frm) { - if(frm.doc.closed_documents.length === 0 || (frm.doc.closed_documents.length === 1 && frm.doc.closed_documents[0].document_type == undefined)) { +frappe.ui.form.on("Accounting Period", { + onload: function (frm) { + if ( + frm.doc.closed_documents.length === 0 || + (frm.doc.closed_documents.length === 1 && frm.doc.closed_documents[0].document_type == undefined) + ) { frappe.call({ method: "get_doctypes_for_closing", - doc:frm.doc, - callback: function(r) { - if(r.message) { + doc: frm.doc, + callback: function (r) { + if (r.message) { cur_frm.clear_table("closed_documents"); - r.message.forEach(function(element) { + r.message.forEach(function (element) { var c = frm.add_child("closed_documents"); c.document_type = element.document_type; c.closed = element.closed; }); refresh_field("closed_documents"); } - } + }, }); } frm.set_query("document_type", "closed_documents", () => { return { query: "erpnext.controllers.queries.get_doctypes_for_closing", - } + }; }); - } + }, }); diff --git a/erpnext/accounts/doctype/accounts_settings/accounts_settings.js b/erpnext/accounts/doctype/accounts_settings/accounts_settings.js index 0627675de792..5b9a52e8f8b1 100644 --- a/erpnext/accounts/doctype/accounts_settings/accounts_settings.js +++ b/erpnext/accounts/doctype/accounts_settings/accounts_settings.js @@ -1,8 +1,6 @@ // Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Accounts Settings', { - refresh: function(frm) { - - } +frappe.ui.form.on("Accounts Settings", { + refresh: function (frm) {}, }); diff --git a/erpnext/accounts/doctype/accounts_settings/regional/united_states.js b/erpnext/accounts/doctype/accounts_settings/regional/united_states.js index 3e38386481ca..a522de9da755 100644 --- a/erpnext/accounts/doctype/accounts_settings/regional/united_states.js +++ b/erpnext/accounts/doctype/accounts_settings/regional/united_states.js @@ -1,8 +1,11 @@ - -frappe.ui.form.on('Accounts Settings', { - refresh: function(frm) { +frappe.ui.form.on("Accounts Settings", { + refresh: function (frm) { frm.set_df_property("acc_frozen_upto", "label", "Books Closed Through"); - frm.set_df_property("frozen_accounts_modifier", "label", "Role Allowed to Close Books & Make Changes to Closed Periods"); + frm.set_df_property( + "frozen_accounts_modifier", + "label", + "Role Allowed to Close Books & Make Changes to Closed Periods" + ); frm.set_df_property("credit_controller", "label", "Credit Manager"); - } + }, }); diff --git a/erpnext/accounts/doctype/bank/bank.js b/erpnext/accounts/doctype/bank/bank.js index 35d606ba3ae3..0e186af41bab 100644 --- a/erpnext/accounts/doctype/bank/bank.js +++ b/erpnext/accounts/doctype/bank/bank.js @@ -1,41 +1,39 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.provide('erpnext.integrations'); +frappe.provide("erpnext.integrations"); -frappe.ui.form.on('Bank', { - onload: function(frm) { +frappe.ui.form.on("Bank", { + onload: function (frm) { add_fields_to_mapping_table(frm); }, - refresh: function(frm) { + refresh: function (frm) { add_fields_to_mapping_table(frm); - frappe.dynamic_link = { doc: frm.doc, fieldname: 'name', doctype: 'Bank' }; + frappe.dynamic_link = { doc: frm.doc, fieldname: "name", doctype: "Bank" }; - frm.toggle_display(['address_html','contact_html'], !frm.doc.__islocal); + frm.toggle_display(["address_html", "contact_html"], !frm.doc.__islocal); if (frm.doc.__islocal) { - frm.set_df_property('address_and_contact', 'hidden', 1); + frm.set_df_property("address_and_contact", "hidden", 1); frappe.contacts.clear_address_and_contact(frm); - } - else { - frm.set_df_property('address_and_contact', 'hidden', 0); + } else { + frm.set_df_property("address_and_contact", "hidden", 0); frappe.contacts.render_address_and_contact(frm); } if (frm.doc.plaid_access_token) { - frm.add_custom_button(__('Refresh Plaid Link'), () => { + frm.add_custom_button(__("Refresh Plaid Link"), () => { new erpnext.integrations.refreshPlaidLink(frm.doc.plaid_access_token); }); } - } + }, }); - let add_fields_to_mapping_table = function (frm) { let options = []; - frappe.model.with_doctype("Bank Transaction", function() { + frappe.model.with_doctype("Bank Transaction", function () { let meta = frappe.get_meta("Bank Transaction"); - meta.fields.forEach(value => { + meta.fields.forEach((value) => { if (!["Section Break", "Column Break"].includes(value.fieldtype)) { options.push(value.fieldname); } @@ -43,30 +41,32 @@ let add_fields_to_mapping_table = function (frm) { }); frm.fields_dict.bank_transaction_mapping.grid.update_docfield_property( - 'bank_transaction_field', 'options', options + "bank_transaction_field", + "options", + options ); }; erpnext.integrations.refreshPlaidLink = class refreshPlaidLink { constructor(access_token) { this.access_token = access_token; - this.plaidUrl = 'https://cdn.plaid.com/link/v2/stable/link-initialize.js'; + this.plaidUrl = "https://cdn.plaid.com/link/v2/stable/link-initialize.js"; this.init_config(); } async init_config() { - this.plaid_env = await frappe.db.get_single_value('Plaid Settings', 'plaid_env'); + this.plaid_env = await frappe.db.get_single_value("Plaid Settings", "plaid_env"); this.token = await this.get_link_token_for_update(); this.init_plaid(); } async get_link_token_for_update() { const token = frappe.xcall( - 'erpnext.erpnext_integrations.doctype.plaid_settings.plaid_settings.get_link_token_for_update', + "erpnext.erpnext_integrations.doctype.plaid_settings.plaid_settings.get_link_token_for_update", { access_token: this.access_token } - ) + ); if (!token) { - frappe.throw(__('Cannot retrieve link token for update. Check Error Log for more information')); + frappe.throw(__("Cannot retrieve link token for update. Check Error Log for more information")); } return token; } @@ -93,13 +93,13 @@ erpnext.integrations.refreshPlaidLink = class refreshPlaidLink { resolve(); return; } - const el = document.createElement('script'); - el.type = 'text/javascript'; + const el = document.createElement("script"); + el.type = "text/javascript"; el.async = true; el.src = src; - el.addEventListener('load', resolve); - el.addEventListener('error', reject); - el.addEventListener('abort', reject); + el.addEventListener("load", resolve); + el.addEventListener("error", reject); + el.addEventListener("abort", reject); document.head.appendChild(el); }); } @@ -108,20 +108,29 @@ erpnext.integrations.refreshPlaidLink = class refreshPlaidLink { me.linkHandler = Plaid.create({ env: me.plaid_env, token: me.token, - onSuccess: me.plaid_success + onSuccess: me.plaid_success, }); } onScriptError(error) { - frappe.msgprint(__("There was an issue connecting to Plaid's authentication server. Check browser console for more information")); + frappe.msgprint( + __( + "There was an issue connecting to Plaid's authentication server. Check browser console for more information" + ) + ); console.log(error); } plaid_success(token, response) { - frappe.xcall('erpnext.erpnext_integrations.doctype.plaid_settings.plaid_settings.update_bank_account_ids', { - response: response, - }).then(() => { - frappe.show_alert({ message: __('Plaid Link Updated'), indicator: 'green' }); - }); + frappe + .xcall( + "erpnext.erpnext_integrations.doctype.plaid_settings.plaid_settings.update_bank_account_ids", + { + response: response, + } + ) + .then(() => { + frappe.show_alert({ message: __("Plaid Link Updated"), indicator: "green" }); + }); } }; diff --git a/erpnext/accounts/doctype/bank_account/bank_account.js b/erpnext/accounts/doctype/bank_account/bank_account.js index 0598190b5187..202f750fb504 100644 --- a/erpnext/accounts/doctype/bank_account/bank_account.js +++ b/erpnext/accounts/doctype/bank_account/bank_account.js @@ -1,45 +1,49 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Bank Account', { - setup: function(frm) { - frm.set_query("account", function() { +frappe.ui.form.on("Bank Account", { + setup: function (frm) { + frm.set_query("account", function () { return { filters: { - 'account_type': 'Bank', - 'company': frm.doc.company, - 'is_group': 0 - } + account_type: "Bank", + company: frm.doc.company, + is_group: 0, + }, }; }); - frm.set_query("party_type", function() { + frm.set_query("party_type", function () { return { query: "erpnext.setup.doctype.party_type.party_type.get_party_type", }; }); }, - refresh: function(frm) { - frappe.dynamic_link = { doc: frm.doc, fieldname: 'name', doctype: 'Bank Account' } + refresh: function (frm) { + frappe.dynamic_link = { doc: frm.doc, fieldname: "name", doctype: "Bank Account" }; - frm.toggle_display(['address_html','contact_html'], !frm.doc.__islocal); + frm.toggle_display(["address_html", "contact_html"], !frm.doc.__islocal); if (frm.doc.__islocal) { frappe.contacts.clear_address_and_contact(frm); - } - else { + } else { frappe.contacts.render_address_and_contact(frm); } if (frm.doc.integration_id) { - frm.add_custom_button(__("Unlink external integrations"), function() { - frappe.confirm(__("This action will unlink this account from any external service integrating ERPNext with your bank accounts. It cannot be undone. Are you certain ?"), function() { - frm.set_value("integration_id", ""); - }); + frm.add_custom_button(__("Unlink external integrations"), function () { + frappe.confirm( + __( + "This action will unlink this account from any external service integrating ERPNext with your bank accounts. It cannot be undone. Are you certain ?" + ), + function () { + frm.set_value("integration_id", ""); + } + ); }); } }, - is_company_account: function(frm) { - frm.set_df_property('account', 'reqd', frm.doc.is_company_account); - } + is_company_account: function (frm) { + frm.set_df_property("account", "reqd", frm.doc.is_company_account); + }, }); diff --git a/erpnext/accounts/doctype/bank_account_subtype/bank_account_subtype.js b/erpnext/accounts/doctype/bank_account_subtype/bank_account_subtype.js index f0456651c8f8..e8fe4e0b9bdf 100644 --- a/erpnext/accounts/doctype/bank_account_subtype/bank_account_subtype.js +++ b/erpnext/accounts/doctype/bank_account_subtype/bank_account_subtype.js @@ -1,8 +1,6 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Bank Account Subtype', { - refresh: function() { - - } +frappe.ui.form.on("Bank Account Subtype", { + refresh: function () {}, }); diff --git a/erpnext/accounts/doctype/bank_account_type/bank_account_type.js b/erpnext/accounts/doctype/bank_account_type/bank_account_type.js index 4cfabe3d1d15..1285fe4866f1 100644 --- a/erpnext/accounts/doctype/bank_account_type/bank_account_type.js +++ b/erpnext/accounts/doctype/bank_account_type/bank_account_type.js @@ -1,8 +1,7 @@ // Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Bank Account Type', { +frappe.ui.form.on("Bank Account Type", { // refresh: function(frm) { - // } }); diff --git a/erpnext/accounts/doctype/bank_clearance/bank_clearance.js b/erpnext/accounts/doctype/bank_clearance/bank_clearance.js index 71f2dcca1b2f..ddf7bc5dec6c 100644 --- a/erpnext/accounts/doctype/bank_clearance/bank_clearance.js +++ b/erpnext/accounts/doctype/bank_clearance/bank_clearance.js @@ -2,80 +2,76 @@ // License: GNU General Public License v3. See license.txt frappe.ui.form.on("Bank Clearance", { - setup: function(frm) { + setup: function (frm) { frm.add_fetch("account", "account_currency", "account_currency"); - frm.set_query("account", function() { + frm.set_query("account", function () { return { - "filters": { - "account_type": ["in",["Bank","Cash"]], - "is_group": 0, - } + filters: { + account_type: ["in", ["Bank", "Cash"]], + is_group: 0, + }, }; }); frm.set_query("bank_account", function () { return { filters: { - 'is_company_account': 1 + is_company_account: 1, }, }; }); }, - onload: function(frm) { - - let default_bank_account = frappe.defaults.get_user_default("Company")? - locals[":Company"][frappe.defaults.get_user_default("Company")]["default_bank_account"]: ""; + onload: function (frm) { + let default_bank_account = frappe.defaults.get_user_default("Company") + ? locals[":Company"][frappe.defaults.get_user_default("Company")]["default_bank_account"] + : ""; frm.set_value("account", default_bank_account); - - frm.set_value("from_date", frappe.datetime.month_start()); frm.set_value("to_date", frappe.datetime.month_end()); }, - refresh: function(frm) { + refresh: function (frm) { frm.disable_save(); - frm.add_custom_button(__('Get Payment Entries'), () => - frm.trigger("get_payment_entries") - ); + frm.add_custom_button(__("Get Payment Entries"), () => frm.trigger("get_payment_entries")); - frm.change_custom_button_type('Get Payment Entries', null, 'primary'); + frm.change_custom_button_type("Get Payment Entries", null, "primary"); }, - update_clearance_date: function(frm) { + update_clearance_date: function (frm) { return frappe.call({ method: "update_clearance_date", doc: frm.doc, - callback: function(r, rt) { + callback: function (r, rt) { frm.refresh_field("payment_entries"); frm.refresh_fields(); if (!frm.doc.payment_entries.length) { - frm.change_custom_button_type('Get Payment Entries', null, 'primary'); - frm.change_custom_button_type('Update Clearance Date', null, 'default'); + frm.change_custom_button_type("Get Payment Entries", null, "primary"); + frm.change_custom_button_type("Update Clearance Date", null, "default"); } - } + }, }); }, - get_payment_entries: function(frm) { + get_payment_entries: function (frm) { return frappe.call({ method: "get_payment_entries", doc: frm.doc, - callback: function(r, rt) { + callback: function (r, rt) { frm.refresh_field("payment_entries"); if (frm.doc.payment_entries.length) { - frm.add_custom_button(__('Update Clearance Date'), () => + frm.add_custom_button(__("Update Clearance Date"), () => frm.trigger("update_clearance_date") ); - frm.change_custom_button_type('Get Payment Entries', null, 'default'); - frm.change_custom_button_type('Update Clearance Date', null, 'primary'); + frm.change_custom_button_type("Get Payment Entries", null, "default"); + frm.change_custom_button_type("Update Clearance Date", null, "primary"); } - } + }, }); - } + }, }); diff --git a/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.js b/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.js index 99cc0a72fb37..060c4b5edaaa 100644 --- a/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.js +++ b/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.js @@ -1,39 +1,39 @@ // Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -cur_frm.add_fetch('bank_account','account','account'); -cur_frm.add_fetch('bank_account','bank_account_no','bank_account_no'); -cur_frm.add_fetch('bank_account','iban','iban'); -cur_frm.add_fetch('bank_account','branch_code','branch_code'); -cur_frm.add_fetch('bank','swift_number','swift_number'); +cur_frm.add_fetch("bank_account", "account", "account"); +cur_frm.add_fetch("bank_account", "bank_account_no", "bank_account_no"); +cur_frm.add_fetch("bank_account", "iban", "iban"); +cur_frm.add_fetch("bank_account", "branch_code", "branch_code"); +cur_frm.add_fetch("bank", "swift_number", "swift_number"); -frappe.ui.form.on('Bank Guarantee', { - setup: function(frm) { - frm.set_query("bank", function() { +frappe.ui.form.on("Bank Guarantee", { + setup: function (frm) { + frm.set_query("bank", function () { return { filters: { - company: frm.doc.company - } + company: frm.doc.company, + }, }; }); - frm.set_query("bank_account", function() { + frm.set_query("bank_account", function () { return { filters: { company: frm.doc.company, - bank: frm.doc.bank - } - } + bank: frm.doc.bank, + }, + }; }); - frm.set_query("project", function() { + frm.set_query("project", function () { return { filters: { - customer: frm.doc.customer - } + customer: frm.doc.customer, + }, }; }); }, - bg_type: function(frm) { + bg_type: function (frm) { if (frm.doc.bg_type == "Receiving") { frm.set_value("reference_doctype", "Sales Order"); } else if (frm.doc.bg_type == "Providing") { @@ -41,34 +41,33 @@ frappe.ui.form.on('Bank Guarantee', { } }, - reference_docname: function(frm) { + reference_docname: function (frm) { if (frm.doc.reference_docname && frm.doc.reference_doctype) { let party_field = frm.doc.reference_doctype == "Sales Order" ? "customer" : "supplier"; frappe.call({ method: "erpnext.accounts.doctype.bank_guarantee.bank_guarantee.get_voucher_details", args: { - "bank_guarantee_type": frm.doc.bg_type, - "reference_name": frm.doc.reference_docname + bank_guarantee_type: frm.doc.bg_type, + reference_name: frm.doc.reference_docname, }, - callback: function(r) { + callback: function (r) { if (r.message) { if (r.message[party_field]) frm.set_value(party_field, r.message[party_field]); if (r.message.project) frm.set_value("project", r.message.project); if (r.message.grand_total) frm.set_value("amount", r.message.grand_total); } - } + }, }); - } }, - start_date: function(frm) { + start_date: function (frm) { var end_date = frappe.datetime.add_days(cur_frm.doc.start_date, cur_frm.doc.validity - 1); cur_frm.set_value("end_date", end_date); }, - validity: function(frm) { + validity: function (frm) { var end_date = frappe.datetime.add_days(cur_frm.doc.start_date, cur_frm.doc.validity - 1); cur_frm.set_value("end_date", end_date); - } + }, }); diff --git a/erpnext/accounts/doctype/bank_reconciliation_tool/bank_reconciliation_tool.js b/erpnext/accounts/doctype/bank_reconciliation_tool/bank_reconciliation_tool.js index f2380bde1250..10c0781e1d3a 100644 --- a/erpnext/accounts/doctype/bank_reconciliation_tool/bank_reconciliation_tool.js +++ b/erpnext/accounts/doctype/bank_reconciliation_tool/bank_reconciliation_tool.js @@ -8,21 +8,22 @@ frappe.ui.form.on("Bank Reconciliation Tool", { return { filters: { company: frm.doc.company, - 'is_company_account': 1 + is_company_account: 1, }, }; }); - let no_bank_transactions_text = - `
${__("No Matching Bank Transactions Found")}
` + let no_bank_transactions_text = `
${__( + "No Matching Bank Transactions Found" + )}
`; set_field_options("no_bank_transactions", no_bank_transactions_text); }, onload: function (frm) { // Set default filter dates - let today = frappe.datetime.get_today() + let today = frappe.datetime.get_today(); frm.doc.bank_statement_from_date = frappe.datetime.add_months(today, -1); frm.doc.bank_statement_to_date = today; - frm.trigger('bank_account'); + frm.trigger("bank_account"); }, filter_by_reference_date: function (frm) { @@ -37,34 +38,27 @@ frappe.ui.form.on("Bank Reconciliation Tool", { refresh: function (frm) { frm.disable_save(); - frappe.require("bank-reconciliation-tool.bundle.js", () => - frm.trigger("make_reconciliation_tool") - ); + frappe.require("bank-reconciliation-tool.bundle.js", () => frm.trigger("make_reconciliation_tool")); frm.add_custom_button(__("Upload Bank Statement"), () => - frappe.call({ - method: - "erpnext.accounts.doctype.bank_statement_import.bank_statement_import.upload_bank_statement", - args: { - dt: frm.doc.doctype, - dn: frm.doc.name, - company: frm.doc.company, - bank_account: frm.doc.bank_account, - }, - callback: function (r) { - if (!r.exc) { - var doc = frappe.model.sync(r.message); - frappe.set_route( - "Form", - doc[0].doctype, - doc[0].name - ); - } - }, - }) + frappe.call({ + method: "erpnext.accounts.doctype.bank_statement_import.bank_statement_import.upload_bank_statement", + args: { + dt: frm.doc.doctype, + dn: frm.doc.name, + company: frm.doc.company, + bank_account: frm.doc.bank_account, + }, + callback: function (r) { + if (!r.exc) { + var doc = frappe.model.sync(r.message); + frappe.set_route("Form", doc[0].doctype, doc[0].name); + } + }, + }) ); - frm.add_custom_button(__('Auto Reconcile'), function() { + frm.add_custom_button(__("Auto Reconcile"), function () { frappe.call({ method: "erpnext.accounts.doctype.bank_reconciliation_tool.bank_reconciliation_tool.auto_reconcile_vouchers", args: { @@ -75,33 +69,22 @@ frappe.ui.form.on("Bank Reconciliation Tool", { from_reference_date: frm.doc.from_reference_date, to_reference_date: frm.doc.to_reference_date, }, - }) + }); }); - frm.add_custom_button(__('Get Unreconciled Entries'), function() { + frm.add_custom_button(__("Get Unreconciled Entries"), function () { frm.trigger("make_reconciliation_tool"); }); - frm.change_custom_button_type('Get Unreconciled Entries', null, 'primary'); - + frm.change_custom_button_type("Get Unreconciled Entries", null, "primary"); }, bank_account: function (frm) { - frappe.db.get_value( - "Bank Account", - frm.doc.bank_account, - "account", - (r) => { - frappe.db.get_value( - "Account", - r.account, - "account_currency", - (r) => { - frm.doc.account_currency = r.account_currency; - frm.trigger("render_chart"); - } - ); - } - ); + frappe.db.get_value("Bank Account", frm.doc.bank_account, "account", (r) => { + frappe.db.get_value("Account", r.account, "account_currency", (r) => { + frm.doc.account_currency = r.account_currency; + frm.trigger("render_chart"); + }); + }); frm.trigger("get_account_opening_balance"); }, @@ -120,11 +103,7 @@ frappe.ui.form.on("Bank Reconciliation Tool", { ) { frm.trigger("render_chart"); frm.trigger("render"); - frappe.utils.scroll_to( - frm.get_field("reconciliation_tool_cards").$wrapper, - true, - 30 - ); + frappe.utils.scroll_to(frm.get_field("reconciliation_tool_cards").$wrapper, true, 30); } }); } @@ -133,11 +112,10 @@ frappe.ui.form.on("Bank Reconciliation Tool", { get_account_opening_balance(frm) { if (frm.doc.bank_account && frm.doc.bank_statement_from_date) { frappe.call({ - method: - "erpnext.accounts.doctype.bank_reconciliation_tool.bank_reconciliation_tool.get_account_balance", + method: "erpnext.accounts.doctype.bank_reconciliation_tool.bank_reconciliation_tool.get_account_balance", args: { bank_account: frm.doc.bank_account, - till_date: frappe.datetime.add_days(frm.doc.bank_statement_from_date, -1) + till_date: frappe.datetime.add_days(frm.doc.bank_statement_from_date, -1), }, callback: (response) => { frm.set_value("account_opening_balance", response.message); @@ -149,8 +127,7 @@ frappe.ui.form.on("Bank Reconciliation Tool", { get_cleared_balance(frm) { if (frm.doc.bank_account && frm.doc.bank_statement_to_date) { return frappe.call({ - method: - "erpnext.accounts.doctype.bank_reconciliation_tool.bank_reconciliation_tool.get_account_balance", + method: "erpnext.accounts.doctype.bank_reconciliation_tool.bank_reconciliation_tool.get_account_balance", args: { bank_account: frm.doc.bank_account, till_date: frm.doc.bank_statement_to_date, @@ -163,41 +140,30 @@ frappe.ui.form.on("Bank Reconciliation Tool", { }, render_chart(frm) { - frm.cards_manager = new erpnext.accounts.bank_reconciliation.NumberCardManager( - { - $reconciliation_tool_cards: frm.get_field( - "reconciliation_tool_cards" - ).$wrapper, - bank_statement_closing_balance: - frm.doc.bank_statement_closing_balance, - cleared_balance: frm.cleared_balance, - currency: frm.doc.account_currency, - } - ); + frm.cards_manager = new erpnext.accounts.bank_reconciliation.NumberCardManager({ + $reconciliation_tool_cards: frm.get_field("reconciliation_tool_cards").$wrapper, + bank_statement_closing_balance: frm.doc.bank_statement_closing_balance, + cleared_balance: frm.cleared_balance, + currency: frm.doc.account_currency, + }); }, render(frm) { if (frm.doc.bank_account) { - frm.bank_reconciliation_data_table_manager = new erpnext.accounts.bank_reconciliation.DataTableManager( - { + frm.bank_reconciliation_data_table_manager = + new erpnext.accounts.bank_reconciliation.DataTableManager({ company: frm.doc.company, bank_account: frm.doc.bank_account, - $reconciliation_tool_dt: frm.get_field( - "reconciliation_tool_dt" - ).$wrapper, - $no_bank_transactions: frm.get_field( - "no_bank_transactions" - ).$wrapper, + $reconciliation_tool_dt: frm.get_field("reconciliation_tool_dt").$wrapper, + $no_bank_transactions: frm.get_field("no_bank_transactions").$wrapper, bank_statement_from_date: frm.doc.bank_statement_from_date, bank_statement_to_date: frm.doc.bank_statement_to_date, filter_by_reference_date: frm.doc.filter_by_reference_date, from_reference_date: frm.doc.from_reference_date, to_reference_date: frm.doc.to_reference_date, - bank_statement_closing_balance: - frm.doc.bank_statement_closing_balance, + bank_statement_closing_balance: frm.doc.bank_statement_closing_balance, cards_manager: frm.cards_manager, - } - ); + }); } }, }); diff --git a/erpnext/accounts/doctype/bank_statement_import/bank_statement_import.js b/erpnext/accounts/doctype/bank_statement_import/bank_statement_import.js index db68dfad79ee..c4b442070d22 100644 --- a/erpnext/accounts/doctype/bank_statement_import/bank_statement_import.js +++ b/erpnext/accounts/doctype/bank_statement_import/bank_statement_import.js @@ -17,11 +17,9 @@ frappe.ui.form.on("Bank Statement Import", { frm.import_in_progress = false; if (data_import !== frm.doc.name) return; frappe.model.clear_doc("Bank Statement Import", frm.doc.name); - frappe.model - .with_doc("Bank Statement Import", frm.doc.name) - .then(() => { - frm.refresh(); - }); + frappe.model.with_doc("Bank Statement Import", frm.doc.name).then(() => { + frm.refresh(); + }); }); frappe.realtime.on("data_import_progress", (data) => { frm.import_in_progress = true; @@ -48,20 +46,9 @@ frappe.ui.form.on("Bank Statement Import", { : __("Updating {0} of {1}, {2}", message_args); } if (data.skipping) { - message = __( - "Skipping {0} of {1}, {2}", - [ - data.current, - data.total, - eta_message, - ] - ); + message = __("Skipping {0} of {1}, {2}", [data.current, data.total, eta_message]); } - frm.dashboard.show_progress( - __("Import Progress"), - percent, - message - ); + frm.dashboard.show_progress(__("Import Progress"), percent, message); frm.page.set_indicator(__("In Progress"), "orange"); // hide progress when complete @@ -103,15 +90,12 @@ frappe.ui.form.on("Bank Statement Import", { frm.trigger("show_report_error_button"); if (frm.doc.status === "Partial Success") { - frm.add_custom_button(__("Export Errored Rows"), () => - frm.trigger("export_errored_rows") - ); + frm.add_custom_button(__("Export Errored Rows"), () => frm.trigger("export_errored_rows")); } if (frm.doc.status.includes("Success")) { - frm.add_custom_button( - __("Go to {0} List", [__(frm.doc.reference_doctype)]), - () => frappe.set_route("List", frm.doc.reference_doctype) + frm.add_custom_button(__("Go to {0} List", [__(frm.doc.reference_doctype)]), () => + frappe.set_route("List", frm.doc.reference_doctype) ); } }, @@ -128,13 +112,8 @@ frappe.ui.form.on("Bank Statement Import", { frm.disable_save(); if (frm.doc.status !== "Success") { if (!frm.is_new() && frm.has_import_file()) { - let label = - frm.doc.status === "Pending" - ? __("Start Import") - : __("Retry"); - frm.page.set_primary_action(label, () => - frm.events.start_import(frm) - ); + let label = frm.doc.status === "Pending" ? __("Start Import") : __("Retry"); + frm.page.set_primary_action(label, () => frm.events.start_import(frm)); } else { frm.page.set_primary_action(__("Save"), () => frm.save()); } @@ -176,24 +155,24 @@ frappe.ui.form.on("Bank Statement Import", { message = successful_records.length > 1 ? __( - "Successfully imported {0} records out of {1}. Click on Export Errored Rows, fix the errors and import again.", - message_args - ) + "Successfully imported {0} records out of {1}. Click on Export Errored Rows, fix the errors and import again.", + message_args + ) : __( - "Successfully imported {0} record out of {1}. Click on Export Errored Rows, fix the errors and import again.", - message_args - ); + "Successfully imported {0} record out of {1}. Click on Export Errored Rows, fix the errors and import again.", + message_args + ); } else { message = successful_records.length > 1 ? __( - "Successfully updated {0} records out of {1}. Click on Export Errored Rows, fix the errors and import again.", - message_args - ) + "Successfully updated {0} records out of {1}. Click on Export Errored Rows, fix the errors and import again.", + message_args + ) : __( - "Successfully updated {0} record out of {1}. Click on Export Errored Rows, fix the errors and import again.", - message_args - ); + "Successfully updated {0} record out of {1}. Click on Export Errored Rows, fix the errors and import again.", + message_args + ); } } frm.dashboard.set_headline(message); @@ -236,8 +215,7 @@ frappe.ui.form.on("Bank Statement Import", { }, download_template() { - let method = - "/api/method/frappe.core.doctype.data_import.data_import.download_template"; + let method = "/api/method/frappe.core.doctype.data_import.data_import.download_template"; open_url_post(method, { doctype: "Bank Transaction", @@ -250,7 +228,7 @@ frappe.ui.form.on("Bank Statement Import", { "description", "reference_number", "bank_account", - "currency" + "currency", ], }, }); @@ -321,10 +299,7 @@ frappe.ui.form.on("Bank Statement Import", { show_import_preview(frm, preview_data) { let import_log = JSON.parse(frm.doc.statement_import_log || "[]"); - if ( - frm.import_preview && - frm.import_preview.doctype === frm.doc.reference_doctype - ) { + if (frm.import_preview && frm.import_preview.doctype === frm.doc.reference_doctype) { frm.import_preview.preview_data = preview_data; frm.import_preview.import_log = import_log; frm.import_preview.refresh(); @@ -340,19 +315,10 @@ frappe.ui.form.on("Bank Statement Import", { frm, events: { remap_column(changed_map) { - let template_options = JSON.parse( - frm.doc.template_options || "{}" - ); - template_options.column_to_field_map = - template_options.column_to_field_map || {}; - Object.assign( - template_options.column_to_field_map, - changed_map - ); - frm.set_value( - "template_options", - JSON.stringify(template_options) - ); + let template_options = JSON.parse(frm.doc.template_options || "{}"); + template_options.column_to_field_map = template_options.column_to_field_map || {}; + Object.assign(template_options.column_to_field_map, changed_map); + frm.set_value("template_options", JSON.stringify(template_options)); frm.save().then(() => frm.trigger("import_file")); }, }, @@ -386,8 +352,7 @@ frappe.ui.form.on("Bank Statement Import", { let other_warnings = []; for (let warning of warnings) { if (warning.row) { - warnings_by_row[warning.row] = - warnings_by_row[warning.row] || []; + warnings_by_row[warning.row] = warnings_by_row[warning.row] || []; warnings_by_row[warning.row].push(warning); } else { other_warnings.push(warning); @@ -402,9 +367,7 @@ frappe.ui.form.on("Bank Statement Import", { if (w.field) { let label = w.field.label + - (w.field.parent !== frm.doc.reference_doctype - ? ` (${w.field.parent})` - : ""); + (w.field.parent !== frm.doc.reference_doctype ? ` (${w.field.parent})` : ""); return `
  • ${label}: ${w.message}
  • `; } return `
  • ${w.message}
  • `; @@ -423,10 +386,9 @@ frappe.ui.form.on("Bank Statement Import", { .map((warning) => { let header = ""; if (warning.col) { - let column_number = `${__( - "Column {0}", - [warning.col] - )}`; + let column_number = `${__("Column {0}", [ + warning.col, + ])}`; let column_header = columns[warning.col].header_title; header = `${column_number} (${column_header})`; } @@ -465,36 +427,28 @@ frappe.ui.form.on("Bank Statement Import", { let html = ""; if (log.success) { if (frm.doc.import_type === "Insert New Records") { - html = __( - "Successfully imported {0}", [ - `${frappe.utils.get_form_link( - frm.doc.reference_doctype, - log.docname, - true - )}`, - ] - ); + html = __("Successfully imported {0}", [ + `${frappe.utils.get_form_link( + frm.doc.reference_doctype, + log.docname, + true + )}`, + ]); } else { - html = __( - "Successfully updated {0}", [ - `${frappe.utils.get_form_link( - frm.doc.reference_doctype, - log.docname, - true - )}`, - ] - ); + html = __("Successfully updated {0}", [ + `${frappe.utils.get_form_link( + frm.doc.reference_doctype, + log.docname, + true + )}`, + ]); } } else { let messages = log.messages .map(JSON.parse) .map((m) => { - let title = m.title - ? `${m.title}` - : ""; - let message = m.message - ? `
    ${m.message}
    ` - : ""; + let title = m.title ? `${m.title}` : ""; + let message = m.message ? `
    ${m.message}
    ` : ""; return title + message; }) .join(""); diff --git a/erpnext/accounts/doctype/bank_statement_import/bank_statement_import_list.js b/erpnext/accounts/doctype/bank_statement_import/bank_statement_import_list.js index 6c754022e680..4ab65ff73aa0 100644 --- a/erpnext/accounts/doctype/bank_statement_import/bank_statement_import_list.js +++ b/erpnext/accounts/doctype/bank_statement_import/bank_statement_import_list.js @@ -1,36 +1,34 @@ let imports_in_progress = []; -frappe.listview_settings['Bank Statement Import'] = { +frappe.listview_settings["Bank Statement Import"] = { onload(listview) { - frappe.realtime.on('data_import_progress', data => { + frappe.realtime.on("data_import_progress", (data) => { if (!imports_in_progress.includes(data.data_import)) { imports_in_progress.push(data.data_import); } }); - frappe.realtime.on('data_import_refresh', data => { - imports_in_progress = imports_in_progress.filter( - d => d !== data.data_import - ); + frappe.realtime.on("data_import_refresh", (data) => { + imports_in_progress = imports_in_progress.filter((d) => d !== data.data_import); listview.refresh(); }); }, - get_indicator: function(doc) { + get_indicator: function (doc) { var colors = { - 'Pending': 'orange', - 'Not Started': 'orange', - 'Partial Success': 'orange', - 'Success': 'green', - 'In Progress': 'orange', - 'Error': 'red' + Pending: "orange", + "Not Started": "orange", + "Partial Success": "orange", + Success: "green", + "In Progress": "orange", + Error: "red", }; let status = doc.status; if (imports_in_progress.includes(doc.name)) { - status = 'In Progress'; + status = "In Progress"; } - if (status == 'Pending') { - status = 'Not Started'; + if (status == "Pending") { + status = "Not Started"; } - return [__(status), colors[status], 'status,=,' + doc.status]; + return [__(status), colors[status], "status,=," + doc.status]; }, - hide_name_column: true + hide_name_column: true, }; diff --git a/erpnext/accounts/doctype/bank_transaction/bank_transaction.js b/erpnext/accounts/doctype/bank_transaction/bank_transaction.js index b3cc1cbb1beb..d899d4291781 100644 --- a/erpnext/accounts/doctype/bank_transaction/bank_transaction.js +++ b/erpnext/accounts/doctype/bank_transaction/bank_transaction.js @@ -3,7 +3,7 @@ frappe.ui.form.on("Bank Transaction", { onload(frm) { - frm.set_query("payment_document", "payment_entries", function() { + frm.set_query("payment_document", "payment_entries", function () { const payment_doctypes = frm.events.get_payment_doctypes(frm); return { filters: { @@ -23,7 +23,7 @@ frappe.ui.form.on("Bank Transaction", { set_bank_statement_filter(frm); }, - setup: function(frm) { + setup: function (frm) { frm.set_query("party_type", function () { return { filters: { @@ -33,16 +33,10 @@ frappe.ui.form.on("Bank Transaction", { }); }, - get_payment_doctypes: function() { + get_payment_doctypes: function () { // get payment doctypes from all the apps - return [ - "Payment Entry", - "Journal Entry", - "Sales Invoice", - "Purchase Invoice", - "Bank Transaction", - ]; - } + return ["Payment Entry", "Journal Entry", "Sales Invoice", "Purchase Invoice", "Bank Transaction"]; + }, }); frappe.ui.form.on("Bank Transaction Payments", { @@ -54,10 +48,11 @@ frappe.ui.form.on("Bank Transaction Payments", { const update_clearance_date = (frm, cdt, cdn) => { if (frm.doc.docstatus === 1) { frappe - .xcall( - "erpnext.accounts.doctype.bank_transaction.bank_transaction.unclear_reference_payment", - { doctype: cdt, docname: cdn, bt_name: frm.doc.name } - ) + .xcall("erpnext.accounts.doctype.bank_transaction.bank_transaction.unclear_reference_payment", { + doctype: cdt, + docname: cdn, + bt_name: frm.doc.name, + }) .then((e) => { if (e == "success") { frappe.show_alert({ diff --git a/erpnext/accounts/doctype/bank_transaction/bank_transaction_list.js b/erpnext/accounts/doctype/bank_transaction/bank_transaction_list.js index 2585ee9c9237..9942c09bf473 100644 --- a/erpnext/accounts/doctype/bank_transaction/bank_transaction_list.js +++ b/erpnext/accounts/doctype/bank_transaction/bank_transaction_list.js @@ -1,15 +1,15 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -frappe.listview_settings['Bank Transaction'] = { +frappe.listview_settings["Bank Transaction"] = { add_fields: ["unallocated_amount"], - get_indicator: function(doc) { - if(doc.docstatus == 2) { + get_indicator: function (doc) { + if (doc.docstatus == 2) { return [__("Cancelled"), "red", "docstatus,=,2"]; - } else if(flt(doc.unallocated_amount)<=0) { + } else if (flt(doc.unallocated_amount) <= 0) { return [__("Reconciled"), "green", "unallocated_amount,=,0"]; - } else if(flt(doc.unallocated_amount)>0) { + } else if (flt(doc.unallocated_amount) > 0) { return [__("Unreconciled"), "orange", "unallocated_amount,>,0"]; } - } + }, }; diff --git a/erpnext/accounts/doctype/budget/budget.js b/erpnext/accounts/doctype/budget/budget.js index e162e3222d39..6e874f7c08c0 100644 --- a/erpnext/accounts/doctype/budget/budget.js +++ b/erpnext/accounts/doctype/budget/budget.js @@ -2,48 +2,48 @@ // For license information, please see license.txt frappe.provide("erpnext.accounts.dimensions"); -frappe.ui.form.on('Budget', { - onload: function(frm) { - frm.set_query("account", "accounts", function() { +frappe.ui.form.on("Budget", { + onload: function (frm) { + frm.set_query("account", "accounts", function () { return { filters: { company: frm.doc.company, report_type: "Profit and Loss", - is_group: 0 - } + is_group: 0, + }, }; }); - frm.set_query("monthly_distribution", function() { + frm.set_query("monthly_distribution", function () { return { filters: { - fiscal_year: frm.doc.fiscal_year - } + fiscal_year: frm.doc.fiscal_year, + }, }; }); erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype); }, - refresh: function(frm) { - frm.trigger("toggle_reqd_fields") + refresh: function (frm) { + frm.trigger("toggle_reqd_fields"); }, - budget_against: function(frm) { - frm.trigger("set_null_value") - frm.trigger("toggle_reqd_fields") + budget_against: function (frm) { + frm.trigger("set_null_value"); + frm.trigger("toggle_reqd_fields"); }, - set_null_value: function(frm) { - if(frm.doc.budget_against == 'Cost Center') { - frm.set_value('project', null) + set_null_value: function (frm) { + if (frm.doc.budget_against == "Cost Center") { + frm.set_value("project", null); } else { - frm.set_value('cost_center', null) + frm.set_value("cost_center", null); } }, - toggle_reqd_fields: function(frm) { - frm.toggle_reqd("cost_center", frm.doc.budget_against=="Cost Center"); - frm.toggle_reqd("project", frm.doc.budget_against=="Project"); - } + toggle_reqd_fields: function (frm) { + frm.toggle_reqd("cost_center", frm.doc.budget_against == "Cost Center"); + frm.toggle_reqd("project", frm.doc.budget_against == "Project"); + }, }); diff --git a/erpnext/accounts/doctype/cash_flow_mapper/cash_flow_mapper.js b/erpnext/accounts/doctype/cash_flow_mapper/cash_flow_mapper.js index 13d223ad407e..5a1df905ce6b 100644 --- a/erpnext/accounts/doctype/cash_flow_mapper/cash_flow_mapper.js +++ b/erpnext/accounts/doctype/cash_flow_mapper/cash_flow_mapper.js @@ -1,6 +1,4 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Cash Flow Mapper', { - -}); +frappe.ui.form.on("Cash Flow Mapper", {}); diff --git a/erpnext/accounts/doctype/cash_flow_mapping/cash_flow_mapping.js b/erpnext/accounts/doctype/cash_flow_mapping/cash_flow_mapping.js index 00c71657c5c5..402dd7e2202f 100644 --- a/erpnext/accounts/doctype/cash_flow_mapping/cash_flow_mapping.js +++ b/erpnext/accounts/doctype/cash_flow_mapping/cash_flow_mapping.js @@ -1,43 +1,45 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Cash Flow Mapping', { - refresh: function(frm) { +frappe.ui.form.on("Cash Flow Mapping", { + refresh: function (frm) { frm.events.disable_unchecked_fields(frm); }, - reset_check_fields: function(frm) { - frm.fields.filter(field => field.df.fieldtype === 'Check') - .map(field => frm.set_df_property(field.df.fieldname, 'read_only', 0)); + reset_check_fields: function (frm) { + frm.fields + .filter((field) => field.df.fieldtype === "Check") + .map((field) => frm.set_df_property(field.df.fieldname, "read_only", 0)); }, has_checked_field(frm) { - const val = frm.fields.filter(field => field.value === 1); + const val = frm.fields.filter((field) => field.value === 1); return val.length ? 1 : 0; }, - _disable_unchecked_fields: function(frm) { + _disable_unchecked_fields: function (frm) { // get value of clicked field - frm.fields.filter(field => field.value === 0) - .map(field => frm.set_df_property(field.df.fieldname, 'read_only', 1)); + frm.fields + .filter((field) => field.value === 0) + .map((field) => frm.set_df_property(field.df.fieldname, "read_only", 1)); }, - disable_unchecked_fields: function(frm) { + disable_unchecked_fields: function (frm) { frm.events.reset_check_fields(frm); const checked = frm.events.has_checked_field(frm); if (checked) { frm.events._disable_unchecked_fields(frm); } }, - is_working_capital: function(frm) { + is_working_capital: function (frm) { frm.events.disable_unchecked_fields(frm); }, - is_finance_cost: function(frm) { + is_finance_cost: function (frm) { frm.events.disable_unchecked_fields(frm); }, - is_income_tax_liability: function(frm) { + is_income_tax_liability: function (frm) { frm.events.disable_unchecked_fields(frm); }, - is_income_tax_expense: function(frm) { + is_income_tax_expense: function (frm) { frm.events.disable_unchecked_fields(frm); }, - is_finance_cost_adjustment: function(frm) { + is_finance_cost_adjustment: function (frm) { frm.events.disable_unchecked_fields(frm); - } + }, }); diff --git a/erpnext/accounts/doctype/cash_flow_mapping_template/cash_flow_mapping_template.js b/erpnext/accounts/doctype/cash_flow_mapping_template/cash_flow_mapping_template.js index 8611153cd8bc..5b799b701314 100644 --- a/erpnext/accounts/doctype/cash_flow_mapping_template/cash_flow_mapping_template.js +++ b/erpnext/accounts/doctype/cash_flow_mapping_template/cash_flow_mapping_template.js @@ -1,6 +1,4 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Cash Flow Mapping Template', { - -}); +frappe.ui.form.on("Cash Flow Mapping Template", {}); diff --git a/erpnext/accounts/doctype/cash_flow_mapping_template_details/cash_flow_mapping_template_details.js b/erpnext/accounts/doctype/cash_flow_mapping_template_details/cash_flow_mapping_template_details.js index 2e5dce4fb571..b0e869fd6082 100644 --- a/erpnext/accounts/doctype/cash_flow_mapping_template_details/cash_flow_mapping_template_details.js +++ b/erpnext/accounts/doctype/cash_flow_mapping_template_details/cash_flow_mapping_template_details.js @@ -1,6 +1,4 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Cash Flow Mapping Template Details', { - -}); +frappe.ui.form.on("Cash Flow Mapping Template Details", {}); diff --git a/erpnext/accounts/doctype/cashier_closing/cashier_closing.js b/erpnext/accounts/doctype/cashier_closing/cashier_closing.js index ce791e43acd5..71664b7ada3c 100644 --- a/erpnext/accounts/doctype/cashier_closing/cashier_closing.js +++ b/erpnext/accounts/doctype/cashier_closing/cashier_closing.js @@ -1,11 +1,10 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -frappe.ui.form.on('Cashier Closing', { - - setup: function(frm){ +frappe.ui.form.on("Cashier Closing", { + setup: function (frm) { if (frm.doc.user == "" || frm.doc.user == null) { frm.doc.user = frappe.session.user; } - } + }, }); diff --git a/erpnext/accounts/doctype/chart_of_accounts_importer/chart_of_accounts_importer.js b/erpnext/accounts/doctype/chart_of_accounts_importer/chart_of_accounts_importer.js index 56fa6ce2f307..1d8bb8530832 100644 --- a/erpnext/accounts/doctype/chart_of_accounts_importer/chart_of_accounts_importer.js +++ b/erpnext/accounts/doctype/chart_of_accounts_importer/chart_of_accounts_importer.js @@ -1,4 +1,4 @@ -frappe.ui.form.on('Chart of Accounts Importer', { +frappe.ui.form.on("Chart of Accounts Importer", { onload: function (frm) { frm.set_value("company", ""); frm.set_value("import_file", ""); @@ -8,31 +8,34 @@ frappe.ui.form.on('Chart of Accounts Importer', { frm.disable_save(); // make company mandatory - frm.set_df_property('company', 'reqd', frm.doc.company ? 0 : 1); - frm.set_df_property('import_file_section', 'hidden', frm.doc.company ? 0 : 1); + frm.set_df_property("company", "reqd", frm.doc.company ? 0 : 1); + frm.set_df_property("import_file_section", "hidden", frm.doc.company ? 0 : 1); if (frm.doc.import_file) { frappe.run_serially([ () => generate_tree_preview(frm), () => create_import_button(frm), - () => frm.set_df_property('chart_preview', 'hidden', 0) + () => frm.set_df_property("chart_preview", "hidden", 0), ]); } - frm.set_df_property('chart_preview', 'hidden', - $(frm.fields_dict['chart_tree'].wrapper).html()!="" ? 0 : 1); + frm.set_df_property( + "chart_preview", + "hidden", + $(frm.fields_dict["chart_tree"].wrapper).html() != "" ? 0 : 1 + ); }, - download_template: function(frm) { + download_template: function (frm) { var d = new frappe.ui.Dialog({ title: __("Download Template"), fields: [ { - label : "File Type", + label: "File Type", fieldname: "file_type", fieldtype: "Select", reqd: 1, - options: ["Excel", "CSV"] + options: ["Excel", "CSV"], }, { label: "Template Type", @@ -41,21 +44,27 @@ frappe.ui.form.on('Chart of Accounts Importer', { reqd: 1, options: ["Sample Template", "Blank Template"], change: () => { - let template_type = d.get_value('template_type'); + let template_type = d.get_value("template_type"); if (template_type === "Sample Template") { - d.set_df_property('template_type', 'description', + d.set_df_property( + "template_type", + "description", `The Sample Template contains all the required accounts pre filled in the template. - You can add more accounts or change existing accounts in the template as per your choice.`); + You can add more accounts or change existing accounts in the template as per your choice.` + ); } else { - d.set_df_property('template_type', 'description', + d.set_df_property( + "template_type", + "description", `The Blank Template contains just the account type and root type required to build the Chart - of Accounts. Please enter the account names and add more rows as per your requirement.`); + of Accounts. Please enter the account names and add more rows as per your requirement.` + ); } - } + }, }, { - label : "Company", + label: "Company", fieldname: "company", fieldtype: "Link", reqd: 1, @@ -63,25 +72,25 @@ frappe.ui.form.on('Chart of Accounts Importer', { default: frm.doc.company, }, ], - primary_action: function() { + primary_action: function () { let data = d.get_values(); if (!data.template_type) { - frappe.throw(__('Please select Template Type to download template')); + frappe.throw(__("Please select Template Type to download template")); } open_url_post( - '/api/method/erpnext.accounts.doctype.chart_of_accounts_importer.chart_of_accounts_importer.download_template', + "/api/method/erpnext.accounts.doctype.chart_of_accounts_importer.chart_of_accounts_importer.download_template", { file_type: data.file_type, template_type: data.template_type, - company: data.company + company: data.company, } ); d.hide(); }, - primary_action_label: __('Download') + primary_action_label: __("Download"), }); d.show(); }, @@ -89,7 +98,7 @@ frappe.ui.form.on('Chart of Accounts Importer', { import_file: function (frm) { if (!frm.doc.import_file) { frm.page.set_indicator(""); - $(frm.fields_dict['chart_tree'].wrapper).empty(); // empty wrapper on removing file + $(frm.fields_dict["chart_tree"].wrapper).empty(); // empty wrapper on removing file } }, @@ -99,89 +108,97 @@ frappe.ui.form.on('Chart of Accounts Importer', { frappe.call({ method: "erpnext.accounts.doctype.chart_of_accounts_importer.chart_of_accounts_importer.validate_company", args: { - company: frm.doc.company + company: frm.doc.company, }, - callback: function(r) { - if(r.message===false) { + callback: function (r) { + if (r.message === false) { frm.set_value("company", ""); - frappe.throw(__("Transactions against the Company already exist! Chart of Accounts can only be imported for a Company with no transactions.")); + frappe.throw( + __( + "Transactions against the Company already exist! Chart of Accounts can only be imported for a Company with no transactions." + ) + ); } else { frm.trigger("refresh"); } - } + }, }); } - } + }, }); -var create_import_button = function(frm) { - frm.page.set_primary_action(__("Import"), function () { - return frappe.call({ - method: "erpnext.accounts.doctype.chart_of_accounts_importer.chart_of_accounts_importer.import_coa", - args: { - file_name: frm.doc.import_file, - company: frm.doc.company - }, - freeze: true, - freeze_message: __("Creating Accounts..."), - callback: function(r) { - if (!r.exc) { - clearInterval(frm.page["interval"]); - frm.page.set_indicator(__('Import Successful'), 'blue'); - create_reset_button(frm); - } - } - }); - }).addClass('btn btn-primary'); +var create_import_button = function (frm) { + frm.page + .set_primary_action(__("Import"), function () { + return frappe.call({ + method: "erpnext.accounts.doctype.chart_of_accounts_importer.chart_of_accounts_importer.import_coa", + args: { + file_name: frm.doc.import_file, + company: frm.doc.company, + }, + freeze: true, + freeze_message: __("Creating Accounts..."), + callback: function (r) { + if (!r.exc) { + clearInterval(frm.page["interval"]); + frm.page.set_indicator(__("Import Successful"), "blue"); + create_reset_button(frm); + } + }, + }); + }) + .addClass("btn btn-primary"); }; -var create_reset_button = function(frm) { - frm.page.set_primary_action(__("Reset"), function () { - frm.page.clear_primary_action(); - delete frm.page["show_import_button"]; - frm.reload_doc(); - }).addClass('btn btn-primary'); +var create_reset_button = function (frm) { + frm.page + .set_primary_action(__("Reset"), function () { + frm.page.clear_primary_action(); + delete frm.page["show_import_button"]; + frm.reload_doc(); + }) + .addClass("btn btn-primary"); }; -var validate_coa = function(frm) { +var validate_coa = function (frm) { if (frm.doc.import_file) { - let parent = __('All Accounts'); + let parent = __("All Accounts"); return frappe.call({ - 'method': 'erpnext.accounts.doctype.chart_of_accounts_importer.chart_of_accounts_importer.get_coa', - 'args': { + method: "erpnext.accounts.doctype.chart_of_accounts_importer.chart_of_accounts_importer.get_coa", + args: { file_name: frm.doc.import_file, parent: parent, - doctype: 'Chart of Accounts Importer', + doctype: "Chart of Accounts Importer", file_type: frm.doc.file_type, - for_validate: 1 + for_validate: 1, }, - callback: function(r) { - if (r.message['show_import_button']) { - frm.page['show_import_button'] = Boolean(r.message['show_import_button']); + callback: function (r) { + if (r.message["show_import_button"]) { + frm.page["show_import_button"] = Boolean(r.message["show_import_button"]); } - } + }, }); } }; -var generate_tree_preview = function(frm) { - let parent = __('All Accounts'); - $(frm.fields_dict['chart_tree'].wrapper).empty(); // empty wrapper to load new data +var generate_tree_preview = function (frm) { + let parent = __("All Accounts"); + $(frm.fields_dict["chart_tree"].wrapper).empty(); // empty wrapper to load new data // generate tree structure based on the csv data return new frappe.ui.Tree({ - parent: $(frm.fields_dict['chart_tree'].wrapper), + parent: $(frm.fields_dict["chart_tree"].wrapper), label: parent, expandable: true, - method: 'erpnext.accounts.doctype.chart_of_accounts_importer.chart_of_accounts_importer.get_coa', + method: "erpnext.accounts.doctype.chart_of_accounts_importer.chart_of_accounts_importer.get_coa", args: { file_name: frm.doc.import_file, parent: parent, - doctype: 'Chart of Accounts Importer', - file_type: frm.doc.file_type + doctype: "Chart of Accounts Importer", + file_type: frm.doc.file_type, }, - onclick: function(node) { + onclick: function (node) { parent = node.value; - } + }, }); }; diff --git a/erpnext/accounts/doctype/cheque_print_template/cheque_print_template.js b/erpnext/accounts/doctype/cheque_print_template/cheque_print_template.js index d10c61858f14..17cb8d00e488 100644 --- a/erpnext/accounts/doctype/cheque_print_template/cheque_print_template.js +++ b/erpnext/accounts/doctype/cheque_print_template/cheque_print_template.js @@ -3,18 +3,20 @@ frappe.provide("erpnext.cheque_print"); -frappe.ui.form.on('Cheque Print Template', { - refresh: function(frm) { - if(!frm.doc.__islocal) { - frm.add_custom_button(frm.doc.has_print_format?__("Update Print Format"):__("Create Print Format"), - function() { +frappe.ui.form.on("Cheque Print Template", { + refresh: function (frm) { + if (!frm.doc.__islocal) { + 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"); + } + ).addClass("btn-primary"); - $(frm.fields_dict.cheque_print_preview.wrapper).empty() + $(frm.fields_dict.cheque_print_preview.wrapper).empty(); - - var template = '
    \ + var template = + '
    \
    frm.events.convert_to_ledger(frm)); + frm.add_custom_button(__("Convert to Non-Group"), () => frm.events.convert_to_ledger(frm)); } else if (doc.is_group == 0) { - frm.add_custom_button(__('Convert to Group'), - () => frm.events.convert_to_group(frm)); + frm.add_custom_button(__("Convert to Group"), () => frm.events.convert_to_group(frm)); } }, convert_to_group(frm) { - frm.call('convert_ledger_to_group').then(r => { - if(r.message === 1) { + frm.call("convert_ledger_to_group").then((r) => { + if (r.message === 1) { frm.refresh(); } }); }, convert_to_ledger(frm) { - frm.call('convert_group_to_ledger').then(r => { - if(r.message === 1) { + frm.call("convert_group_to_ledger").then((r) => { + if (r.message === 1) { frm.refresh(); } }); - } + }, }); diff --git a/erpnext/accounts/doctype/cost_center/cost_center_tree.js b/erpnext/accounts/doctype/cost_center/cost_center_tree.js index 1d482c58f1a1..3edeb8efb0ba 100644 --- a/erpnext/accounts/doctype/cost_center/cost_center_tree.js +++ b/erpnext/accounts/doctype/cost_center/cost_center_tree.js @@ -1,54 +1,84 @@ frappe.treeview_settings["Cost Center"] = { breadcrumb: "Accounts", get_tree_root: false, - filters: [{ - fieldname: "company", - fieldtype:"Select", - options: erpnext.utils.get_tree_options("company"), - label: __("Company"), - default: erpnext.utils.get_tree_default("company") - }], + filters: [ + { + fieldname: "company", + fieldtype: "Select", + options: erpnext.utils.get_tree_options("company"), + label: __("Company"), + default: erpnext.utils.get_tree_default("company"), + }, + ], root_label: "Cost Centers", - get_tree_nodes: 'erpnext.accounts.utils.get_children', - add_tree_node: 'erpnext.accounts.utils.add_cc', - menu_items:[ + get_tree_nodes: "erpnext.accounts.utils.get_children", + add_tree_node: "erpnext.accounts.utils.add_cc", + menu_items: [ { - label: __('New Company'), - action: function() { frappe.new_doc("Company", true) }, - condition: 'frappe.boot.user.can_create.indexOf("Company") !== -1' - } + label: __("New Company"), + action: function () { + frappe.new_doc("Company", true); + }, + condition: 'frappe.boot.user.can_create.indexOf("Company") !== -1', + }, ], - fields:[ - {fieldtype:'Data', fieldname:'cost_center_name', label:__('New Cost Center Name'), reqd:true}, - {fieldtype:'Check', fieldname:'is_group', label:__('Is Group'), - description:__('Further cost centers can be made under Groups but entries can be made against non-Groups')}, - {fieldtype:'Data', fieldname:'cost_center_number', label:__('Cost Center Number'), - description: __("Number of new Cost Center, it will be included in the cost center name as a prefix")} + fields: [ + { fieldtype: "Data", fieldname: "cost_center_name", label: __("New Cost Center Name"), reqd: true }, + { + fieldtype: "Check", + fieldname: "is_group", + label: __("Is Group"), + description: __( + "Further cost centers can be made under Groups but entries can be made against non-Groups" + ), + }, + { + fieldtype: "Data", + fieldname: "cost_center_number", + label: __("Cost Center Number"), + description: __( + "Number of new Cost Center, it will be included in the cost center name as a prefix" + ), + }, ], - ignore_fields:["parent_cost_center"], - onload: function(treeview) { + ignore_fields: ["parent_cost_center"], + onload: function (treeview) { function get_company() { return treeview.page.fields_dict.company.get_value(); } // tools - treeview.page.add_inner_button(__("Chart of Accounts"), function() { - frappe.set_route('Tree', 'Account', {company: get_company()}); - }, __('View')); + treeview.page.add_inner_button( + __("Chart of Accounts"), + function () { + frappe.set_route("Tree", "Account", { company: get_company() }); + }, + __("View") + ); // make - treeview.page.add_inner_button(__("Budget List"), function() { - frappe.set_route('List', 'Budget', {company: get_company()}); - }, __('Budget')); - - treeview.page.add_inner_button(__("Monthly Distribution"), function() { - frappe.set_route('List', 'Monthly Distribution', {company: get_company()}); - }, __('Budget')); - - treeview.page.add_inner_button(__("Budget Variance Report"), function() { - frappe.set_route('query-report', 'Budget Variance Report', {company: get_company()}); - }, __('Budget')); + treeview.page.add_inner_button( + __("Budget List"), + function () { + frappe.set_route("List", "Budget", { company: get_company() }); + }, + __("Budget") + ); - } + treeview.page.add_inner_button( + __("Monthly Distribution"), + function () { + frappe.set_route("List", "Monthly Distribution", { company: get_company() }); + }, + __("Budget") + ); -} + treeview.page.add_inner_button( + __("Budget Variance Report"), + function () { + frappe.set_route("query-report", "Budget Variance Report", { company: get_company() }); + }, + __("Budget") + ); + }, +}; diff --git a/erpnext/accounts/doctype/cost_center_allocation/cost_center_allocation.js b/erpnext/accounts/doctype/cost_center_allocation/cost_center_allocation.js index 0da90161f518..8adc5b212159 100644 --- a/erpnext/accounts/doctype/cost_center_allocation/cost_center_allocation.js +++ b/erpnext/accounts/doctype/cost_center_allocation/cost_center_allocation.js @@ -1,24 +1,24 @@ // Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Cost Center Allocation', { - setup: function(frm) { - frm.set_query('main_cost_center', function() { +frappe.ui.form.on("Cost Center Allocation", { + setup: function (frm) { + frm.set_query("main_cost_center", function () { return { filters: { company: frm.doc.company, - is_group: 0 - } + is_group: 0, + }, }; }); - frm.set_query('cost_center', 'allocation_percentages', function() { + frm.set_query("cost_center", "allocation_percentages", function () { return { filters: { company: frm.doc.company, - is_group: 0 - } + is_group: 0, + }, }; }); - } + }, }); diff --git a/erpnext/accounts/doctype/coupon_code/coupon_code.js b/erpnext/accounts/doctype/coupon_code/coupon_code.js index da3a9f8132fb..f8b5bdc35f5b 100644 --- a/erpnext/accounts/doctype/coupon_code/coupon_code.js +++ b/erpnext/accounts/doctype/coupon_code/coupon_code.js @@ -1,44 +1,41 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Coupon Code', { - setup: function(frm) { - frm.set_query("pricing_rule", function() { +frappe.ui.form.on("Coupon Code", { + setup: function (frm) { + frm.set_query("pricing_rule", function () { return { - filters: [ - ["Pricing Rule","coupon_code_based", "=", "1"] - ] + filters: [["Pricing Rule", "coupon_code_based", "=", "1"]], }; }); }, - coupon_name:function(frm){ - if (frm.doc.__islocal===1) { + coupon_name: function (frm) { + if (frm.doc.__islocal === 1) { frm.trigger("make_coupon_code"); } }, - coupon_type:function(frm){ - if (frm.doc.__islocal===1) { + coupon_type: function (frm) { + if (frm.doc.__islocal === 1) { frm.trigger("make_coupon_code"); } }, - make_coupon_code: function(frm) { - var coupon_name=frm.doc.coupon_name; + make_coupon_code: function (frm) { + var coupon_name = frm.doc.coupon_name; var coupon_code; - if (frm.doc.coupon_type=='Gift Card') { - coupon_code=Math.random().toString(12).substring(2, 12).toUpperCase(); + if (frm.doc.coupon_type == "Gift Card") { + coupon_code = Math.random().toString(12).substring(2, 12).toUpperCase(); + } else if (frm.doc.coupon_type == "Promotional") { + coupon_name = coupon_name.replace(/\s/g, ""); + coupon_code = coupon_name.toUpperCase().slice(0, 8); } - else if(frm.doc.coupon_type=='Promotional'){ - coupon_name=coupon_name.replace(/\s/g,''); - coupon_code=coupon_name.toUpperCase().slice(0,8); - } - frm.doc.coupon_code=coupon_code; - frm.refresh_field('coupon_code'); + frm.doc.coupon_code = coupon_code; + frm.refresh_field("coupon_code"); }, - refresh: function(frm) { + refresh: function (frm) { if (frm.doc.pricing_rule) { - frm.add_custom_button(__("Add/Edit Coupon Conditions"), function(){ + frm.add_custom_button(__("Add/Edit Coupon Conditions"), function () { frappe.set_route("Form", "Pricing Rule", frm.doc.pricing_rule); }); } - } + }, }); diff --git a/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.js b/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.js index 6c40f2bec0df..d931f627dbd2 100644 --- a/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.js +++ b/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.js @@ -1,28 +1,27 @@ // Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Currency Exchange Settings', { - service_provider: function(frm) { +frappe.ui.form.on("Currency Exchange Settings", { + service_provider: function (frm) { if (frm.doc.service_provider == "exchangerate.host") { - let result = ['result']; + let result = ["result"]; let params = { - date: '{transaction_date}', - from: '{from_currency}', - to: '{to_currency}' + date: "{transaction_date}", + from: "{from_currency}", + to: "{to_currency}", }; add_param(frm, "https://api.exchangerate.host/convert", params, result); } else if (frm.doc.service_provider == "frankfurter.app") { - let result = ['rates', '{to_currency}']; + let result = ["rates", "{to_currency}"]; let params = { - base: '{from_currency}', - symbols: '{to_currency}' + base: "{from_currency}", + symbols: "{to_currency}", }; add_param(frm, "https://frankfurter.app/{transaction_date}", params, result); } - } + }, }); - function add_param(frm, api, params, result) { var row; frm.clear_table("req_params"); @@ -30,13 +29,13 @@ function add_param(frm, api, params, result) { frm.doc.api_endpoint = api; - $.each(params, function(key, value) { + $.each(params, function (key, value) { row = frm.add_child("req_params"); row.key = key; row.value = value; }); - $.each(result, function(key, value) { + $.each(result, function (key, value) { row = frm.add_child("result_key"); row.key = value; }); diff --git a/erpnext/accounts/doctype/dunning/dunning.js b/erpnext/accounts/doctype/dunning/dunning.js index 9909c6c2ab0f..5ddee638dea8 100644 --- a/erpnext/accounts/doctype/dunning/dunning.js +++ b/erpnext/accounts/doctype/dunning/dunning.js @@ -9,7 +9,7 @@ frappe.ui.form.on("Dunning", { docstatus: 1, company: frm.doc.company, outstanding_amount: [">", 0], - status: "Overdue" + status: "Overdue", }, }; }); @@ -18,18 +18,14 @@ frappe.ui.form.on("Dunning", { filters: { company: frm.doc.company, root_type: "Income", - is_group: 0 - } + is_group: 0, + }, }; }); }, refresh: function (frm) { frm.set_df_property("company", "read_only", frm.doc.__islocal ? 0 : 1); - frm.set_df_property( - "sales_invoice", - "read_only", - frm.doc.__islocal ? 0 : 1 - ); + frm.set_df_property("sales_invoice", "read_only", frm.doc.__islocal ? 0 : 1); if (frm.doc.docstatus === 1 && frm.doc.status === "Unresolved") { frm.add_custom_button(__("Resolve"), () => { frm.set_value("status", "Resolved"); @@ -40,22 +36,27 @@ frappe.ui.form.on("Dunning", { __("Payment"), function () { frm.events.make_payment_entry(frm); - },__("Create") + }, + __("Create") ); frm.page.set_inner_btn_group_as_primary(__("Create")); } - if(frm.doc.docstatus > 0) { - frm.add_custom_button(__('Ledger'), function() { - frappe.route_options = { - "voucher_no": frm.doc.name, - "from_date": frm.doc.posting_date, - "to_date": frm.doc.posting_date, - "company": frm.doc.company, - "show_cancelled_entries": frm.doc.docstatus === 2 - }; - frappe.set_route("query-report", "General Ledger"); - }, __('View')); + if (frm.doc.docstatus > 0) { + frm.add_custom_button( + __("Ledger"), + function () { + frappe.route_options = { + voucher_no: frm.doc.name, + from_date: frm.doc.posting_date, + to_date: frm.doc.posting_date, + company: frm.doc.company, + show_cancelled_entries: frm.doc.docstatus === 2, + }; + frappe.set_route("query-report", "General Ledger"); + }, + __("View") + ); } }, overdue_days: function (frm) { @@ -86,8 +87,7 @@ frappe.ui.form.on("Dunning", { get_dunning_letter_text: function (frm) { if (frm.doc.dunning_type) { frappe.call({ - method: - "erpnext.accounts.doctype.dunning.dunning.get_dunning_letter_text", + method: "erpnext.accounts.doctype.dunning.dunning.get_dunning_letter_text", args: { dunning_type: frm.doc.dunning_type, language: frm.doc.language, @@ -129,26 +129,25 @@ frappe.ui.form.on("Dunning", { }, calculate_overdue_days: function (frm) { if (frm.doc.posting_date && frm.doc.due_date) { - const overdue_days = moment(frm.doc.posting_date).diff( - frm.doc.due_date, - "days" - ); + const overdue_days = moment(frm.doc.posting_date).diff(frm.doc.due_date, "days"); frm.set_value("overdue_days", overdue_days); } }, calculate_interest_and_amount: function (frm) { - const interest_per_year = frm.doc.outstanding_amount * frm.doc.rate_of_interest / 100; - const interest_amount = flt((interest_per_year * cint(frm.doc.overdue_days)) / 365 || 0, precision('interest_amount')); - const dunning_amount = flt(interest_amount + frm.doc.dunning_fee, precision('dunning_amount')); - const grand_total = flt(frm.doc.outstanding_amount + dunning_amount, precision('grand_total')); + const interest_per_year = (frm.doc.outstanding_amount * frm.doc.rate_of_interest) / 100; + const interest_amount = flt( + (interest_per_year * cint(frm.doc.overdue_days)) / 365 || 0, + precision("interest_amount") + ); + const dunning_amount = flt(interest_amount + frm.doc.dunning_fee, precision("dunning_amount")); + const grand_total = flt(frm.doc.outstanding_amount + dunning_amount, precision("grand_total")); frm.set_value("interest_amount", interest_amount); frm.set_value("dunning_amount", dunning_amount); frm.set_value("grand_total", grand_total); }, make_payment_entry: function (frm) { return frappe.call({ - method: - "erpnext.accounts.doctype.payment_entry.payment_entry.get_payment_entry", + method: "erpnext.accounts.doctype.payment_entry.payment_entry.get_payment_entry", args: { dt: frm.doc.doctype, dn: frm.doc.name, diff --git a/erpnext/accounts/doctype/dunning_type/dunning_type.js b/erpnext/accounts/doctype/dunning_type/dunning_type.js index 54156b488dd7..5fa4fd411db4 100644 --- a/erpnext/accounts/doctype/dunning_type/dunning_type.js +++ b/erpnext/accounts/doctype/dunning_type/dunning_type.js @@ -1,8 +1,7 @@ // Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Dunning Type', { +frappe.ui.form.on("Dunning Type", { // refresh: function(frm) { - // } }); diff --git a/erpnext/accounts/doctype/exchange_rate_revaluation/exchange_rate_revaluation.js b/erpnext/accounts/doctype/exchange_rate_revaluation/exchange_rate_revaluation.js index 1ef5c837402b..741039acae6b 100644 --- a/erpnext/accounts/doctype/exchange_rate_revaluation/exchange_rate_revaluation.js +++ b/erpnext/accounts/doctype/exchange_rate_revaluation/exchange_rate_revaluation.js @@ -1,75 +1,79 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Exchange Rate Revaluation', { - setup: function(frm) { - frm.set_query("party_type", "accounts", function() { +frappe.ui.form.on("Exchange Rate Revaluation", { + setup: function (frm) { + frm.set_query("party_type", "accounts", function () { return { - "filters": { - "name": ["in", Object.keys(frappe.boot.party_account_types)], - } + filters: { + name: ["in", Object.keys(frappe.boot.party_account_types)], + }, }; }); - frm.set_query("account", "accounts", function(doc) { + frm.set_query("account", "accounts", function (doc) { return { - "filters": { - "company": doc.company - } + filters: { + company: doc.company, + }, }; }); }, - refresh: function(frm) { - if(frm.doc.docstatus==1) { + refresh: function (frm) { + if (frm.doc.docstatus == 1) { frappe.call({ - method: 'check_journal_entry_condition', + method: "check_journal_entry_condition", doc: frm.doc, - callback: function(r) { + callback: function (r) { if (r.message) { - frm.add_custom_button(__('Journal Entries'), function() { - return frm.events.make_jv(frm); - }, __('Create')); + frm.add_custom_button( + __("Journal Entries"), + function () { + return frm.events.make_jv(frm); + }, + __("Create") + ); } - } + }, }); } }, - validate_rounding_loss: function(frm) { + validate_rounding_loss: function (frm) { let allowance = frm.doc.rounding_loss_allowance; if (!(allowance >= 0 && allowance < 1)) { frappe.throw(__("Rounding Loss Allowance should be between 0 and 1")); } }, - rounding_loss_allowance: function(frm) { + rounding_loss_allowance: function (frm) { frm.events.validate_rounding_loss(frm); }, - validate: function(frm) { + validate: function (frm) { frm.events.validate_rounding_loss(frm); }, - get_entries: function(frm, account) { + get_entries: function (frm, account) { frappe.call({ method: "get_accounts_data", doc: cur_frm.doc, account: account, - callback: function(r){ + callback: function (r) { frappe.model.clear_table(frm.doc, "accounts"); - if(r.message) { + if (r.message) { r.message.forEach((d) => { - cur_frm.add_child("accounts",d); + cur_frm.add_child("accounts", d); }); frm.events.get_total_gain_loss(frm); refresh_field("accounts"); } - } + }, }); }, - get_total_gain_loss: function(frm) { - if(!(frm.doc.accounts && frm.doc.accounts.length)) return; + get_total_gain_loss: function (frm) { + if (!(frm.doc.accounts && frm.doc.accounts.length)) return; let total_gain_loss = 0; frm.doc.accounts.forEach((d) => { @@ -80,7 +84,7 @@ frappe.ui.form.on('Exchange Rate Revaluation', { frm.refresh_fields(); }, - make_jv : function(frm) { + make_jv: function (frm) { let revaluation_journal = null; let zero_balance_journal = null; frappe.call({ @@ -88,66 +92,68 @@ frappe.ui.form.on('Exchange Rate Revaluation', { doc: frm.doc, freeze: true, freeze_message: "Making Journal Entries...", - callback: function(r){ + callback: function (r) { if (r.message) { let response = r.message; - if(response['revaluation_jv'] || response['zero_balance_jv']) { + if (response["revaluation_jv"] || response["zero_balance_jv"]) { frappe.msgprint(__("Journals have been created")); } } - } + }, }); - } + }, }); frappe.ui.form.on("Exchange Rate Revaluation Account", { - new_exchange_rate: function(frm, cdt, cdn) { + new_exchange_rate: function (frm, cdt, cdn) { var row = frappe.get_doc(cdt, cdn); - row.new_balance_in_base_currency = flt(row.new_exchange_rate * flt(row.balance_in_account_currency), - precision("new_balance_in_base_currency", row)); + row.new_balance_in_base_currency = flt( + row.new_exchange_rate * flt(row.balance_in_account_currency), + precision("new_balance_in_base_currency", row) + ); row.gain_loss = row.new_balance_in_base_currency - flt(row.balance_in_base_currency); refresh_field("accounts"); frm.events.get_total_gain_loss(frm); }, - account: function(frm, cdt, cdn) { + account: function (frm, cdt, cdn) { var row = locals[cdt][cdn]; if (row.account) { get_account_details(frm, cdt, cdn); } }, - party: function(frm, cdt, cdn) { + party: function (frm, cdt, cdn) { var row = locals[cdt][cdn]; if (row.party && row.account) { get_account_details(frm, cdt, cdn); } }, - accounts_remove: function(frm) { + accounts_remove: function (frm) { frm.events.get_total_gain_loss(frm); - } + }, }); -var get_account_details = function(frm, cdt, cdn) { +var get_account_details = function (frm, cdt, cdn) { var row = frappe.get_doc(cdt, cdn); - if(!frm.doc.company || !frm.doc.posting_date) { + if (!frm.doc.company || !frm.doc.posting_date) { frappe.throw(__("Please select Company and Posting Date to getting entries")); } frappe.call({ method: "erpnext.accounts.doctype.exchange_rate_revaluation.exchange_rate_revaluation.get_account_details", - args:{ + args: { account: row.account, company: frm.doc.company, posting_date: frm.doc.posting_date, party_type: row.party_type, party: row.party, - rounding_loss_allowance: frm.doc.rounding_loss_allowance + rounding_loss_allowance: frm.doc.rounding_loss_allowance, }, - callback: function(r){ + callback: function (r) { $.extend(row, r.message); refresh_field("accounts"); frm.events.get_total_gain_loss(frm); - } + }, }); }; diff --git a/erpnext/accounts/doctype/finance_book/finance_book.js b/erpnext/accounts/doctype/finance_book/finance_book.js index 71191bb0cfae..ebe1d246ef1f 100644 --- a/erpnext/accounts/doctype/finance_book/finance_book.js +++ b/erpnext/accounts/doctype/finance_book/finance_book.js @@ -1,8 +1,6 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Finance Book', { - refresh: function(frm) { - - } +frappe.ui.form.on("Finance Book", { + refresh: function (frm) {}, }); diff --git a/erpnext/accounts/doctype/fiscal_year/fiscal_year.js b/erpnext/accounts/doctype/fiscal_year/fiscal_year.js index 508b2eaf2a48..a44b52f08f8f 100644 --- a/erpnext/accounts/doctype/fiscal_year/fiscal_year.js +++ b/erpnext/accounts/doctype/fiscal_year/fiscal_year.js @@ -1,17 +1,21 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -frappe.ui.form.on('Fiscal Year', { - onload: function(frm) { - if(frm.doc.__islocal) { - frm.set_value("year_start_date", - frappe.datetime.add_days(frappe.defaults.get_default("year_end_date"), 1)); +frappe.ui.form.on("Fiscal Year", { + onload: function (frm) { + if (frm.doc.__islocal) { + frm.set_value( + "year_start_date", + frappe.datetime.add_days(frappe.defaults.get_default("year_end_date"), 1) + ); } }, - year_start_date: function(frm) { + year_start_date: function (frm) { if (!frm.doc.is_short_year) { - let year_end_date = - frappe.datetime.add_days(frappe.datetime.add_months(frm.doc.year_start_date, 12), -1); + let year_end_date = frappe.datetime.add_days( + frappe.datetime.add_months(frm.doc.year_start_date, 12), + -1 + ); frm.set_value("year_end_date", year_end_date); } }, diff --git a/erpnext/accounts/doctype/gl_entry/gl_entry.js b/erpnext/accounts/doctype/gl_entry/gl_entry.js index 4d2a51351877..7f81a2a4e025 100644 --- a/erpnext/accounts/doctype/gl_entry/gl_entry.js +++ b/erpnext/accounts/doctype/gl_entry/gl_entry.js @@ -1,8 +1,8 @@ // Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('GL Entry', { - refresh: function(frm) { - frm.page.btn_secondary.hide() - } +frappe.ui.form.on("GL Entry", { + refresh: function (frm) { + frm.page.btn_secondary.hide(); + }, }); diff --git a/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.js b/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.js index db4f7c423f90..974f037a81da 100644 --- a/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.js +++ b/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.js @@ -1,47 +1,49 @@ // Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Invoice Discounting', { +frappe.ui.form.on("Invoice Discounting", { setup: (frm) => { frm.set_query("sales_invoice", "invoices", (doc) => { return { - "filters": { - "docstatus": 1, - "company": doc.company, - "outstanding_amount": [">", 0] + filters: { + docstatus: 1, + company: doc.company, + outstanding_amount: [">", 0], }, }; }); - frm.events.filter_accounts("bank_account", frm, [["account_type", "=", "Bank"]]); frm.events.filter_accounts("bank_charges_account", frm, [["root_type", "=", "Expense"]]); frm.events.filter_accounts("short_term_loan", frm, [["root_type", "=", "Liability"]]); - frm.events.filter_accounts("accounts_receivable_discounted", frm, [["account_type", "=", "Receivable"]]); + frm.events.filter_accounts("accounts_receivable_discounted", frm, [ + ["account_type", "=", "Receivable"], + ]); frm.events.filter_accounts("accounts_receivable_credit", frm, [["account_type", "=", "Receivable"]]); frm.events.filter_accounts("accounts_receivable_unpaid", frm, [["account_type", "=", "Receivable"]]); - }, filter_accounts: (fieldname, frm, addl_filters) => { let filters = [ ["company", "=", frm.doc.company], - ["is_group", "=", 0] + ["is_group", "=", 0], ]; - if(addl_filters){ - filters = $.merge(filters , addl_filters); + if (addl_filters) { + filters = $.merge(filters, addl_filters); } - frm.set_query(fieldname, () => { return { "filters": filters }; }); + frm.set_query(fieldname, () => { + return { filters: filters }; + }); }, - refresh_filters: (frm) =>{ - let invoice_accounts = Object.keys(frm.doc.invoices).map(function(key) { + refresh_filters: (frm) => { + let invoice_accounts = Object.keys(frm.doc.invoices).map(function (key) { return frm.doc.invoices[key].debit_to; }); let filters = [ ["account_type", "=", "Receivable"], - ["name", "not in", invoice_accounts] + ["name", "not in", invoice_accounts], ]; frm.events.filter_accounts("accounts_receivable_credit", frm, filters); frm.events.filter_accounts("accounts_receivable_discounted", frm, filters); @@ -52,19 +54,19 @@ frappe.ui.form.on('Invoice Discounting', { frm.events.show_general_ledger(frm); if (frm.doc.docstatus === 0) { - frm.add_custom_button(__('Get Invoices'), function() { + frm.add_custom_button(__("Get Invoices"), function () { frm.events.get_invoices(frm); }); } if (frm.doc.docstatus === 1 && frm.doc.status !== "Settled") { if (frm.doc.status == "Sanctioned") { - frm.add_custom_button(__('Disburse Loan'), function() { + frm.add_custom_button(__("Disburse Loan"), function () { frm.events.create_disbursement_entry(frm); }).addClass("btn-primary"); } if (frm.doc.status == "Disbursed") { - frm.add_custom_button(__('Close Loan'), function() { + frm.add_custom_button(__("Close Loan"), function () { frm.events.close_loan(frm); }).addClass("btn-primary"); } @@ -92,119 +94,121 @@ frappe.ui.form.on('Invoice Discounting', { calculate_total_amount: (frm) => { let total_amount = 0.0; - for (let row of (frm.doc.invoices || [])) { + for (let row of frm.doc.invoices || []) { total_amount += flt(row.outstanding_amount); } frm.set_value("total_amount", total_amount); }, get_invoices: (frm) => { var d = new frappe.ui.Dialog({ - title: __('Get Invoices based on Filters'), + title: __("Get Invoices based on Filters"), fields: [ { - "label": "Customer", - "fieldname": "customer", - "fieldtype": "Link", - "options": "Customer" + label: "Customer", + fieldname: "customer", + fieldtype: "Link", + options: "Customer", }, { - "label": "From Date", - "fieldname": "from_date", - "fieldtype": "Date" + label: "From Date", + fieldname: "from_date", + fieldtype: "Date", }, { - "label": "To Date", - "fieldname": "to_date", - "fieldtype": "Date" + label: "To Date", + fieldname: "to_date", + fieldtype: "Date", }, { - "fieldname": "col_break", - "fieldtype": "Column Break", + fieldname: "col_break", + fieldtype: "Column Break", }, { - "label": "Min Amount", - "fieldname": "min_amount", - "fieldtype": "Currency" + label: "Min Amount", + fieldname: "min_amount", + fieldtype: "Currency", }, { - "label": "Max Amount", - "fieldname": "max_amount", - "fieldtype": "Currency" - } + label: "Max Amount", + fieldname: "max_amount", + fieldtype: "Currency", + }, ], - primary_action: function() { + primary_action: function () { var data = d.get_values(); frappe.call({ method: "erpnext.accounts.doctype.invoice_discounting.invoice_discounting.get_invoices", args: { - filters: data + filters: data, }, - callback: function(r) { - if(!r.exc) { + callback: function (r) { + if (!r.exc) { d.hide(); - $.each(r.message, function(i, v) { - frm.doc.invoices = frm.doc.invoices.filter(row => row.sales_invoice); + $.each(r.message, function (i, v) { + frm.doc.invoices = frm.doc.invoices.filter((row) => row.sales_invoice); let row = frm.add_child("invoices"); $.extend(row, v); frm.events.refresh_filters(frm); }); refresh_field("invoices"); } - } + }, }); }, - primary_action_label: __('Get Invocies') + primary_action_label: __("Get Invocies"), }); d.show(); }, create_disbursement_entry: (frm) => { frappe.call({ - method:"create_disbursement_entry", + method: "create_disbursement_entry", doc: frm.doc, - callback: function(r) { - if(!r.exc){ + callback: function (r) { + if (!r.exc) { var doclist = frappe.model.sync(r.message); frappe.set_route("Form", doclist[0].doctype, doclist[0].name); } - } + }, }); - }, close_loan: (frm) => { frappe.call({ - method:"close_loan", + method: "close_loan", doc: frm.doc, - callback: function(r) { - if(!r.exc){ + callback: function (r) { + if (!r.exc) { var doclist = frappe.model.sync(r.message); frappe.set_route("Form", doclist[0].doctype, doclist[0].name); } - } + }, }); - }, show_general_ledger: (frm) => { - if(frm.doc.docstatus > 0) { - cur_frm.add_custom_button(__('Accounting Ledger'), function() { - frappe.route_options = { - voucher_no: frm.doc.name, - from_date: frm.doc.posting_date, - to_date: moment(frm.doc.modified).format('YYYY-MM-DD'), - company: frm.doc.company, - group_by: "Group by Voucher (Consolidated)", - show_cancelled_entries: frm.doc.docstatus === 2 - }; - frappe.set_route("query-report", "General Ledger"); - }, __("View")); + if (frm.doc.docstatus > 0) { + cur_frm.add_custom_button( + __("Accounting Ledger"), + function () { + frappe.route_options = { + voucher_no: frm.doc.name, + from_date: frm.doc.posting_date, + to_date: moment(frm.doc.modified).format("YYYY-MM-DD"), + company: frm.doc.company, + group_by: "Group by Voucher (Consolidated)", + show_cancelled_entries: frm.doc.docstatus === 2, + }; + frappe.set_route("query-report", "General Ledger"); + }, + __("View") + ); } - } + }, }); -frappe.ui.form.on('Discounted Invoice', { +frappe.ui.form.on("Discounted Invoice", { sales_invoice: (frm) => { frm.events.calculate_total_amount(frm); frm.events.refresh_filters(frm); @@ -212,5 +216,5 @@ frappe.ui.form.on('Discounted Invoice', { invoices_remove: (frm) => { frm.events.calculate_total_amount(frm); frm.events.refresh_filters(frm); - } + }, }); diff --git a/erpnext/accounts/doctype/invoice_discounting/invoice_discounting_list.js b/erpnext/accounts/doctype/invoice_discounting/invoice_discounting_list.js index 4895efcd4cc2..0b08e393de23 100644 --- a/erpnext/accounts/doctype/invoice_discounting/invoice_discounting_list.js +++ b/erpnext/accounts/doctype/invoice_discounting/invoice_discounting_list.js @@ -1,21 +1,16 @@ -frappe.listview_settings['Invoice Discounting'] = { +frappe.listview_settings["Invoice Discounting"] = { add_fields: ["status"], - get_indicator: function(doc) - { - if(doc.status == "Draft") { + get_indicator: function (doc) { + if (doc.status == "Draft") { return [__("Draft"), "red", "status,=,Draft"]; - } - else if(doc.status == "Sanctioned") { + } else if (doc.status == "Sanctioned") { return [__("Sanctioned"), "green", "status,=,Sanctioned"]; - } - else if(doc.status == "Disbursed") { + } else if (doc.status == "Disbursed") { return [__("Disbursed"), "blue", "status,=,Disbursed"]; - } - else if(doc.status == "Settled") { + } else if (doc.status == "Settled") { return [__("Settled"), "orange", "status,=,Settled"]; - } - else if(doc.status == "Canceled") { + } else if (doc.status == "Canceled") { return [__("Canceled"), "red", "status,=,Canceled"]; } - } + }, }; diff --git a/erpnext/accounts/doctype/item_tax_template/item_tax_template.js b/erpnext/accounts/doctype/item_tax_template/item_tax_template.js index e921a0d949d4..b608ccd35686 100644 --- a/erpnext/accounts/doctype/item_tax_template/item_tax_template.js +++ b/erpnext/accounts/doctype/item_tax_template/item_tax_template.js @@ -1,27 +1,49 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Item Tax Template', { - setup: function(frm) { - frm.set_query("tax_type", "taxes", function(doc) { +frappe.ui.form.on("Item Tax Template", { + setup: function (frm) { + frm.set_query("tax_type", "taxes", function (doc) { return { filters: [ - ['Account', 'company', '=', frm.doc.company], - ['Account', 'is_group', '=', 0], - ['Account', 'account_type', 'in', ['Tax', 'Chargeable', 'Income Account', 'Expense Account', 'Expenses Included In Valuation']] - ] - } + ["Account", "company", "=", frm.doc.company], + ["Account", "is_group", "=", 0], + [ + "Account", + "account_type", + "in", + [ + "Tax", + "Chargeable", + "Income Account", + "Expense Account", + "Expenses Included In Valuation", + ], + ], + ], + }; }); }, company: function (frm) { - frm.set_query("tax_type", "taxes", function(doc) { + frm.set_query("tax_type", "taxes", function (doc) { return { filters: [ - ['Account', 'company', '=', frm.doc.company], - ['Account', 'is_group', '=', 0], - ['Account', 'account_type', 'in', ['Tax', 'Chargeable', 'Income Account', 'Expense Account', 'Expenses Included In Valuation']] - ] - } + ["Account", "company", "=", frm.doc.company], + ["Account", "is_group", "=", 0], + [ + "Account", + "account_type", + "in", + [ + "Tax", + "Chargeable", + "Income Account", + "Expense Account", + "Expenses Included In Valuation", + ], + ], + ], + }; }); - } + }, }); diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.js b/erpnext/accounts/doctype/journal_entry/journal_entry.js index 5f59f036ef9d..a2f5455f2f74 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.js +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.js @@ -4,39 +4,57 @@ frappe.provide("erpnext.accounts"); frappe.provide("erpnext.journal_entry"); - frappe.ui.form.on("Journal Entry", { - setup: function(frm) { + setup: function (frm) { frm.add_fetch("bank_account", "account", "account"); - frm.ignore_doctypes_on_cancel_all = ["Sales Invoice", "Purchase Invoice", "Journal Entry", "Repost Payment Ledger", "Asset", "Asset Movement", "Repost Accounting Ledger", "Unreconcile Payment", "Unreconcile Payment Entries", "Bank Transaction"]; + frm.ignore_doctypes_on_cancel_all = [ + "Sales Invoice", + "Purchase Invoice", + "Journal Entry", + "Repost Payment Ledger", + "Asset", + "Asset Movement", + "Repost Accounting Ledger", + "Unreconcile Payment", + "Unreconcile Payment Entries", + "Bank Transaction", + ]; }, - refresh: function(frm) { + refresh: function (frm) { erpnext.toggle_naming_series(); - if(frm.doc.docstatus > 0) { - frm.add_custom_button(__('Ledger'), function() { - frappe.route_options = { - "voucher_no": frm.doc.name, - "from_date": frm.doc.posting_date, - "to_date": moment(frm.doc.modified).format('YYYY-MM-DD'), - "company": frm.doc.company, - "finance_book": frm.doc.finance_book, - "group_by": '', - "show_cancelled_entries": frm.doc.docstatus === 2 - }; - frappe.set_route("query-report", "General Ledger"); - }, __('View')); + if (frm.doc.docstatus > 0) { + frm.add_custom_button( + __("Ledger"), + function () { + frappe.route_options = { + voucher_no: frm.doc.name, + from_date: frm.doc.posting_date, + to_date: moment(frm.doc.modified).format("YYYY-MM-DD"), + company: frm.doc.company, + finance_book: frm.doc.finance_book, + group_by: "", + show_cancelled_entries: frm.doc.docstatus === 2, + }; + frappe.set_route("query-report", "General Ledger"); + }, + __("View") + ); } - if(frm.doc.docstatus==1) { - frm.add_custom_button(__('Reverse Journal Entry'), function() { - return erpnext.journal_entry.reverse_journal_entry(frm); - }, __('Actions')); + if (frm.doc.docstatus == 1) { + frm.add_custom_button( + __("Reverse Journal Entry"), + function () { + return erpnext.journal_entry.reverse_journal_entry(frm); + }, + __("Actions") + ); } if (frm.doc.__islocal) { - frm.add_custom_button(__('Quick Entry'), function() { + frm.add_custom_button(__("Quick Entry"), function () { return erpnext.journal_entry.quick_entry(frm); }); } @@ -44,52 +62,63 @@ frappe.ui.form.on("Journal Entry", { // hide /unhide fields based on currency erpnext.journal_entry.toggle_fields_based_on_currency(frm); - if ((frm.doc.voucher_type == "Inter Company Journal Entry") && (frm.doc.docstatus == 1) && (!frm.doc.inter_company_journal_entry_reference)) { - frm.add_custom_button(__("Create Inter Company Journal Entry"), - function() { + if ( + frm.doc.voucher_type == "Inter Company Journal Entry" && + frm.doc.docstatus == 1 && + !frm.doc.inter_company_journal_entry_reference + ) { + frm.add_custom_button( + __("Create Inter Company Journal Entry"), + function () { frm.trigger("make_inter_company_journal_entry"); - }, __('Make')); + }, + __("Make") + ); } erpnext.accounts.unreconcile_payment.add_unreconcile_btn(frm); }, - before_save: function(frm) { - if ((frm.doc.docstatus == 0) && (!frm.doc.is_system_generated)) { - let payment_entry_references = frm.doc.accounts.filter(elem => (elem.reference_type == "Payment Entry")); + before_save: function (frm) { + if (frm.doc.docstatus == 0 && !frm.doc.is_system_generated) { + let payment_entry_references = frm.doc.accounts.filter( + (elem) => elem.reference_type == "Payment Entry" + ); if (payment_entry_references.length > 0) { - let rows = payment_entry_references.map(x => "#"+x.idx); - frappe.throw(__("Rows: {0} have 'Payment Entry' as reference_type. This should not be set manually.", [frappe.utils.comma_and(rows)])); + let rows = payment_entry_references.map((x) => "#" + x.idx); + frappe.throw( + __("Rows: {0} have 'Payment Entry' as reference_type. This should not be set manually.", [ + frappe.utils.comma_and(rows), + ]) + ); } } }, - make_inter_company_journal_entry: function(frm) { + make_inter_company_journal_entry: function (frm) { var d = new frappe.ui.Dialog({ title: __("Select Company"), fields: [ { - 'fieldname': 'company', - 'fieldtype': 'Link', - 'label': __('Company'), - 'options': 'Company', - "get_query": function () { + fieldname: "company", + fieldtype: "Link", + label: __("Company"), + options: "Company", + get_query: function () { return { - filters: [ - ["Company", "name", "!=", frm.doc.company] - ] + filters: [["Company", "name", "!=", frm.doc.company]], }; }, - 'reqd': 1 - } + reqd: 1, + }, ], }); - d.set_primary_action(__('Create'), function() { + d.set_primary_action(__("Create"), function () { d.hide(); var args = d.get_values(); frappe.call({ args: { - "name": frm.doc.name, - "voucher_type": frm.doc.voucher_type, - "company": args.company + name: frm.doc.name, + voucher_type: frm.doc.voucher_type, + company: args.company, }, method: "erpnext.accounts.doctype.journal_entry.journal_entry.make_inter_company_journal_entry", callback: function (r) { @@ -97,96 +126,101 @@ frappe.ui.form.on("Journal Entry", { var doc = frappe.model.sync(r.message)[0]; frappe.set_route("Form", doc.doctype, doc.name); } - } + }, }); }); d.show(); }, - multi_currency: function(frm) { + multi_currency: function (frm) { erpnext.journal_entry.toggle_fields_based_on_currency(frm); }, - posting_date: function(frm) { - if(!frm.doc.multi_currency || !frm.doc.posting_date) return; + posting_date: function (frm) { + if (!frm.doc.multi_currency || !frm.doc.posting_date) return; - $.each(frm.doc.accounts || [], function(i, row) { + $.each(frm.doc.accounts || [], function (i, row) { erpnext.journal_entry.set_exchange_rate(frm, row.doctype, row.name); - }) + }); }, - company: function(frm) { + company: function (frm) { frappe.call({ method: "frappe.client.get_value", args: { doctype: "Company", - filters: {"name": frm.doc.company}, - fieldname: "cost_center" + filters: { name: frm.doc.company }, + fieldname: "cost_center", }, - callback: function(r){ - if(r.message){ - $.each(frm.doc.accounts || [], function(i, jvd) { + callback: function (r) { + if (r.message) { + $.each(frm.doc.accounts || [], function (i, jvd) { frappe.model.set_value(jvd.doctype, jvd.name, "cost_center", r.message.cost_center); }); } - } + }, }); erpnext.accounts.dimensions.update_dimension(frm, frm.doctype); }, - voucher_type: function(frm){ + voucher_type: function (frm) { + if (!frm.doc.company) return null; - if(!frm.doc.company) return null; - - if((!(frm.doc.accounts || []).length) || ((frm.doc.accounts || []).length === 1 && !frm.doc.accounts[0].account)) { - if(in_list(["Bank Entry", "Cash Entry"], frm.doc.voucher_type)) { + if ( + !(frm.doc.accounts || []).length || + ((frm.doc.accounts || []).length === 1 && !frm.doc.accounts[0].account) + ) { + if (in_list(["Bank Entry", "Cash Entry"], frm.doc.voucher_type)) { return frappe.call({ type: "GET", method: "erpnext.accounts.doctype.journal_entry.journal_entry.get_default_bank_cash_account", args: { - "account_type": (frm.doc.voucher_type=="Bank Entry" ? - "Bank" : (frm.doc.voucher_type=="Cash Entry" ? "Cash" : null)), - "company": frm.doc.company + account_type: + frm.doc.voucher_type == "Bank Entry" + ? "Bank" + : frm.doc.voucher_type == "Cash Entry" + ? "Cash" + : null, + company: frm.doc.company, }, - callback: function(r) { - if(r.message) { + callback: function (r) { + if (r.message) { // If default company bank account not set - if(!$.isEmptyObject(r.message)){ + if (!$.isEmptyObject(r.message)) { update_jv_details(frm.doc, [r.message]); } } - } + }, }); } } }, - from_template: function(frm){ - if (frm.doc.from_template){ - frappe.db.get_doc("Journal Entry Template", frm.doc.from_template) - .then((doc) => { - frappe.model.clear_table(frm.doc, "accounts"); - frm.set_value({ - "company": doc.company, - "voucher_type": doc.voucher_type, - "naming_series": doc.naming_series, - "is_opening": doc.is_opening, - "multi_currency": doc.multi_currency - }) - update_jv_details(frm.doc, doc.accounts); + from_template: function (frm) { + if (frm.doc.from_template) { + frappe.db.get_doc("Journal Entry Template", frm.doc.from_template).then((doc) => { + frappe.model.clear_table(frm.doc, "accounts"); + frm.set_value({ + company: doc.company, + voucher_type: doc.voucher_type, + naming_series: doc.naming_series, + is_opening: doc.is_opening, + multi_currency: doc.multi_currency, }); + update_jv_details(frm.doc, doc.accounts); + }); } - } + }, }); -var update_jv_details = function(doc, r) { - $.each(r, function(i, d) { +var update_jv_details = function (doc, r) { + $.each(r, function (i, d) { var row = frappe.model.add_child(doc, "Journal Entry Account", "accounts"); - frappe.model.set_value(row.doctype, row.name, "account", d.account) + frappe.model.set_value(row.doctype, row.name, "account", d.account); }); refresh_field("accounts"); -} +}; erpnext.accounts.JournalEntry = class JournalEntry extends frappe.ui.form.Controller { onload() { @@ -201,69 +235,67 @@ erpnext.accounts.JournalEntry = class JournalEntry extends frappe.ui.form.Contro load_defaults() { //this.frm.show_print_first = true; - if(this.frm.doc.__islocal && this.frm.doc.company) { + if (this.frm.doc.__islocal && this.frm.doc.company) { frappe.model.set_default_values(this.frm.doc); - $.each(this.frm.doc.accounts || [], function(i, jvd) { + $.each(this.frm.doc.accounts || [], function (i, jvd) { frappe.model.set_default_values(jvd); }); var posting_date = this.frm.doc.posting_date; - if(!this.frm.doc.amended_from) this.frm.set_value('posting_date', posting_date || frappe.datetime.get_today()); + if (!this.frm.doc.amended_from) + this.frm.set_value("posting_date", posting_date || frappe.datetime.get_today()); } } setup_queries() { var me = this; - me.frm.set_query("account", "accounts", function(doc, cdt, cdn) { + me.frm.set_query("account", "accounts", function (doc, cdt, cdn) { return erpnext.journal_entry.account_query(me.frm); }); - me.frm.set_query("party_type", "accounts", function(doc, cdt, cdn) { + me.frm.set_query("party_type", "accounts", function (doc, cdt, cdn) { const row = locals[cdt][cdn]; return { query: "erpnext.setup.doctype.party_type.party_type.get_party_type", filters: { - 'account': row.account - } - } + account: row.account, + }, + }; }); - me.frm.set_query("reference_name", "accounts", function(doc, cdt, cdn) { + me.frm.set_query("reference_name", "accounts", function (doc, cdt, cdn) { var jvd = frappe.get_doc(cdt, cdn); // journal entry - if(jvd.reference_type==="Journal Entry") { + if (jvd.reference_type === "Journal Entry") { frappe.model.validate_missing(jvd, "account"); return { query: "erpnext.accounts.doctype.journal_entry.journal_entry.get_against_jv", filters: { account: jvd.account, - party: jvd.party - } + party: jvd.party, + }, }; } var out = { - filters: [ - [jvd.reference_type, "docstatus", "=", 1] - ] + filters: [[jvd.reference_type, "docstatus", "=", 1]], }; - if(in_list(["Sales Invoice", "Purchase Invoice"], jvd.reference_type)) { + if (in_list(["Sales Invoice", "Purchase Invoice"], jvd.reference_type)) { out.filters.push([jvd.reference_type, "outstanding_amount", "!=", 0]); // Filter by cost center - if(jvd.cost_center) { + if (jvd.cost_center) { out.filters.push([jvd.reference_type, "cost_center", "in", ["", jvd.cost_center]]); } // account filter frappe.model.validate_missing(jvd, "account"); - var party_account_field = jvd.reference_type==="Sales Invoice" ? "debit_to": "credit_to"; + var party_account_field = jvd.reference_type === "Sales Invoice" ? "debit_to" : "credit_to"; out.filters.push([jvd.reference_type, party_account_field, "=", jvd.account]); - } - if(in_list(["Sales Order", "Purchase Order"], jvd.reference_type)) { + if (in_list(["Sales Order", "Purchase Order"], jvd.reference_type)) { // party_type and party mandatory frappe.model.validate_missing(jvd, "party_type"); frappe.model.validate_missing(jvd, "party"); @@ -271,11 +303,11 @@ erpnext.accounts.JournalEntry = class JournalEntry extends frappe.ui.form.Contro out.filters.push([jvd.reference_type, "per_billed", "<", 100]); } - if(jvd.party_type && jvd.party) { + if (jvd.party_type && jvd.party) { var party_field = ""; - if(jvd.reference_type.indexOf("Sales")===0) { + if (jvd.reference_type.indexOf("Sales") === 0) { var party_field = "customer"; - } else if (jvd.reference_type.indexOf("Purchase")===0) { + } else if (jvd.reference_type.indexOf("Purchase") === 0) { var party_field = "supplier"; } @@ -286,51 +318,49 @@ erpnext.accounts.JournalEntry = class JournalEntry extends frappe.ui.form.Contro return out; }); - - } reference_name(doc, cdt, cdn) { var d = frappe.get_doc(cdt, cdn); - if(d.reference_name) { - if (d.reference_type==="Purchase Invoice" && !flt(d.debit)) { - this.get_outstanding('Purchase Invoice', d.reference_name, doc.company, d); - } else if (d.reference_type==="Sales Invoice" && !flt(d.credit)) { - this.get_outstanding('Sales Invoice', d.reference_name, doc.company, d); - } else if (d.reference_type==="Journal Entry" && !flt(d.credit) && !flt(d.debit)) { - this.get_outstanding('Journal Entry', d.reference_name, doc.company, d); + if (d.reference_name) { + if (d.reference_type === "Purchase Invoice" && !flt(d.debit)) { + this.get_outstanding("Purchase Invoice", d.reference_name, doc.company, d); + } else if (d.reference_type === "Sales Invoice" && !flt(d.credit)) { + this.get_outstanding("Sales Invoice", d.reference_name, doc.company, d); + } else if (d.reference_type === "Journal Entry" && !flt(d.credit) && !flt(d.debit)) { + this.get_outstanding("Journal Entry", d.reference_name, doc.company, d); } } } get_outstanding(doctype, docname, company, child) { var args = { - "doctype": doctype, - "docname": docname, - "party": child.party, - "account": child.account, - "account_currency": child.account_currency, - "company": company - } + doctype: doctype, + docname: docname, + party: child.party, + account: child.account, + account_currency: child.account_currency, + company: company, + }; return frappe.call({ method: "erpnext.accounts.doctype.journal_entry.journal_entry.get_outstanding", - args: { args: args}, - callback: function(r) { - if(r.message) { - $.each(r.message, function(field, value) { + args: { args: args }, + callback: function (r) { + if (r.message) { + $.each(r.message, function (field, value) { frappe.model.set_value(child.doctype, child.name, field, value); - }) + }); } - } + }, }); } accounts_add(doc, cdt, cdn) { var row = frappe.get_doc(cdt, cdn); - $.each(doc.accounts, function(i, d) { - if(d.account && d.party && d.party_type) { + $.each(doc.accounts, function (i, d) { + if (d.account && d.party && d.party_type) { row.account = d.account; row.party = d.party; row.party_type = d.party_type; @@ -338,8 +368,8 @@ erpnext.accounts.JournalEntry = class JournalEntry extends frappe.ui.form.Contro }); // set difference - if(doc.difference) { - if(doc.difference > 0) { + if (doc.difference) { + if (doc.difference > 0) { row.credit_in_account_currency = doc.difference; row.credit = doc.difference; } else { @@ -349,41 +379,43 @@ erpnext.accounts.JournalEntry = class JournalEntry extends frappe.ui.form.Contro } cur_frm.cscript.update_totals(doc); - erpnext.accounts.dimensions.copy_dimension_from_first_row(this.frm, cdt, cdn, 'accounts'); + erpnext.accounts.dimensions.copy_dimension_from_first_row(this.frm, cdt, cdn, "accounts"); } - }; cur_frm.script_manager.make(erpnext.accounts.JournalEntry); -cur_frm.cscript.update_totals = function(doc) { - var td=0.0; var tc =0.0; +cur_frm.cscript.update_totals = function (doc) { + var td = 0.0; + var tc = 0.0; var accounts = doc.accounts || []; - for(var i in accounts) { + for (var i in accounts) { td += flt(accounts[i].debit, precision("debit", accounts[i])); tc += flt(accounts[i].credit, precision("credit", accounts[i])); } var doc = locals[doc.doctype][doc.name]; doc.total_debit = td; doc.total_credit = tc; - doc.difference = flt((td - tc), precision("difference")); - refresh_many(['total_debit','total_credit','difference']); -} + doc.difference = flt(td - tc, precision("difference")); + refresh_many(["total_debit", "total_credit", "difference"]); +}; -cur_frm.cscript.get_balance = function(doc,dt,dn) { +cur_frm.cscript.get_balance = function (doc, dt, dn) { cur_frm.cscript.update_totals(doc); - cur_frm.call('get_balance', null, () => { cur_frm.refresh(); }); -} + cur_frm.call("get_balance", null, () => { + cur_frm.refresh(); + }); +}; -cur_frm.cscript.validate = function(doc,cdt,cdn) { +cur_frm.cscript.validate = function (doc, cdt, cdn) { cur_frm.cscript.update_totals(doc); -} +}; frappe.ui.form.on("Journal Entry Account", { - party: function(frm, cdt, cdn) { + party: function (frm, cdt, cdn) { var d = frappe.get_doc(cdt, cdn); - if(!d.account && d.party_type && d.party) { - if(!frm.doc.company) frappe.throw(__("Please select Company")); + if (!d.account && d.party_type && d.party) { + if (!frm.doc.company) frappe.throw(__("Please select Company")); return frm.call({ method: "erpnext.accounts.doctype.journal_entry.journal_entry.get_party_account_and_currency", child: d, @@ -391,89 +423,97 @@ frappe.ui.form.on("Journal Entry Account", { company: frm.doc.company, party_type: d.party_type, party: d.party, - } + }, }); } }, - cost_center: function(frm, dt, dn) { + cost_center: function (frm, dt, dn) { erpnext.journal_entry.set_account_details(frm, dt, dn); }, - account: function(frm, dt, dn) { + account: function (frm, dt, dn) { erpnext.journal_entry.set_account_details(frm, dt, dn); }, - debit_in_account_currency: function(frm, cdt, cdn) { + debit_in_account_currency: function (frm, cdt, cdn) { erpnext.journal_entry.set_exchange_rate(frm, cdt, cdn); }, - credit_in_account_currency: function(frm, cdt, cdn) { + credit_in_account_currency: function (frm, cdt, cdn) { erpnext.journal_entry.set_exchange_rate(frm, cdt, cdn); }, - debit: function(frm, dt, dn) { + debit: function (frm, dt, dn) { cur_frm.cscript.update_totals(frm.doc); }, - credit: function(frm, dt, dn) { + credit: function (frm, dt, dn) { cur_frm.cscript.update_totals(frm.doc); }, - exchange_rate: function(frm, cdt, cdn) { + exchange_rate: function (frm, cdt, cdn) { var company_currency = frappe.get_doc(":Company", frm.doc.company).default_currency; var row = locals[cdt][cdn]; - if(row.account_currency == company_currency || !frm.doc.multi_currency) { + if (row.account_currency == company_currency || !frm.doc.multi_currency) { frappe.model.set_value(cdt, cdn, "exchange_rate", 1); } erpnext.journal_entry.set_debit_credit_in_company_currency(frm, cdt, cdn); - } -}) + }, +}); -frappe.ui.form.on("Journal Entry Account", "accounts_remove", function(frm) { +frappe.ui.form.on("Journal Entry Account", "accounts_remove", function (frm) { cur_frm.cscript.update_totals(frm.doc); }); $.extend(erpnext.journal_entry, { - toggle_fields_based_on_currency: function(frm) { + toggle_fields_based_on_currency: function (frm) { var fields = ["currency_section", "account_currency", "exchange_rate", "debit", "credit"]; var grid = frm.get_field("accounts").grid; - if(grid) grid.set_column_disp(fields, frm.doc.multi_currency); + if (grid) grid.set_column_disp(fields, frm.doc.multi_currency); // dynamic label var field_label_map = { - "debit_in_account_currency": "Debit", - "credit_in_account_currency": "Credit" + debit_in_account_currency: "Debit", + credit_in_account_currency: "Credit", }; $.each(field_label_map, function (fieldname, label) { frm.fields_dict.accounts.grid.update_docfield_property( fieldname, - 'label', - frm.doc.multi_currency ? (label + " in Account Currency") : label + "label", + frm.doc.multi_currency ? label + " in Account Currency" : label ); - }) + }); }, - set_debit_credit_in_company_currency: function(frm, cdt, cdn) { + set_debit_credit_in_company_currency: function (frm, cdt, cdn) { var row = locals[cdt][cdn]; - frappe.model.set_value(cdt, cdn, "debit", - flt(flt(row.debit_in_account_currency)*row.exchange_rate, precision("debit", row))); + frappe.model.set_value( + cdt, + cdn, + "debit", + flt(flt(row.debit_in_account_currency) * row.exchange_rate, precision("debit", row)) + ); - frappe.model.set_value(cdt, cdn, "credit", - flt(flt(row.credit_in_account_currency)*row.exchange_rate, precision("credit", row))); + frappe.model.set_value( + cdt, + cdn, + "credit", + flt(flt(row.credit_in_account_currency) * row.exchange_rate, precision("credit", row)) + ); cur_frm.cscript.update_totals(frm.doc); }, - set_exchange_rate: function(frm, cdt, cdn) { + set_exchange_rate: function (frm, cdt, cdn) { var company_currency = frappe.get_doc(":Company", frm.doc.company).default_currency; var row = locals[cdt][cdn]; - if(row.account_currency == company_currency || !frm.doc.multi_currency) { + if (row.account_currency == company_currency || !frm.doc.multi_currency) { row.exchange_rate = 1; erpnext.journal_entry.set_debit_credit_in_company_currency(frm, cdt, cdn); } else if (!row.exchange_rate || row.exchange_rate == 1 || row.account_type == "Bank") { @@ -488,50 +528,70 @@ $.extend(erpnext.journal_entry, { reference_name: cstr(row.reference_name), debit: flt(row.debit_in_account_currency), credit: flt(row.credit_in_account_currency), - exchange_rate: row.exchange_rate + exchange_rate: row.exchange_rate, }, - callback: function(r) { - if(r.message) { + callback: function (r) { + if (r.message) { row.exchange_rate = r.message; erpnext.journal_entry.set_debit_credit_in_company_currency(frm, cdt, cdn); } - } - }) + }, + }); } else { erpnext.journal_entry.set_debit_credit_in_company_currency(frm, cdt, cdn); } refresh_field("exchange_rate", cdn, "accounts"); }, - quick_entry: function(frm) { + quick_entry: function (frm) { var naming_series_options = frm.fields_dict.naming_series.df.options; - var naming_series_default = frm.fields_dict.naming_series.df.default || naming_series_options.split("\n")[0]; + var naming_series_default = + frm.fields_dict.naming_series.df.default || naming_series_options.split("\n")[0]; var dialog = new frappe.ui.Dialog({ title: __("Quick Journal Entry"), fields: [ - {fieldtype: "Currency", fieldname: "debit", label: __("Amount"), reqd: 1}, - {fieldtype: "Link", fieldname: "debit_account", label: __("Debit Account"), reqd: 1, + { fieldtype: "Currency", fieldname: "debit", label: __("Amount"), reqd: 1 }, + { + fieldtype: "Link", + fieldname: "debit_account", + label: __("Debit Account"), + reqd: 1, options: "Account", - get_query: function() { + get_query: function () { return erpnext.journal_entry.account_query(frm); - } + }, }, - {fieldtype: "Link", fieldname: "credit_account", label: __("Credit Account"), reqd: 1, + { + fieldtype: "Link", + fieldname: "credit_account", + label: __("Credit Account"), + reqd: 1, options: "Account", - get_query: function() { + get_query: function () { return erpnext.journal_entry.account_query(frm); - } + }, + }, + { + fieldtype: "Date", + fieldname: "posting_date", + label: __("Date"), + reqd: 1, + default: frm.doc.posting_date, + }, + { fieldtype: "Small Text", fieldname: "user_remark", label: __("User Remark") }, + { + fieldtype: "Select", + fieldname: "naming_series", + label: __("Series"), + reqd: 1, + options: naming_series_options, + default: naming_series_default, }, - {fieldtype: "Date", fieldname: "posting_date", label: __("Date"), reqd: 1, - default: frm.doc.posting_date}, - {fieldtype: "Small Text", fieldname: "user_remark", label: __("User Remark")}, - {fieldtype: "Select", fieldname: "naming_series", label: __("Series"), reqd: 1, - options: naming_series_options, default: naming_series_default}, - ] + ], }); - dialog.set_primary_action(__("Save"), function() { + dialog.set_primary_action(__("Save"), function () { var btn = this; var values = dialog.get_values(); @@ -548,11 +608,21 @@ $.extend(erpnext.journal_entry, { var debit_row = frm.fields_dict.accounts.grid.add_new_row(); frappe.model.set_value(debit_row.doctype, debit_row.name, "account", values.debit_account); - frappe.model.set_value(debit_row.doctype, debit_row.name, "debit_in_account_currency", values.debit); + frappe.model.set_value( + debit_row.doctype, + debit_row.name, + "debit_in_account_currency", + values.debit + ); var credit_row = frm.fields_dict.accounts.grid.add_new_row(); frappe.model.set_value(credit_row.doctype, credit_row.name, "account", values.credit_account); - frappe.model.set_value(credit_row.doctype, credit_row.name, "credit_in_account_currency", values.debit); + frappe.model.set_value( + credit_row.doctype, + credit_row.name, + "credit_in_account_currency", + values.debit + ); frm.save(); @@ -562,33 +632,33 @@ $.extend(erpnext.journal_entry, { dialog.show(); }, - account_query: function(frm) { + account_query: function (frm) { var filters = { company: frm.doc.company, - is_group: 0 + is_group: 0, }; - if(!frm.doc.multi_currency) { + if (!frm.doc.multi_currency) { $.extend(filters, { - account_currency: frappe.get_doc(":Company", frm.doc.company).default_currency + account_currency: frappe.get_doc(":Company", frm.doc.company).default_currency, }); } return { filters: filters }; }, - reverse_journal_entry: function() { + reverse_journal_entry: function () { frappe.model.open_mapped_doc({ method: "erpnext.accounts.doctype.journal_entry.journal_entry.make_reverse_journal_entry", - frm: cur_frm - }) + frm: cur_frm, + }); }, }); $.extend(erpnext.journal_entry, { - set_account_details: function(frm, dt, dn) { + set_account_details: function (frm, dt, dn) { var d = locals[dt][dn]; - if(d.account) { - if(!frm.doc.company) frappe.throw(__("Please select Company first")); - if(!frm.doc.posting_date) frappe.throw(__("Please select Posting Date first")); + if (d.account) { + if (!frm.doc.company) frappe.throw(__("Please select Company first")); + if (!frm.doc.posting_date) frappe.throw(__("Please select Posting Date first")); return frappe.call({ method: "erpnext.accounts.doctype.journal_entry.journal_entry.get_account_details_and_party_type", @@ -600,13 +670,13 @@ $.extend(erpnext.journal_entry, { credit: flt(d.credit_in_account_currency), exchange_rate: d.exchange_rate, }, - callback: function(r) { - if(r.message) { + callback: function (r) { + if (r.message) { $.extend(d, r.message); erpnext.journal_entry.set_debit_credit_in_company_currency(frm, dt, dn); - refresh_field('accounts'); + refresh_field("accounts"); } - } + }, }); } }, diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry_list.js b/erpnext/accounts/doctype/journal_entry/journal_entry_list.js index 48d6115e3dfa..9d6e87392e54 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry_list.js +++ b/erpnext/accounts/doctype/journal_entry/journal_entry_list.js @@ -1,12 +1,12 @@ -frappe.listview_settings['Journal Entry'] = { +frappe.listview_settings["Journal Entry"] = { add_fields: ["voucher_type", "posting_date", "total_debit", "company", "user_remark"], - get_indicator: function(doc) { - if(doc.docstatus==0) { - return [__("Draft", "red", "docstatus,=,0")] - } else if(doc.docstatus==2) { - return [__("Cancelled", "grey", "docstatus,=,2")] + get_indicator: function (doc) { + if (doc.docstatus == 0) { + return [__("Draft", "red", "docstatus,=,0")]; + } else if (doc.docstatus == 2) { + return [__("Cancelled", "grey", "docstatus,=,2")]; } else { - return [__(doc.voucher_type), "blue", "voucher_type,=," + doc.voucher_type] + return [__(doc.voucher_type), "blue", "voucher_type,=," + doc.voucher_type]; } - } + }, }; diff --git a/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js b/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js index 5ebdf61db2ce..9a526af4eb49 100644 --- a/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js +++ b/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js @@ -2,78 +2,82 @@ // For license information, please see license.txt frappe.ui.form.on("Journal Entry Template", { - onload: function(frm) { - if(frm.is_new()) { + onload: function (frm) { + if (frm.is_new()) { frappe.call({ type: "GET", method: "erpnext.accounts.doctype.journal_entry_template.journal_entry_template.get_naming_series", - callback: function(r){ - if(r.message) { + callback: function (r) { + if (r.message) { frm.set_df_property("naming_series", "options", r.message.split("\n")); frm.set_value("naming_series", r.message.split("\n")[0]); frm.refresh_field("naming_series"); } - } + }, }); } }, - refresh: function(frm) { + refresh: function (frm) { frappe.model.set_default_values(frm.doc); - frm.set_query("account" ,"accounts", function(){ + frm.set_query("account", "accounts", function () { var filters = { company: frm.doc.company, - is_group: 0 + is_group: 0, }; - if(!frm.doc.multi_currency) { + if (!frm.doc.multi_currency) { $.extend(filters, { - account_currency: frappe.get_doc(":Company", frm.doc.company).default_currency + account_currency: frappe.get_doc(":Company", frm.doc.company).default_currency, }); } return { filters: filters }; }); }, - voucher_type: function(frm) { - var add_accounts = function(doc, r) { - $.each(r, function(i, d) { + voucher_type: function (frm) { + var add_accounts = function (doc, r) { + $.each(r, function (i, d) { var row = frappe.model.add_child(doc, "Journal Entry Template Account", "accounts"); row.account = d.account; }); refresh_field("accounts"); }; - if(!frm.doc.company) return; + if (!frm.doc.company) return; frm.trigger("clear_child"); - switch(frm.doc.voucher_type){ + switch (frm.doc.voucher_type) { case "Bank Entry": case "Cash Entry": frappe.call({ type: "GET", method: "erpnext.accounts.doctype.journal_entry.journal_entry.get_default_bank_cash_account", args: { - "account_type": (frm.doc.voucher_type=="Bank Entry" ? - "Bank" : (frm.doc.voucher_type=="Cash Entry" ? "Cash" : null)), - "company": frm.doc.company + account_type: + frm.doc.voucher_type == "Bank Entry" + ? "Bank" + : frm.doc.voucher_type == "Cash Entry" + ? "Cash" + : null, + company: frm.doc.company, }, - callback: function(r) { - if(r.message) { + callback: function (r) { + if (r.message) { // If default company bank account not set - if(!$.isEmptyObject(r.message)){ + if (!$.isEmptyObject(r.message)) { add_accounts(frm.doc, [r.message]); } } - } + }, }); break; default: frm.trigger("clear_child"); } }, - clear_child: function(frm){ + clear_child: function (frm) { frappe.model.clear_table(frm.doc, "accounts"); frm.refresh_field("accounts"); - } + }, }); diff --git a/erpnext/accounts/doctype/ledger_merge/ledger_merge.js b/erpnext/accounts/doctype/ledger_merge/ledger_merge.js index b2db98dbd035..6faae84447bd 100644 --- a/erpnext/accounts/doctype/ledger_merge/ledger_merge.js +++ b/erpnext/accounts/doctype/ledger_merge/ledger_merge.js @@ -1,9 +1,9 @@ // Copyright (c) 2021, Wahni Green Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Ledger Merge', { - setup: function(frm) { - frappe.realtime.on('ledger_merge_refresh', ({ ledger_merge }) => { +frappe.ui.form.on("Ledger Merge", { + setup: function (frm) { + frappe.realtime.on("ledger_merge_refresh", ({ ledger_merge }) => { if (ledger_merge !== frm.doc.name) return; frappe.model.clear_doc(frm.doc.doctype, frm.doc.name); frappe.model.with_doc(frm.doc.doctype, frm.doc.name).then(() => { @@ -11,29 +11,29 @@ frappe.ui.form.on('Ledger Merge', { }); }); - frappe.realtime.on('ledger_merge_progress', data => { + frappe.realtime.on("ledger_merge_progress", (data) => { if (data.ledger_merge !== frm.doc.name) return; - let message = __('Merging {0} of {1}', [data.current, data.total]); + let message = __("Merging {0} of {1}", [data.current, data.total]); let percent = Math.floor((data.current * 100) / data.total); - frm.dashboard.show_progress(__('Merge Progress'), percent, message); - frm.page.set_indicator(__('In Progress'), 'orange'); + frm.dashboard.show_progress(__("Merge Progress"), percent, message); + frm.page.set_indicator(__("In Progress"), "orange"); }); - frm.set_query("account", function(doc) { - if (!doc.company) frappe.throw(__('Please set Company')); - if (!doc.root_type) frappe.throw(__('Please set Root Type')); + frm.set_query("account", function (doc) { + if (!doc.company) frappe.throw(__("Please set Company")); + if (!doc.root_type) frappe.throw(__("Please set Root Type")); return { filters: { root_type: doc.root_type, - company: doc.company - } + company: doc.company, + }, }; }); - frm.set_query('account', 'merge_accounts', function(doc) { - if (!doc.company) frappe.throw(__('Please set Company')); - if (!doc.root_type) frappe.throw(__('Please set Root Type')); - if (!doc.account) frappe.throw(__('Please set Account')); + frm.set_query("account", "merge_accounts", function (doc) { + if (!doc.company) frappe.throw(__("Please set Company")); + if (!doc.root_type) frappe.throw(__("Please set Root Type")); + if (!doc.account) frappe.throw(__("Please set Account")); let acc = [doc.account]; frm.doc.merge_accounts.forEach((row) => { acc.push(row.account); @@ -43,86 +43,86 @@ frappe.ui.form.on('Ledger Merge', { is_group: doc.is_group, root_type: doc.root_type, name: ["not in", acc], - company: doc.company - } + company: doc.company, + }, }; }); }, - refresh: function(frm) { + refresh: function (frm) { frm.page.hide_icon_group(); - frm.trigger('set_merge_status'); - frm.trigger('update_primary_action'); + frm.trigger("set_merge_status"); + frm.trigger("update_primary_action"); }, - after_save: function(frm) { + after_save: function (frm) { setTimeout(() => { - frm.trigger('update_primary_action'); + frm.trigger("update_primary_action"); }, 500); }, - update_primary_action: function(frm) { + update_primary_action: function (frm) { if (frm.is_dirty()) { frm.enable_save(); return; } frm.disable_save(); - if (frm.doc.status !== 'Success') { + if (frm.doc.status !== "Success") { if (!frm.is_new()) { - let label = frm.doc.status === 'Pending' ? __('Start Merge') : __('Retry'); + let label = frm.doc.status === "Pending" ? __("Start Merge") : __("Retry"); frm.page.set_primary_action(label, () => frm.events.start_merge(frm)); } else { - frm.page.set_primary_action(__('Save'), () => frm.save()); + frm.page.set_primary_action(__("Save"), () => frm.save()); } } }, - start_merge: function(frm) { + start_merge: function (frm) { frm.call({ - method: 'form_start_merge', + method: "form_start_merge", args: { docname: frm.doc.name }, - btn: frm.page.btn_primary - }).then(r => { + btn: frm.page.btn_primary, + }).then((r) => { if (r.message === true) { frm.disable_save(); } }); }, - set_merge_status: function(frm) { + set_merge_status: function (frm) { if (frm.doc.status == "Pending") return; let successful_records = 0; frm.doc.merge_accounts.forEach((row) => { if (row.merged) successful_records += 1; }); let message_args = [successful_records, frm.doc.merge_accounts.length]; - frm.dashboard.set_headline(__('Successfully merged {0} out of {1}.', message_args)); + frm.dashboard.set_headline(__("Successfully merged {0} out of {1}.", message_args)); }, - root_type: function(frm) { - frm.set_value('account', ''); - frm.set_value('merge_accounts', []); + root_type: function (frm) { + frm.set_value("account", ""); + frm.set_value("merge_accounts", []); }, - company: function(frm) { - frm.set_value('account', ''); - frm.set_value('merge_accounts', []); - } + company: function (frm) { + frm.set_value("account", ""); + frm.set_value("merge_accounts", []); + }, }); -frappe.ui.form.on('Ledger Merge Accounts', { - merge_accounts_add: function(frm) { - frm.trigger('update_primary_action'); +frappe.ui.form.on("Ledger Merge Accounts", { + merge_accounts_add: function (frm) { + frm.trigger("update_primary_action"); }, - merge_accounts_remove: function(frm) { - frm.trigger('update_primary_action'); + merge_accounts_remove: function (frm) { + frm.trigger("update_primary_action"); }, - account: function(frm, cdt, cdn) { + account: function (frm, cdt, cdn) { let row = frappe.get_doc(cdt, cdn); row.account_name = row.account; - frm.refresh_field('merge_accounts'); - frm.trigger('update_primary_action'); - } + frm.refresh_field("merge_accounts"); + frm.trigger("update_primary_action"); + }, }); diff --git a/erpnext/accounts/doctype/loyalty_point_entry/loyalty_point_entry.js b/erpnext/accounts/doctype/loyalty_point_entry/loyalty_point_entry.js index d7dc7f3f3c7c..d522f6d8af1f 100644 --- a/erpnext/accounts/doctype/loyalty_point_entry/loyalty_point_entry.js +++ b/erpnext/accounts/doctype/loyalty_point_entry/loyalty_point_entry.js @@ -1,8 +1,6 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Loyalty Point Entry', { - refresh: function(frm) { - - } +frappe.ui.form.on("Loyalty Point Entry", { + refresh: function (frm) {}, }); diff --git a/erpnext/accounts/doctype/loyalty_program/loyalty_program.js b/erpnext/accounts/doctype/loyalty_program/loyalty_program.js index 6951b2a2b32f..4c29be3b5562 100644 --- a/erpnext/accounts/doctype/loyalty_program/loyalty_program.js +++ b/erpnext/accounts/doctype/loyalty_program/loyalty_program.js @@ -3,30 +3,37 @@ frappe.provide("erpnext.accounts.dimensions"); -frappe.ui.form.on('Loyalty Program', { - setup: function(frm) { - var help_content = - ` +frappe.ui.form.on("Loyalty Program", { + setup: function (frm) { + var help_content = `
    + let table_footer = + hidden_logs && hidden_logs.length > 0 + ? ` - `: ""; + ` + : ""; if (field === "fixed_error_log_preview") { rows_head = ` - ` - table_caption = "Resolved Issues" + `; + table_caption = "Resolved Issues"; } else { rows_head = ` - ` - table_caption = "Error Log" + `; + table_caption = "Error Log"; } frm.get_field(field).$wrapper.html(` @@ -144,7 +152,7 @@ frappe.ui.form.on("Tally Migration", { summary[row.doc.doctype] = 1; } } - return summary + return summary; }, {}); console.table(summary); }, @@ -177,7 +185,7 @@ frappe.ui.form.on("Tally Migration", { let hidden_logs = completed_log.slice(20); frm.events.render_html_table(frm, logs, hidden_logs, "fixed_error_log_preview"); - } + }, }); erpnext.tally_migration.getError = (traceback) => { @@ -186,31 +194,33 @@ erpnext.tally_migration.getError = (traceback) => { let message; if (is_multiline) { - let exc_error_idx = traceback.trim().lastIndexOf("\n") + 1 - let error_line = traceback.substr(exc_error_idx) - let split_str_idx = (error_line.indexOf(':') > 0) ? error_line.indexOf(':') + 1 : 0; + let exc_error_idx = traceback.trim().lastIndexOf("\n") + 1; + let error_line = traceback.substr(exc_error_idx); + let split_str_idx = error_line.indexOf(":") > 0 ? error_line.indexOf(":") + 1 : 0; message = error_line.slice(split_str_idx).trim(); } else { message = traceback; } - return message -} + return message; +}; erpnext.tally_migration.cleanDoc = (obj) => { /* Strips all null and empty values of your JSON object */ let temp = obj; - $.each(temp, function(key, value){ - if (value === "" || value === null){ + $.each(temp, function (key, value) { + if (value === "" || value === null) { delete obj[key]; - } else if (Object.prototype.toString.call(value) === '[object Object]') { + } else if (Object.prototype.toString.call(value) === "[object Object]") { erpnext.tally_migration.cleanDoc(value); } else if ($.isArray(value)) { - $.each(value, function (k,v) { erpnext.tally_migration.cleanDoc(v); }); + $.each(value, function (k, v) { + erpnext.tally_migration.cleanDoc(v); + }); } }); return temp; -} +}; erpnext.tally_migration.unresolve = (document) => { /* Mark document migration as unresolved ie. move to failed error log */ @@ -218,9 +228,9 @@ erpnext.tally_migration.unresolve = (document) => { let failed_log = erpnext.tally_migration.failed_import_log; let fixed_log = erpnext.tally_migration.fixed_errors_log; - let modified_fixed_log = fixed_log.filter(row => { + let modified_fixed_log = fixed_log.filter((row) => { if (!frappe.utils.deep_equal(erpnext.tally_migration.cleanDoc(row.doc), document)) { - return row + return row; } }); @@ -231,7 +241,7 @@ erpnext.tally_migration.unresolve = (document) => { frm.dirty(); frm.save(); -} +}; erpnext.tally_migration.resolve = (document) => { /* Mark document migration as resolved ie. move to fixed error log */ @@ -239,9 +249,9 @@ erpnext.tally_migration.resolve = (document) => { let failed_log = erpnext.tally_migration.failed_import_log; let fixed_log = erpnext.tally_migration.fixed_errors_log; - let modified_failed_log = failed_log.filter(row => { + let modified_failed_log = failed_log.filter((row) => { if (!frappe.utils.deep_equal(erpnext.tally_migration.cleanDoc(row.doc), document)) { - return row + return row; } }); fixed_log.push({ doc: document, exc: `Solved on ${Date()}` }); @@ -251,27 +261,27 @@ erpnext.tally_migration.resolve = (document) => { frm.dirty(); frm.save(); -} +}; erpnext.tally_migration.create_new_doc = (document) => { /* Mark as resolved and create new document */ erpnext.tally_migration.resolve(document); return frappe.call({ type: "POST", - method: 'erpnext.erpnext_integrations.doctype.tally_migration.tally_migration.new_doc', + method: "erpnext.erpnext_integrations.doctype.tally_migration.tally_migration.new_doc", args: { - document + document, }, freeze: true, - callback: function(r) { - if(!r.exc) { + callback: function (r) { + if (!r.exc) { frappe.model.sync(r.message); frappe.get_doc(r.message.doctype, r.message.name).__run_link_triggers = true; frappe.set_route("Form", r.message.doctype, r.message.name); } - } + }, }); -} +}; erpnext.tally_migration.get_html_rows = (logs, field) => { let index = 0; @@ -304,14 +314,18 @@ erpnext.tally_migration.get_html_rows = (logs, field) => { `; let create_button = ` - ` + `; let mark_as_unresolved = ` - ` + `; if (field === "fixed_error_log_preview") { return ` @@ -343,7 +357,8 @@ erpnext.tally_migration.get_html_rows = (logs, field) => { `; } - }).join(""); + }) + .join(""); - return rows -} + return rows; +}; diff --git a/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.js b/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.js index 2925db82e330..eb944d9f2797 100644 --- a/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.js +++ b/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.js @@ -1,37 +1,35 @@ // Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('TaxJar Settings', { +frappe.ui.form.on("TaxJar Settings", { is_sandbox: (frm) => { frm.toggle_reqd("api_key", !frm.doc.is_sandbox); frm.toggle_reqd("sandbox_api_key", frm.doc.is_sandbox); }, on_load: (frm) => { - frm.set_query('shipping_account_head', function() { + frm.set_query("shipping_account_head", function () { return { filters: { - 'company': frm.doc.company - } + company: frm.doc.company, + }, }; }); - frm.set_query('tax_account_head', function() { + frm.set_query("tax_account_head", function () { return { filters: { - 'company': frm.doc.company - } + company: frm.doc.company, + }, }; }); }, refresh: (frm) => { - frm.add_custom_button(__('Update Nexus List'), function() { + frm.add_custom_button(__("Update Nexus List"), function () { frm.call({ doc: frm.doc, - method: 'update_nexus_list' + method: "update_nexus_list", }); }); }, - - }); diff --git a/erpnext/erpnext_integrations/doctype/woocommerce_settings/woocommerce_settings.js b/erpnext/erpnext_integrations/doctype/woocommerce_settings/woocommerce_settings.js index d7a3d36a5f13..dc3941b30731 100644 --- a/erpnext/erpnext_integrations/doctype/woocommerce_settings/woocommerce_settings.js +++ b/erpnext/erpnext_integrations/doctype/woocommerce_settings/woocommerce_settings.js @@ -1,47 +1,47 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Woocommerce Settings', { - refresh (frm) { +frappe.ui.form.on("Woocommerce Settings", { + refresh(frm) { frm.trigger("add_button_generate_secret"); frm.trigger("check_enabled"); - frm.set_query("tax_account", ()=>{ + frm.set_query("tax_account", () => { return { - "filters": { - "company": frappe.defaults.get_default("company"), - "is_group": 0 - } + filters: { + company: frappe.defaults.get_default("company"), + is_group: 0, + }, }; }); }, - enable_sync (frm) { + enable_sync(frm) { frm.trigger("check_enabled"); }, add_button_generate_secret(frm) { - frm.add_custom_button(__('Generate Secret'), () => { - frappe.confirm( - __("Apps using current key won't be able to access, are you sure?"), - () => { - frappe.call({ - type:"POST", - method:"erpnext.erpnext_integrations.doctype.woocommerce_settings.woocommerce_settings.generate_secret", - }).done(() => { + frm.add_custom_button(__("Generate Secret"), () => { + frappe.confirm(__("Apps using current key won't be able to access, are you sure?"), () => { + frappe + .call({ + type: "POST", + method: "erpnext.erpnext_integrations.doctype.woocommerce_settings.woocommerce_settings.generate_secret", + }) + .done(() => { frm.reload_doc(); - }).fail(() => { + }) + .fail(() => { frappe.msgprint(__("Could not generate Secret")); }); - } - ); + }); }); }, - check_enabled (frm) { + check_enabled(frm) { frm.set_df_property("woocommerce_server_url", "reqd", frm.doc.enable_sync); frm.set_df_property("api_consumer_key", "reqd", frm.doc.enable_sync); frm.set_df_property("api_consumer_secret", "reqd", frm.doc.enable_sync); - } + }, }); frappe.ui.form.on("Woocommerce Settings", "onload", function () { @@ -51,6 +51,6 @@ frappe.ui.form.on("Woocommerce Settings", "onload", function () { $.each(r.message, function (key, value) { set_field_options(key, value); }); - } + }, }); }); diff --git a/erpnext/loan_management/dashboard_chart_source/top_10_pledged_loan_securities/top_10_pledged_loan_securities.js b/erpnext/loan_management/dashboard_chart_source/top_10_pledged_loan_securities/top_10_pledged_loan_securities.js index 58179416b1ad..1ea336456317 100644 --- a/erpnext/loan_management/dashboard_chart_source/top_10_pledged_loan_securities/top_10_pledged_loan_securities.js +++ b/erpnext/loan_management/dashboard_chart_source/top_10_pledged_loan_securities/top_10_pledged_loan_securities.js @@ -1,4 +1,4 @@ -frappe.provide('frappe.dashboards.chart_sources'); +frappe.provide("frappe.dashboards.chart_sources"); frappe.dashboards.chart_sources["Top 10 Pledged Loan Securities"] = { method: "erpnext.loan_management.dashboard_chart_source.top_10_pledged_loan_securities.top_10_pledged_loan_securities.get_data", @@ -8,7 +8,7 @@ frappe.dashboards.chart_sources["Top 10 Pledged Loan Securities"] = { label: __("Company"), fieldtype: "Link", options: "Company", - default: frappe.defaults.get_user_default("Company") - } - ] + default: frappe.defaults.get_user_default("Company"), + }, + ], }; diff --git a/erpnext/loan_management/doctype/loan/loan_list.js b/erpnext/loan_management/doctype/loan/loan_list.js index 6591b7299680..ac011627377d 100644 --- a/erpnext/loan_management/doctype/loan/loan_list.js +++ b/erpnext/loan_management/doctype/loan/loan_list.js @@ -1,16 +1,16 @@ // Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -frappe.listview_settings['Loan'] = { - get_indicator: function(doc) { +frappe.listview_settings["Loan"] = { + get_indicator: function (doc) { var status_color = { - "Draft": "red", - "Sanctioned": "blue", - "Disbursed": "orange", + Draft: "red", + Sanctioned: "blue", + Disbursed: "orange", "Partially Disbursed": "yellow", "Loan Closure Requested": "green", - "Closed": "green" + Closed: "green", }; - return [__(doc.status), status_color[doc.status], "status,=,"+doc.status]; + return [__(doc.status), status_color[doc.status], "status,=," + doc.status]; }, }; diff --git a/erpnext/loan_management/doctype/loan_balance_adjustment/loan_balance_adjustment.js b/erpnext/loan_management/doctype/loan_balance_adjustment/loan_balance_adjustment.js index 8aec63ad75fa..3042c6c7aeee 100644 --- a/erpnext/loan_management/doctype/loan_balance_adjustment/loan_balance_adjustment.js +++ b/erpnext/loan_management/doctype/loan_balance_adjustment/loan_balance_adjustment.js @@ -1,8 +1,7 @@ // Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Loan Balance Adjustment', { +frappe.ui.form.on("Loan Balance Adjustment", { // refresh: function(frm) { - // } }); diff --git a/erpnext/loan_management/doctype/loan_refund/loan_refund.js b/erpnext/loan_management/doctype/loan_refund/loan_refund.js index f108bf7a2814..c507aa5abaa0 100644 --- a/erpnext/loan_management/doctype/loan_refund/loan_refund.js +++ b/erpnext/loan_management/doctype/loan_refund/loan_refund.js @@ -1,8 +1,7 @@ // Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Loan Refund', { +frappe.ui.form.on("Loan Refund", { // refresh: function(frm) { - // } }); diff --git a/erpnext/loan_management/doctype/loan_security/loan_security.js b/erpnext/loan_management/doctype/loan_security/loan_security.js index 0e815af76a04..9db3a33bd2d3 100644 --- a/erpnext/loan_management/doctype/loan_security/loan_security.js +++ b/erpnext/loan_management/doctype/loan_security/loan_security.js @@ -1,8 +1,7 @@ // Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Loan Security', { +frappe.ui.form.on("Loan Security", { // refresh: function(frm) { - // } }); diff --git a/erpnext/loan_management/doctype/loan_security_pledge/loan_security_pledge.js b/erpnext/loan_management/doctype/loan_security_pledge/loan_security_pledge.js index 48ca392edf75..be9089974873 100644 --- a/erpnext/loan_management/doctype/loan_security_pledge/loan_security_pledge.js +++ b/erpnext/loan_management/doctype/loan_security_pledge/loan_security_pledge.js @@ -1,43 +1,48 @@ // Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Loan Security Pledge', { - calculate_amounts: function(frm, cdt, cdn) { +frappe.ui.form.on("Loan Security Pledge", { + calculate_amounts: function (frm, cdt, cdn) { let row = locals[cdt][cdn]; - frappe.model.set_value(cdt, cdn, 'amount', row.qty * row.loan_security_price); - frappe.model.set_value(cdt, cdn, 'post_haircut_amount', cint(row.amount - (row.amount * row.haircut/100))); + frappe.model.set_value(cdt, cdn, "amount", row.qty * row.loan_security_price); + frappe.model.set_value( + cdt, + cdn, + "post_haircut_amount", + cint(row.amount - (row.amount * row.haircut) / 100) + ); let amount = 0; let maximum_amount = 0; - $.each(frm.doc.securities || [], function(i, item){ + $.each(frm.doc.securities || [], function (i, item) { amount += item.amount; maximum_amount += item.post_haircut_amount; }); - frm.set_value('total_security_value', amount); - frm.set_value('maximum_loan_value', maximum_amount); - } + frm.set_value("total_security_value", amount); + frm.set_value("maximum_loan_value", maximum_amount); + }, }); frappe.ui.form.on("Pledge", { - loan_security: function(frm, cdt, cdn) { + loan_security: function (frm, cdt, cdn) { let row = locals[cdt][cdn]; if (row.loan_security) { frappe.call({ method: "erpnext.loan_management.doctype.loan_security_price.loan_security_price.get_loan_security_price", args: { - loan_security: row.loan_security + loan_security: row.loan_security, }, - callback: function(r) { - frappe.model.set_value(cdt, cdn, 'loan_security_price', r.message); + callback: function (r) { + frappe.model.set_value(cdt, cdn, "loan_security_price", r.message); frm.events.calculate_amounts(frm, cdt, cdn); - } + }, }); } }, - qty: function(frm, cdt, cdn) { + qty: function (frm, cdt, cdn) { frm.events.calculate_amounts(frm, cdt, cdn); }, }); diff --git a/erpnext/loan_management/doctype/loan_security_pledge/loan_security_pledge_list.js b/erpnext/loan_management/doctype/loan_security_pledge/loan_security_pledge_list.js index 174d1b0d62b8..c8f36ec5eeeb 100644 --- a/erpnext/loan_management/doctype/loan_security_pledge/loan_security_pledge_list.js +++ b/erpnext/loan_management/doctype/loan_security_pledge/loan_security_pledge_list.js @@ -2,14 +2,14 @@ // License: GNU General Public License v3. See license.txt // render -frappe.listview_settings['Loan Security Pledge'] = { +frappe.listview_settings["Loan Security Pledge"] = { add_fields: ["status"], - get_indicator: function(doc) { + get_indicator: function (doc) { var status_color = { - "Unpledged": "orange", - "Pledged": "green", - "Partially Pledged": "green" + Unpledged: "orange", + Pledged: "green", + "Partially Pledged": "green", }; - return [__(doc.status), status_color[doc.status], "status,=,"+doc.status]; - } + return [__(doc.status), status_color[doc.status], "status,=," + doc.status]; + }, }; diff --git a/erpnext/loan_management/doctype/loan_security_price/loan_security_price.js b/erpnext/loan_management/doctype/loan_security_price/loan_security_price.js index 31b4ec7249ea..b79ccb51e373 100644 --- a/erpnext/loan_management/doctype/loan_security_price/loan_security_price.js +++ b/erpnext/loan_management/doctype/loan_security_price/loan_security_price.js @@ -1,8 +1,7 @@ // Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Loan Security Price', { +frappe.ui.form.on("Loan Security Price", { // refresh: function(frm) { - // } }); diff --git a/erpnext/loan_management/doctype/loan_security_shortfall/loan_security_shortfall.js b/erpnext/loan_management/doctype/loan_security_shortfall/loan_security_shortfall.js index f26c138371e0..504a5d9748aa 100644 --- a/erpnext/loan_management/doctype/loan_security_shortfall/loan_security_shortfall.js +++ b/erpnext/loan_management/doctype/loan_security_shortfall/loan_security_shortfall.js @@ -1,25 +1,25 @@ // Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Loan Security Shortfall', { - refresh: function(frm) { - frm.add_custom_button(__("Add Loan Security"), function() { - frm.trigger('shortfall_action'); +frappe.ui.form.on("Loan Security Shortfall", { + refresh: function (frm) { + frm.add_custom_button(__("Add Loan Security"), function () { + frm.trigger("shortfall_action"); }); }, - shortfall_action: function(frm) { + shortfall_action: function (frm) { frappe.call({ method: "erpnext.loan_management.doctype.loan_security_shortfall.loan_security_shortfall.add_security", args: { - 'loan': frm.doc.loan + loan: frm.doc.loan, }, - callback: function(r) { + callback: function (r) { if (r.message) { let doc = frappe.model.sync(r.message)[0]; frappe.set_route("Form", doc.doctype, doc.name); } - } + }, }); - } + }, }); diff --git a/erpnext/loan_management/doctype/loan_security_type/loan_security_type.js b/erpnext/loan_management/doctype/loan_security_type/loan_security_type.js index 3a1e0689c1da..5e277d3d6ba8 100644 --- a/erpnext/loan_management/doctype/loan_security_type/loan_security_type.js +++ b/erpnext/loan_management/doctype/loan_security_type/loan_security_type.js @@ -1,8 +1,7 @@ // Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Loan Security Type', { +frappe.ui.form.on("Loan Security Type", { // refresh: function(frm) { - // }, }); diff --git a/erpnext/loan_management/doctype/loan_security_unpledge/loan_security_unpledge.js b/erpnext/loan_management/doctype/loan_security_unpledge/loan_security_unpledge.js index 822320627741..b6803e00de93 100644 --- a/erpnext/loan_management/doctype/loan_security_unpledge/loan_security_unpledge.js +++ b/erpnext/loan_management/doctype/loan_security_unpledge/loan_security_unpledge.js @@ -1,11 +1,10 @@ // Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Loan Security Unpledge', { - refresh: function(frm) { - - if (frm.doc.docstatus == 1 && frm.doc.status == 'Approved') { - frm.set_df_property('status', 'read_only', 1); +frappe.ui.form.on("Loan Security Unpledge", { + refresh: function (frm) { + if (frm.doc.docstatus == 1 && frm.doc.status == "Approved") { + frm.set_df_property("status", "read_only", 1); } - } + }, }); diff --git a/erpnext/loan_management/doctype/loan_security_unpledge/loan_security_unpledge_list.js b/erpnext/loan_management/doctype/loan_security_unpledge/loan_security_unpledge_list.js index 196ebbb96add..52624fa14365 100644 --- a/erpnext/loan_management/doctype/loan_security_unpledge/loan_security_unpledge_list.js +++ b/erpnext/loan_management/doctype/loan_security_unpledge/loan_security_unpledge_list.js @@ -2,13 +2,13 @@ // License: GNU General Public License v3. See license.txt // render -frappe.listview_settings['Loan Security Unpledge'] = { +frappe.listview_settings["Loan Security Unpledge"] = { add_fields: ["status"], - get_indicator: function(doc) { + get_indicator: function (doc) { var status_color = { - "Requested": "orange", - "Approved": "green", + Requested: "orange", + Approved: "green", }; - return [__(doc.status), status_color[doc.status], "status,=,"+doc.status]; - } + return [__(doc.status), status_color[doc.status], "status,=," + doc.status]; + }, }; diff --git a/erpnext/loan_management/doctype/loan_type/loan_type.js b/erpnext/loan_management/doctype/loan_type/loan_type.js index 9f9137cfbcde..bb0bd8106f96 100644 --- a/erpnext/loan_management/doctype/loan_type/loan_type.js +++ b/erpnext/loan_management/doctype/loan_type/loan_type.js @@ -1,16 +1,16 @@ // Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Loan Type', { - onload: function(frm) { +frappe.ui.form.on("Loan Type", { + onload: function (frm) { $.each(["penalty_income_account", "interest_income_account"], function (i, field) { frm.set_query(field, function () { return { - "filters": { - "company": frm.doc.company, - "root_type": "Income", - "is_group": 0 - } + filters: { + company: frm.doc.company, + root_type: "Income", + is_group: 0, + }, }; }); }); @@ -18,13 +18,13 @@ frappe.ui.form.on('Loan Type', { $.each(["payment_account", "loan_account", "disbursement_account"], function (i, field) { frm.set_query(field, function () { return { - "filters": { - "company": frm.doc.company, - "root_type": "Asset", - "is_group": 0 - } + filters: { + company: frm.doc.company, + root_type: "Asset", + is_group: 0, + }, }; }); }); - } + }, }); diff --git a/erpnext/loan_management/doctype/pledge/pledge.js b/erpnext/loan_management/doctype/pledge/pledge.js index fb6ab1077828..faee76dbd3ad 100644 --- a/erpnext/loan_management/doctype/pledge/pledge.js +++ b/erpnext/loan_management/doctype/pledge/pledge.js @@ -1,8 +1,7 @@ // Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Pledge', { +frappe.ui.form.on("Pledge", { // refresh: function(frm) { - // } }); diff --git a/erpnext/loan_management/doctype/process_loan_interest_accrual/process_loan_interest_accrual.js b/erpnext/loan_management/doctype/process_loan_interest_accrual/process_loan_interest_accrual.js index c596be2d2a8b..45cc07344d85 100644 --- a/erpnext/loan_management/doctype/process_loan_interest_accrual/process_loan_interest_accrual.js +++ b/erpnext/loan_management/doctype/process_loan_interest_accrual/process_loan_interest_accrual.js @@ -1,8 +1,7 @@ // Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Process Loan Interest Accrual', { +frappe.ui.form.on("Process Loan Interest Accrual", { // refresh: function(frm) { - // } }); diff --git a/erpnext/loan_management/doctype/process_loan_security_shortfall/process_loan_security_shortfall.js b/erpnext/loan_management/doctype/process_loan_security_shortfall/process_loan_security_shortfall.js index 645e3ada9a8b..5ac98af15e39 100644 --- a/erpnext/loan_management/doctype/process_loan_security_shortfall/process_loan_security_shortfall.js +++ b/erpnext/loan_management/doctype/process_loan_security_shortfall/process_loan_security_shortfall.js @@ -1,8 +1,8 @@ // Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Process Loan Security Shortfall', { - onload: function(frm) { - frm.set_value('update_time', frappe.datetime.now_datetime()); - } +frappe.ui.form.on("Process Loan Security Shortfall", { + onload: function (frm) { + frm.set_value("update_time", frappe.datetime.now_datetime()); + }, }); diff --git a/erpnext/loan_management/doctype/sanctioned_loan_amount/sanctioned_loan_amount.js b/erpnext/loan_management/doctype/sanctioned_loan_amount/sanctioned_loan_amount.js index 5361e7ca2a59..af647d974bf6 100644 --- a/erpnext/loan_management/doctype/sanctioned_loan_amount/sanctioned_loan_amount.js +++ b/erpnext/loan_management/doctype/sanctioned_loan_amount/sanctioned_loan_amount.js @@ -1,8 +1,7 @@ // Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Sanctioned Loan Amount', { +frappe.ui.form.on("Sanctioned Loan Amount", { // refresh: function(frm) { - // } }); diff --git a/erpnext/loan_management/loan_common.js b/erpnext/loan_management/loan_common.js index 247e30b84393..72f40c5700fe 100644 --- a/erpnext/loan_management/loan_common.js +++ b/erpnext/loan_management/loan_common.js @@ -2,37 +2,42 @@ // For license information, please see license.txt frappe.ui.form.on(cur_frm.doctype, { - refresh: function(frm) { - if (['Loan Disbursement', 'Loan Repayment', 'Loan Interest Accrual', 'Loan Write Off'].includes(frm.doc.doctype) - && frm.doc.docstatus > 0) { + refresh: function (frm) { + if ( + ["Loan Disbursement", "Loan Repayment", "Loan Interest Accrual", "Loan Write Off"].includes( + frm.doc.doctype + ) && + frm.doc.docstatus > 0 + ) { + frm.add_custom_button( + __("Accounting Ledger"), + function () { + frappe.route_options = { + voucher_no: frm.doc.name, + company: frm.doc.company, + from_date: moment(frm.doc.posting_date).format("YYYY-MM-DD"), + to_date: moment(frm.doc.modified).format("YYYY-MM-DD"), + show_cancelled_entries: frm.doc.docstatus === 2, + }; - frm.add_custom_button(__("Accounting Ledger"), function() { - frappe.route_options = { - voucher_no: frm.doc.name, - company: frm.doc.company, - from_date: moment(frm.doc.posting_date).format('YYYY-MM-DD'), - to_date: moment(frm.doc.modified).format('YYYY-MM-DD'), - show_cancelled_entries: frm.doc.docstatus === 2 - }; - - frappe.set_route("query-report", "General Ledger"); - },__("View")); + frappe.set_route("query-report", "General Ledger"); + }, + __("View") + ); } }, - applicant: function(frm) { + applicant: function (frm) { if (!["Loan Application", "Loan"].includes(frm.doc.doctype)) { return; } if (frm.doc.applicant) { - frappe.model.with_doc(frm.doc.applicant_type, frm.doc.applicant, function() { + frappe.model.with_doc(frm.doc.applicant_type, frm.doc.applicant, function () { var applicant = frappe.model.get_doc(frm.doc.applicant_type, frm.doc.applicant); - frm.set_value("applicant_name", - applicant.employee_name || applicant.member_name); + frm.set_value("applicant_name", applicant.employee_name || applicant.member_name); }); - } - else { + } else { frm.set_value("applicant_name", null); } - } + }, }); diff --git a/erpnext/loan_management/report/applicant_wise_loan_security_exposure/applicant_wise_loan_security_exposure.js b/erpnext/loan_management/report/applicant_wise_loan_security_exposure/applicant_wise_loan_security_exposure.js index 73d60c404588..c85fce0f380e 100644 --- a/erpnext/loan_management/report/applicant_wise_loan_security_exposure/applicant_wise_loan_security_exposure.js +++ b/erpnext/loan_management/report/applicant_wise_loan_security_exposure/applicant_wise_loan_security_exposure.js @@ -3,14 +3,14 @@ /* eslint-disable */ frappe.query_reports["Applicant-Wise Loan Security Exposure"] = { - "filters": [ + filters: [ { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_user_default("Company"), - "reqd": 1 - } - ] + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), + reqd: 1, + }, + ], }; diff --git a/erpnext/loan_management/report/loan_interest_report/loan_interest_report.js b/erpnext/loan_management/report/loan_interest_report/loan_interest_report.js index 458c79a1ea8f..53ff92fa1579 100644 --- a/erpnext/loan_management/report/loan_interest_report/loan_interest_report.js +++ b/erpnext/loan_management/report/loan_interest_report/loan_interest_report.js @@ -3,48 +3,48 @@ /* eslint-disable */ frappe.query_reports["Loan Interest Report"] = { - "filters": [ + filters: [ { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_user_default("Company"), - "reqd": 1 + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), + reqd: 1, }, { - "fieldname":"applicant_type", - "label": __("Applicant Type"), - "fieldtype": "Select", - "options": ["Customer", "Employee"], - "reqd": 1, - "default": "Customer", - on_change: function() { - frappe.query_report.set_filter_value('applicant', ""); - } + fieldname: "applicant_type", + label: __("Applicant Type"), + fieldtype: "Select", + options: ["Customer", "Employee"], + reqd: 1, + default: "Customer", + on_change: function () { + frappe.query_report.set_filter_value("applicant", ""); + }, }, { - "fieldname": "applicant", - "label": __("Applicant"), - "fieldtype": "Dynamic Link", - "get_options": function() { - var applicant_type = frappe.query_report.get_filter_value('applicant_type'); - var applicant = frappe.query_report.get_filter_value('applicant'); - if(applicant && !applicant_type) { + fieldname: "applicant", + label: __("Applicant"), + fieldtype: "Dynamic Link", + get_options: function () { + var applicant_type = frappe.query_report.get_filter_value("applicant_type"); + var applicant = frappe.query_report.get_filter_value("applicant"); + if (applicant && !applicant_type) { frappe.throw(__("Please select Applicant Type first")); } return applicant_type; - } + }, }, { - "fieldname":"from_date", - "label": __("From Date"), - "fieldtype": "Date", + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", }, { - "fieldname":"to_date", - "label": __("From Date"), - "fieldtype": "Date", + fieldname: "to_date", + label: __("From Date"), + fieldtype: "Date", }, - ] + ], }; diff --git a/erpnext/loan_management/report/loan_repayment_and_closure/loan_repayment_and_closure.js b/erpnext/loan_management/report/loan_repayment_and_closure/loan_repayment_and_closure.js index ed5e937c9964..0274715a3198 100644 --- a/erpnext/loan_management/report/loan_repayment_and_closure/loan_repayment_and_closure.js +++ b/erpnext/loan_management/report/loan_repayment_and_closure/loan_repayment_and_closure.js @@ -3,39 +3,38 @@ /* eslint-disable */ frappe.query_reports["Loan Repayment and Closure"] = { - "filters": [ + filters: [ { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "reqd": 1, - "default": frappe.defaults.get_user_default("Company") + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + reqd: 1, + default: frappe.defaults.get_user_default("Company"), }, { - "fieldname":"applicant_type", - "label": __("Applicant Type"), - "fieldtype": "Select", - "options": ["Customer", "Employee"], - "reqd": 1, - "default": "Customer", - on_change: function() { - frappe.query_report.set_filter_value('applicant', ""); - } + fieldname: "applicant_type", + label: __("Applicant Type"), + fieldtype: "Select", + options: ["Customer", "Employee"], + reqd: 1, + default: "Customer", + on_change: function () { + frappe.query_report.set_filter_value("applicant", ""); + }, }, { - "fieldname": "applicant", - "label": __("Applicant"), - "fieldtype": "Dynamic Link", - "get_options": function() { - var applicant_type = frappe.query_report.get_filter_value('applicant_type'); - var applicant = frappe.query_report.get_filter_value('applicant'); - if(applicant && !applicant_type) { + fieldname: "applicant", + label: __("Applicant"), + fieldtype: "Dynamic Link", + get_options: function () { + var applicant_type = frappe.query_report.get_filter_value("applicant_type"); + var applicant = frappe.query_report.get_filter_value("applicant"); + if (applicant && !applicant_type) { frappe.throw(__("Please select Applicant Type first")); } return applicant_type; - } - + }, }, - ] + ], }; diff --git a/erpnext/loan_management/report/loan_security_exposure/loan_security_exposure.js b/erpnext/loan_management/report/loan_security_exposure/loan_security_exposure.js index 777f29624a7f..5650d89f495e 100644 --- a/erpnext/loan_management/report/loan_security_exposure/loan_security_exposure.js +++ b/erpnext/loan_management/report/loan_security_exposure/loan_security_exposure.js @@ -3,14 +3,14 @@ /* eslint-disable */ frappe.query_reports["Loan Security Exposure"] = { - "filters": [ + filters: [ { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_user_default("Company"), - "reqd": 1 - } - ] + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), + reqd: 1, + }, + ], }; diff --git a/erpnext/loan_management/report/loan_security_status/loan_security_status.js b/erpnext/loan_management/report/loan_security_status/loan_security_status.js index 6e6191c7e44d..6e5195b72f3b 100644 --- a/erpnext/loan_management/report/loan_security_status/loan_security_status.js +++ b/erpnext/loan_management/report/loan_security_status/loan_security_status.js @@ -3,44 +3,44 @@ /* eslint-disable */ frappe.query_reports["Loan Security Status"] = { - "filters": [ + filters: [ { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "reqd": 1, - "default": frappe.defaults.get_user_default("Company") + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + reqd: 1, + default: frappe.defaults.get_user_default("Company"), }, { - "fieldname":"applicant_type", - "label": __("Applicant Type"), - "fieldtype": "Select", - "options": ["Customer", "Employee"], - "reqd": 1, - "default": "Customer", - on_change: function() { - frappe.query_report.set_filter_value('applicant', ""); - } + fieldname: "applicant_type", + label: __("Applicant Type"), + fieldtype: "Select", + options: ["Customer", "Employee"], + reqd: 1, + default: "Customer", + on_change: function () { + frappe.query_report.set_filter_value("applicant", ""); + }, }, { - "fieldname": "applicant", - "label": __("Applicant"), - "fieldtype": "Dynamic Link", - "get_options": function() { - var applicant_type = frappe.query_report.get_filter_value('applicant_type'); - var applicant = frappe.query_report.get_filter_value('applicant'); - if(applicant && !applicant_type) { + fieldname: "applicant", + label: __("Applicant"), + fieldtype: "Dynamic Link", + get_options: function () { + var applicant_type = frappe.query_report.get_filter_value("applicant_type"); + var applicant = frappe.query_report.get_filter_value("applicant"); + if (applicant && !applicant_type) { frappe.throw(__("Please select Applicant Type first")); } return applicant_type; - } + }, }, { - "fieldname":"pledge_status", - "label": __("Pledge Status"), - "fieldtype": "Select", - "options": ["", "Requested", "Pledged", "Partially Pledged", "Unpledged"], + fieldname: "pledge_status", + label: __("Pledge Status"), + fieldtype: "Select", + options: ["", "Requested", "Pledged", "Partially Pledged", "Unpledged"], }, - ] + ], }; diff --git a/erpnext/maintenance/doctype/maintenance_schedule/maintenance_schedule.js b/erpnext/maintenance/doctype/maintenance_schedule/maintenance_schedule.js index 5252798ba57e..4613a0fc840f 100644 --- a/erpnext/maintenance/doctype/maintenance_schedule/maintenance_schedule.js +++ b/erpnext/maintenance/doctype/maintenance_schedule/maintenance_schedule.js @@ -2,15 +2,15 @@ // License: GNU General Public License v3. See license.txt frappe.provide("erpnext.maintenance"); -frappe.ui.form.on('Maintenance Schedule', { +frappe.ui.form.on("Maintenance Schedule", { setup: function (frm) { - frm.set_query('contact_person', erpnext.queries.contact_query); - frm.set_query('customer_address', erpnext.queries.address_query); - frm.set_query('customer', erpnext.queries.customer); + frm.set_query("contact_person", erpnext.queries.contact_query); + frm.set_query("customer_address", erpnext.queries.address_query); + frm.set_query("customer", erpnext.queries.customer); }, onload: function (frm) { if (!frm.doc.status) { - frm.set_value({ status: 'Draft' }); + frm.set_value({ status: "Draft" }); } if (frm.doc.__islocal) { frm.set_value({ transaction_date: frappe.datetime.get_today() }); @@ -18,128 +18,136 @@ frappe.ui.form.on('Maintenance Schedule', { }, refresh: function (frm) { setTimeout(() => { - frm.toggle_display('generate_schedule', !(frm.is_new() || frm.doc.docstatus)); - frm.toggle_display('schedule', !(frm.is_new())); + frm.toggle_display("generate_schedule", !(frm.is_new() || frm.doc.docstatus)); + frm.toggle_display("schedule", !frm.is_new()); }, 10); }, customer: function (frm) { - erpnext.utils.get_party_details(frm) + erpnext.utils.get_party_details(frm); }, customer_address: function (frm) { - erpnext.utils.get_address_display(frm, 'customer_address', 'address_display'); + erpnext.utils.get_address_display(frm, "customer_address", "address_display"); }, contact_person: function (frm) { erpnext.utils.get_contact_details(frm); }, generate_schedule: function (frm) { if (frm.is_new()) { - frappe.msgprint(__('Please save first')); + frappe.msgprint(__("Please save first")); } else { - frm.call('generate_schedule'); + frm.call("generate_schedule"); } - } -}) + }, +}); // TODO commonify this code erpnext.maintenance.MaintenanceSchedule = class MaintenanceSchedule extends frappe.ui.form.Controller { refresh() { - frappe.dynamic_link = {doc: this.frm.doc, fieldname: 'customer', doctype: 'Customer'} + frappe.dynamic_link = { doc: this.frm.doc, fieldname: "customer", doctype: "Customer" }; var me = this; if (this.frm.doc.docstatus === 0) { - this.frm.add_custom_button(__('Sales Order'), + this.frm.add_custom_button( + __("Sales Order"), function () { erpnext.utils.map_current_doc({ method: "erpnext.selling.doctype.sales_order.sales_order.make_maintenance_schedule", source_doctype: "Sales Order", target: me.frm, setters: { - customer: me.frm.doc.customer || undefined + customer: me.frm.doc.customer || undefined, }, get_query_filters: { docstatus: 1, - company: me.frm.doc.company - } + company: me.frm.doc.company, + }, }); - }, __("Get Items From")); + }, + __("Get Items From") + ); } else if (this.frm.doc.docstatus === 1) { let schedules = me.frm.doc.schedules; - let flag = schedules.some(schedule => schedule.completion_status === "Pending"); + let flag = schedules.some((schedule) => schedule.completion_status === "Pending"); if (flag) { - this.frm.add_custom_button(__('Maintenance Visit'), function () { - let options = ""; + this.frm.add_custom_button( + __("Maintenance Visit"), + function () { + let options = ""; - me.frm.call('get_pending_data', {data_type: "items"}).then(r => { - options = r.message; + me.frm.call("get_pending_data", { data_type: "items" }).then((r) => { + options = r.message; - let schedule_id = ""; - let d = new frappe.ui.Dialog({ - title: __("Enter Visit Details"), - fields: [{ - fieldtype: "Select", - fieldname: "item_name", - label: __("Item Name"), - options: options, - reqd: 1, - onchange: function () { - let field = d.get_field("scheduled_date"); - me.frm.call('get_pending_data', - { - item_name: this.value, - data_type: "date" - }).then(r => { - field.df.options = r.message; - field.refresh(); - }); - } - }, - { - label: __('Scheduled Date'), - fieldname: 'scheduled_date', - fieldtype: 'Select', - options: "", - reqd: 1, - onchange: function () { - let field = d.get_field('item_name'); - me.frm.call( - 'get_pending_data', - { - item_name: field.value, - s_date: this.value, - data_type: "id" - }).then(r => { - schedule_id = r.message; - }); - } - }, - ], - primary_action_label: 'Create Visit', - primary_action(values) { - frappe.call({ - method: "erpnext.maintenance.doctype.maintenance_schedule.maintenance_schedule.make_maintenance_visit", - args: { - item_name: values.item_name, - s_id: schedule_id, - source_name: me.frm.doc.name, + let schedule_id = ""; + let d = new frappe.ui.Dialog({ + title: __("Enter Visit Details"), + fields: [ + { + fieldtype: "Select", + fieldname: "item_name", + label: __("Item Name"), + options: options, + reqd: 1, + onchange: function () { + let field = d.get_field("scheduled_date"); + me.frm + .call("get_pending_data", { + item_name: this.value, + data_type: "date", + }) + .then((r) => { + field.df.options = r.message; + field.refresh(); + }); + }, + }, + { + label: __("Scheduled Date"), + fieldname: "scheduled_date", + fieldtype: "Select", + options: "", + reqd: 1, + onchange: function () { + let field = d.get_field("item_name"); + me.frm + .call("get_pending_data", { + item_name: field.value, + s_date: this.value, + data_type: "id", + }) + .then((r) => { + schedule_id = r.message; + }); + }, }, - callback: function (r) { - if (!r.exc) { - frappe.model.sync(r.message); - frappe.set_route("Form", r.message.doctype, r.message.name); - } - } - }); - d.hide(); - } + ], + primary_action_label: "Create Visit", + primary_action(values) { + frappe.call({ + method: "erpnext.maintenance.doctype.maintenance_schedule.maintenance_schedule.make_maintenance_visit", + args: { + item_name: values.item_name, + s_id: schedule_id, + source_name: me.frm.doc.name, + }, + callback: function (r) { + if (!r.exc) { + frappe.model.sync(r.message); + frappe.set_route("Form", r.message.doctype, r.message.name); + } + }, + }); + d.hide(); + }, + }); + d.show(); }); - d.show(); - }); - }, __('Create')); + }, + __("Create") + ); } } } - }; -extend_cscript(cur_frm.cscript, new erpnext.maintenance.MaintenanceSchedule({frm: cur_frm})); +extend_cscript(cur_frm.cscript, new erpnext.maintenance.MaintenanceSchedule({ frm: cur_frm })); diff --git a/erpnext/maintenance/doctype/maintenance_visit/maintenance_visit.js b/erpnext/maintenance/doctype/maintenance_visit/maintenance_visit.js index e2f6cb3a6cc8..0a05791b1e98 100644 --- a/erpnext/maintenance/doctype/maintenance_visit/maintenance_visit.js +++ b/erpnext/maintenance/doctype/maintenance_visit/maintenance_visit.js @@ -2,11 +2,11 @@ // License: GNU General Public License v3. See license.txt frappe.provide("erpnext.maintenance"); -frappe.ui.form.on('Maintenance Visit', { +frappe.ui.form.on("Maintenance Visit", { setup: function (frm) { - frm.set_query('contact_person', erpnext.queries.contact_query); - frm.set_query('customer_address', erpnext.queries.address_query); - frm.set_query('customer', erpnext.queries.customer); + frm.set_query("contact_person", erpnext.queries.contact_query); + frm.set_query("customer_address", erpnext.queries.address_query); + frm.set_query("customer", erpnext.queries.customer); }, onload: function (frm) { // filters for serial no based on item code @@ -15,42 +15,44 @@ frappe.ui.form.on('Maintenance Visit', { if (!item_code) { return; } - frappe.call({ - method: "erpnext.maintenance.doctype.maintenance_schedule.maintenance_schedule.get_serial_nos_from_schedule", - args: { - schedule: frm.doc.maintenance_schedule, - item_code: item_code - } - }).then((r) => { - let serial_nos = r.message; - frm.set_query('serial_no', 'purposes', () => { - if (serial_nos.length > 0) { + frappe + .call({ + method: "erpnext.maintenance.doctype.maintenance_schedule.maintenance_schedule.get_serial_nos_from_schedule", + args: { + schedule: frm.doc.maintenance_schedule, + item_code: item_code, + }, + }) + .then((r) => { + let serial_nos = r.message; + frm.set_query("serial_no", "purposes", () => { + if (serial_nos.length > 0) { + return { + filters: { + item_code: item_code, + name: ["in", serial_nos], + }, + }; + } return { filters: { - 'item_code': item_code, - 'name': ["in", serial_nos] - } + item_code: item_code, + }, }; - } - return { - filters: { - 'item_code': item_code - } - }; + }); }); - }); } else { - frm.set_query('serial_no', 'purposes', (frm, cdt, cdn) => { + frm.set_query("serial_no", "purposes", (frm, cdt, cdn) => { let row = locals[cdt][cdn]; return { filters: { - 'item_code': row.item_code - } + item_code: row.item_code, + }, }; }); } if (!frm.doc.status) { - frm.set_value({ status: 'Draft' }); + frm.set_value({ status: "Draft" }); } if (frm.doc.__islocal) { frm.set_value({ mntc_date: frappe.datetime.get_today() }); @@ -60,25 +62,26 @@ frappe.ui.form.on('Maintenance Visit', { erpnext.utils.get_party_details(frm); }, customer_address: function (frm) { - erpnext.utils.get_address_display(frm, 'customer_address', 'address_display'); + erpnext.utils.get_address_display(frm, "customer_address", "address_display"); }, contact_person: function (frm) { erpnext.utils.get_contact_details(frm); - } -}) + }, +}); // TODO commonify this code erpnext.maintenance.MaintenanceVisit = class MaintenanceVisit extends frappe.ui.form.Controller { refresh() { - frappe.dynamic_link = {doc: this.frm.doc, fieldname: 'customer', doctype: 'Customer'} + frappe.dynamic_link = { doc: this.frm.doc, fieldname: "customer", doctype: "Customer" }; var me = this; if (this.frm.doc.docstatus === 0) { - this.frm.add_custom_button(__('Maintenance Schedule'), + this.frm.add_custom_button( + __("Maintenance Schedule"), function () { if (!me.frm.doc.customer) { - frappe.msgprint(__('Please select Customer first')); + frappe.msgprint(__("Please select Customer first")); return; } erpnext.utils.map_current_doc({ @@ -90,11 +93,14 @@ erpnext.maintenance.MaintenanceVisit = class MaintenanceVisit extends frappe.ui. }, get_query_filters: { docstatus: 1, - company: me.frm.doc.company - } - }) - }, __("Get Items From")); - this.frm.add_custom_button(__('Warranty Claim'), + company: me.frm.doc.company, + }, + }); + }, + __("Get Items From") + ); + this.frm.add_custom_button( + __("Warranty Claim"), function () { erpnext.utils.map_current_doc({ method: "erpnext.support.doctype.warranty_claim.warranty_claim.make_maintenance_visit", @@ -106,14 +112,17 @@ erpnext.maintenance.MaintenanceVisit = class MaintenanceVisit extends frappe.ui. }, get_query_filters: { status: ["in", "Open, Work in Progress"], - company: me.frm.doc.company - } - }) - }, __("Get Items From")); - this.frm.add_custom_button(__('Sales Order'), + company: me.frm.doc.company, + }, + }); + }, + __("Get Items From") + ); + this.frm.add_custom_button( + __("Sales Order"), function () { if (!me.frm.doc.customer) { - frappe.msgprint(__('Please select Customer first')); + frappe.msgprint(__("Please select Customer first")); return; } erpnext.utils.map_current_doc({ @@ -127,11 +136,13 @@ erpnext.maintenance.MaintenanceVisit = class MaintenanceVisit extends frappe.ui. docstatus: 1, company: me.frm.doc.company, order_type: me.frm.doc.order_type, - } - }) - }, __("Get Items From")); + }, + }); + }, + __("Get Items From") + ); } } }; -extend_cscript(cur_frm.cscript, new erpnext.maintenance.MaintenanceVisit({frm: cur_frm})); +extend_cscript(cur_frm.cscript, new erpnext.maintenance.MaintenanceVisit({ frm: cur_frm })); diff --git a/erpnext/maintenance/doctype/maintenance_visit/maintenance_visit_list.js b/erpnext/maintenance/doctype/maintenance_visit/maintenance_visit_list.js index e98979deb1bc..c47706e33d9e 100644 --- a/erpnext/maintenance/doctype/maintenance_visit/maintenance_visit_list.js +++ b/erpnext/maintenance/doctype/maintenance_visit/maintenance_visit_list.js @@ -1,11 +1,15 @@ -frappe.listview_settings['Maintenance Visit'] = { +frappe.listview_settings["Maintenance Visit"] = { add_fields: ["customer", "customer_name", "completion_status", "maintenance_type"], - get_indicator: function(doc) { + get_indicator: function (doc) { var s = doc.completion_status || "Pending"; - return [__(s), { - "Pending": "blue", - "Partially Completed": "orange", - "Fully Completed": "green" - }[s], "completion_status,=," + doc.completion_status]; - } + return [ + __(s), + { + Pending: "blue", + "Partially Completed": "orange", + "Fully Completed": "green", + }[s], + "completion_status,=," + doc.completion_status, + ]; + }, }; diff --git a/erpnext/manufacturing/doctype/blanket_order/blanket_order.js b/erpnext/manufacturing/doctype/blanket_order/blanket_order.js index 7b26a14a57b2..ead247cc222b 100644 --- a/erpnext/manufacturing/doctype/blanket_order/blanket_order.js +++ b/erpnext/manufacturing/doctype/blanket_order/blanket_order.js @@ -1,60 +1,72 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Blanket Order', { - onload: function(frm) { - frm.trigger('set_tc_name_filter'); +frappe.ui.form.on("Blanket Order", { + onload: function (frm) { + frm.trigger("set_tc_name_filter"); }, - setup: function(frm) { + setup: function (frm) { frm.custom_make_buttons = { - 'Purchase Order': 'Purchase Order', - 'Sales Order': 'Sales Order', - 'Quotation': 'Quotation', + "Purchase Order": "Purchase Order", + "Sales Order": "Sales Order", + Quotation: "Quotation", }; frm.add_fetch("customer", "customer_name", "customer_name"); frm.add_fetch("supplier", "supplier_name", "supplier_name"); }, - refresh: function(frm) { + refresh: function (frm) { erpnext.hide_company(); if (frm.doc.customer && frm.doc.docstatus === 1 && frm.doc.to_date > frappe.datetime.get_today()) { - frm.add_custom_button(__("Sales Order"), function() { - frappe.model.open_mapped_doc({ - method: "erpnext.manufacturing.doctype.blanket_order.blanket_order.make_order", - frm: frm, - args: { - doctype: 'Sales Order' - } - }); - }, __('Create')); + frm.add_custom_button( + __("Sales Order"), + function () { + frappe.model.open_mapped_doc({ + method: "erpnext.manufacturing.doctype.blanket_order.blanket_order.make_order", + frm: frm, + args: { + doctype: "Sales Order", + }, + }); + }, + __("Create") + ); - frm.add_custom_button(__("Quotation"), function() { - frappe.model.open_mapped_doc({ - method: "erpnext.manufacturing.doctype.blanket_order.blanket_order.make_order", - frm: frm, - args: { - doctype: 'Quotation' - } - }); - }, __('Create')); + frm.add_custom_button( + __("Quotation"), + function () { + frappe.model.open_mapped_doc({ + method: "erpnext.manufacturing.doctype.blanket_order.blanket_order.make_order", + frm: frm, + args: { + doctype: "Quotation", + }, + }); + }, + __("Create") + ); } if (frm.doc.supplier && frm.doc.docstatus === 1) { - frm.add_custom_button(__("Purchase Order"), function(){ - frappe.model.open_mapped_doc({ - method: "erpnext.manufacturing.doctype.blanket_order.blanket_order.make_order", - frm: frm, - args: { - doctype: 'Purchase Order' - } - }); - }, __('Create')); + frm.add_custom_button( + __("Purchase Order"), + function () { + frappe.model.open_mapped_doc({ + method: "erpnext.manufacturing.doctype.blanket_order.blanket_order.make_order", + frm: frm, + args: { + doctype: "Purchase Order", + }, + }); + }, + __("Create") + ); } }, - onload_post_render: function(frm) { + onload_post_render: function (frm) { frm.get_field("items").grid.set_multiple_add("item_code", "qty"); }, @@ -66,28 +78,28 @@ frappe.ui.form.on('Blanket Order', { }); }, - set_tc_name_filter: function(frm) { - if (frm.doc.blanket_order_type === 'Selling') { - frm.set_df_property("customer","reqd", 1); - frm.set_df_property("supplier","reqd", 0); + set_tc_name_filter: function (frm) { + if (frm.doc.blanket_order_type === "Selling") { + frm.set_df_property("customer", "reqd", 1); + frm.set_df_property("supplier", "reqd", 0); frm.set_value("supplier", ""); - frm.set_query("tc_name", function() { + frm.set_query("tc_name", function () { return { filters: { selling: 1 } }; }); } - if (frm.doc.blanket_order_type === 'Purchasing') { - frm.set_df_property("supplier","reqd", 1); - frm.set_df_property("customer","reqd", 0); + if (frm.doc.blanket_order_type === "Purchasing") { + frm.set_df_property("supplier", "reqd", 1); + frm.set_df_property("customer", "reqd", 0); frm.set_value("customer", ""); - frm.set_query("tc_name", function() { + frm.set_query("tc_name", function () { return { filters: { buying: 1 } }; }); } }, blanket_order_type: function (frm) { - frm.trigger('set_tc_name_filter'); - } + frm.trigger("set_tc_name_filter"); + }, }); diff --git a/erpnext/manufacturing/doctype/bom/bom.js b/erpnext/manufacturing/doctype/bom/bom.js index 231c476734c4..b7ab6ef38728 100644 --- a/erpnext/manufacturing/doctype/bom/bom.js +++ b/erpnext/manufacturing/doctype/bom/bom.js @@ -6,139 +6,150 @@ frappe.provide("erpnext.bom"); frappe.ui.form.on("BOM", { setup(frm) { frm.custom_make_buttons = { - 'Work Order': 'Work Order', - 'Quality Inspection': 'Quality Inspection' + "Work Order": "Work Order", + "Quality Inspection": "Quality Inspection", }; - frm.set_query("bom_no", "items", function() { + frm.set_query("bom_no", "items", function () { return { filters: { - 'currency': frm.doc.currency, - 'company': frm.doc.company - } + currency: frm.doc.currency, + company: frm.doc.company, + }, }; }); - frm.set_query("source_warehouse", "items", function() { + frm.set_query("source_warehouse", "items", function () { return { filters: { - 'company': frm.doc.company - } + company: frm.doc.company, + }, }; }); - frm.set_query("item", function() { + frm.set_query("item", function () { return { query: "erpnext.manufacturing.doctype.bom.bom.item_query", filters: { - "is_stock_item": 1 - } + is_stock_item: 1, + }, }; }); - frm.set_query("project", function() { - return{ - filters:[ - ['Project', 'status', 'not in', 'Completed, Cancelled'] - ] + frm.set_query("project", function () { + return { + filters: [["Project", "status", "not in", "Completed, Cancelled"]], }; }); - frm.set_query("item_code", "items", function(doc) { + frm.set_query("item_code", "items", function (doc) { return { query: "erpnext.manufacturing.doctype.bom.bom.item_query", filters: { - "include_item_in_manufacturing": 1, - "is_fixed_asset": 0 - } + include_item_in_manufacturing: 1, + is_fixed_asset: 0, + }, }; }); - frm.set_query("bom_no", "items", function(doc, cdt, cdn) { + frm.set_query("bom_no", "items", function (doc, cdt, cdn) { var d = locals[cdt][cdn]; return { filters: { - 'item': d.item_code, - 'is_active': 1, - 'docstatus': 1 - } + item: d.item_code, + is_active: 1, + docstatus: 1, + }, }; }); }, - validate: function(frm) { + validate: function (frm) { if (frm.doc.fg_based_operating_cost && frm.doc.with_operations) { - frappe.throw({message: __("Please check either with operations or FG Based Operating Cost."), title: __("Mandatory")}); + frappe.throw({ + message: __("Please check either with operations or FG Based Operating Cost."), + title: __("Mandatory"), + }); } }, - with_operations: function(frm) { + with_operations: function (frm) { frm.set_df_property("fg_based_operating_cost", "hidden", frm.doc.with_operations ? 1 : 0); }, - fg_based_operating_cost: function(frm) { + fg_based_operating_cost: function (frm) { frm.set_df_property("with_operations", "hidden", frm.doc.fg_based_operating_cost ? 1 : 0); }, - onload_post_render: function(frm) { + onload_post_render: function (frm) { frm.get_field("items").grid.set_multiple_add("item_code", "qty"); }, refresh(frm) { frm.toggle_enable("item", frm.doc.__islocal); - frm.set_indicator_formatter('item_code', - function(doc) { - if (doc.original_item){ - return (doc.item_code != doc.original_item) ? "orange" : "" - } - return "" + frm.set_indicator_formatter("item_code", function (doc) { + if (doc.original_item) { + return doc.item_code != doc.original_item ? "orange" : ""; } - ) + return ""; + }); - if (!frm.is_new() && frm.doc.docstatus<2) { - frm.add_custom_button(__("Update Cost"), function() { + if (!frm.is_new() && frm.doc.docstatus < 2) { + frm.add_custom_button(__("Update Cost"), function () { frm.events.update_cost(frm, true); }); - frm.add_custom_button(__("Browse BOM"), function() { + frm.add_custom_button(__("Browse BOM"), function () { frappe.route_options = { - "bom": frm.doc.name + bom: frm.doc.name, }; frappe.set_route("Tree", "BOM"); }); } if (!frm.is_new() && !frm.doc.docstatus == 0) { - frm.add_custom_button(__("New Version"), function() { + frm.add_custom_button(__("New Version"), function () { let new_bom = frappe.model.copy_doc(frm.doc); frappe.set_route("Form", "BOM", new_bom.name); }); } - if(frm.doc.docstatus==1) { - frm.add_custom_button(__("Work Order"), function() { - frm.trigger("make_work_order"); - }, __("Create")); + if (frm.doc.docstatus == 1) { + frm.add_custom_button( + __("Work Order"), + function () { + frm.trigger("make_work_order"); + }, + __("Create") + ); if (frm.doc.has_variants) { - frm.add_custom_button(__("Variant BOM"), function() { - frm.trigger("make_variant_bom"); - }, __("Create")); + frm.add_custom_button( + __("Variant BOM"), + function () { + frm.trigger("make_variant_bom"); + }, + __("Create") + ); } if (frm.doc.inspection_required) { - frm.add_custom_button(__("Quality Inspection"), function() { - frm.trigger("make_quality_inspection"); - }, __("Create")); + frm.add_custom_button( + __("Quality Inspection"), + function () { + frm.trigger("make_quality_inspection"); + }, + __("Create") + ); } - frm.page.set_inner_btn_group_as_primary(__('Create')); + frm.page.set_inner_btn_group_as_primary(__("Create")); } - if(frm.doc.items && frm.doc.allow_alternative_item) { - const has_alternative = frm.doc.items.find(i => i.allow_alternative_item === 1); + if (frm.doc.items && frm.doc.allow_alternative_item) { + const has_alternative = frm.doc.items.find((i) => i.allow_alternative_item === 1); if (frm.doc.docstatus == 0 && has_alternative) { - frm.add_custom_button(__('Alternate Item'), () => { + frm.add_custom_button(__("Alternate Item"), () => { erpnext.utils.select_alternate_items({ frm: frm, child_docname: "items", @@ -146,23 +157,26 @@ frappe.ui.form.on("BOM", { child_doctype: "BOM Item", original_item_field: "original_item", condition: (d) => { - if (d.allow_alternative_item) {return true;} - } - }) + if (d.allow_alternative_item) { + return true; + } + }, + }); }); } } - if (frm.doc.has_variants) { - frm.set_intro(__('This is a Template BOM and will be used to make the work order for {0} of the item {1}', - [ + frm.set_intro( + __("This is a Template BOM and will be used to make the work order for {0} of the item {1}", [ `variants`, `${frm.doc.item}`, - ]), true); + ]), + true + ); frm.$wrapper.find(".variants-intro").on("click", () => { - frappe.set_route("List", "Item", {"variant_of": frm.doc.item}); + frappe.set_route("List", "Item", { variant_of: frm.doc.item }); }); } }, @@ -176,38 +190,43 @@ frappe.ui.form.on("BOM", { item: item, qty: data.qty || 0.0, project: frm.doc.project, - variant_items: variant_items + variant_items: variant_items, }, freeze: true, callback(r) { - if(r.message) { + if (r.message) { let doc = frappe.model.sync(r.message)[0]; frappe.set_route("Form", doc.doctype, doc.name); } - } + }, }); }); }, make_variant_bom(frm) { - frm.events.setup_variant_prompt(frm, "Variant BOM", (frm, item, data, variant_items) => { - frappe.call({ - method: "erpnext.manufacturing.doctype.bom.bom.make_variant_bom", - args: { - source_name: frm.doc.name, - bom_no: frm.doc.name, - item: item, - variant_items: variant_items - }, - freeze: true, - callback(r) { - if(r.message) { - let doc = frappe.model.sync(r.message)[0]; - frappe.set_route("Form", doc.doctype, doc.name); - } - } - }); - }, true); + frm.events.setup_variant_prompt( + frm, + "Variant BOM", + (frm, item, data, variant_items) => { + frappe.call({ + method: "erpnext.manufacturing.doctype.bom.bom.make_variant_bom", + args: { + source_name: frm.doc.name, + bom_no: frm.doc.name, + item: item, + variant_items: variant_items, + }, + freeze: true, + callback(r) { + if (r.message) { + let doc = frappe.model.sync(r.message)[0]; + frappe.set_route("Form", doc.doctype, doc.name); + } + }, + }); + }, + true + ); }, setup_variant_prompt(frm, title, callback, skip_qty_field) { @@ -215,27 +234,27 @@ frappe.ui.form.on("BOM", { if (frm.doc.has_variants) { fields.push({ - fieldtype: 'Link', - label: __('Variant Item'), - fieldname: 'item', + fieldtype: "Link", + label: __("Variant Item"), + fieldname: "item", options: "Item", reqd: 1, get_query() { return { query: "erpnext.controllers.queries.item_query", filters: { - "variant_of": frm.doc.item - } + variant_of: frm.doc.item, + }, }; - } + }, }); } if (!skip_qty_field) { fields.push({ - fieldtype: 'Float', - label: __('Qty To Manufacture'), - fieldname: 'qty', + fieldtype: "Float", + label: __("Qty To Manufacture"), + fieldname: "qty", reqd: 1, default: 1, onchange: () => { @@ -244,29 +263,23 @@ frappe.ui.form.on("BOM", { acc[item.item_code] = item.qty; return acc; }, {}); - const mf_qty = cur_dialog.fields_list.filter( - (f) => f.df.fieldname === "qty" - )[0]?.value; - const items = cur_dialog.fields.filter( - (f) => f.fieldname === "items" - )[0]?.data; + const mf_qty = cur_dialog.fields_list.filter((f) => f.df.fieldname === "qty")[0]?.value; + const items = cur_dialog.fields.filter((f) => f.fieldname === "items")[0]?.data; if (!items) { return; } items.forEach((item) => { - item.qty = - (variant_items_map[item.item_code] * mf_qty) / - quantity; + item.qty = (variant_items_map[item.item_code] * mf_qty) / quantity; }); cur_dialog.refresh(); - } + }, }); } - var has_template_rm = frm.doc.items.filter(d => d.has_variants === 1) || []; + var has_template_rm = frm.doc.items.filter((d) => d.has_variants === 1) || []; if (has_template_rm && has_template_rm.length > 0) { fields.push({ fieldname: "items", @@ -296,10 +309,10 @@ frappe.ui.form.on("BOM", { return { query: "erpnext.controllers.queries.item_query", filters: { - "variant_of": data.item_code - } + variant_of: data.item_code, + }, }; - } + }, }, { fieldname: "qty", @@ -312,44 +325,48 @@ frappe.ui.form.on("BOM", { fieldname: "source_warehouse", label: __("Source Warehouse"), fieldtype: "Link", - options: "Warehouse" + options: "Warehouse", }, { fieldname: "operation", label: __("Operation"), fieldtype: "Data", hidden: 1, - } + }, ], in_place_edit: true, data: [], - get_data () { + get_data() { return []; }, }); } - let dialog = frappe.prompt(fields, data => { - let item = data.item || frm.doc.item; - let variant_items = data.items || []; + let dialog = frappe.prompt( + fields, + (data) => { + let item = data.item || frm.doc.item; + let variant_items = data.items || []; - variant_items.forEach(d => { - if (!d.variant_item_code) { - frappe.throw(__("Select variant item code for the template item {0}", [d.item_code])); - } - }) - - callback(frm, item, data, variant_items); + variant_items.forEach((d) => { + if (!d.variant_item_code) { + frappe.throw(__("Select variant item code for the template item {0}", [d.item_code])); + } + }); - }, __(title), __("Create")); + callback(frm, item, data, variant_items); + }, + __(title), + __("Create") + ); - has_template_rm.forEach(d => { + has_template_rm.forEach((d) => { dialog.fields_dict.items.df.data.push({ - "item_code": d.item_code, - "variant_item_code": "", - "qty": d.qty, - "source_warehouse": d.source_warehouse, - "operation": d.operation + item_code: d.item_code, + variant_item_code: "", + qty: d.qty, + source_warehouse: d.source_warehouse, + operation: d.operation, }); }); @@ -361,11 +378,11 @@ frappe.ui.form.on("BOM", { make_quality_inspection(frm) { frappe.model.open_mapped_doc({ method: "erpnext.stock.doctype.quality_inspection.quality_inspection.make_quality_inspection", - frm: frm - }) + frm: frm, + }); }, - update_cost(frm, save_doc=false) { + update_cost(frm, save_doc = false) { return frappe.call({ doc: frm.doc, method: "update_cost", @@ -373,12 +390,12 @@ frappe.ui.form.on("BOM", { args: { update_parent: true, save: save_doc, - from_child_bom: false + from_child_bom: false, }, callback(r) { refresh_field("items"); - if(!r.exc) frm.refresh_fields(); - } + if (!r.exc) frm.refresh_fields(); + }, }); }, @@ -400,39 +417,39 @@ frappe.ui.form.on("BOM", { erpnext.bom.calculate_op_cost(frm.doc); erpnext.bom.calculate_total(frm.doc); } - } + }, }); } }, process_loss_percentage(frm) { - let qty = 0.0 + let qty = 0.0; if (frm.doc.process_loss_percentage) { qty = (frm.doc.quantity * frm.doc.process_loss_percentage) / 100; } frm.set_value("process_loss_qty", qty); - } + }, }); erpnext.bom.BomController = class BomController extends erpnext.TransactionController { conversion_rate(doc) { - if(this.frm.doc.currency === this.get_company_currency()) { + if (this.frm.doc.currency === this.get_company_currency()) { this.frm.set_value("conversion_rate", 1.0); } else { erpnext.bom.update_cost(doc); } } - item_code(doc, cdt, cdn){ + item_code(doc, cdt, cdn) { var scrap_items = false; var child = locals[cdt][cdn]; - if (child.doctype == 'BOM Scrap Item') { + if (child.doctype == "BOM Scrap Item") { scrap_items = true; } if (child.bom_no) { - child.bom_no = ''; + child.bom_no = ""; } get_bom_material_detail(doc, cdt, cdn, scrap_items); @@ -460,26 +477,26 @@ erpnext.bom.BomController = class BomController extends erpnext.TransactionContr } }; -extend_cscript(cur_frm.cscript, new erpnext.bom.BomController({frm: cur_frm})); +extend_cscript(cur_frm.cscript, new erpnext.bom.BomController({ frm: cur_frm })); -cur_frm.cscript.hour_rate = function(doc) { +cur_frm.cscript.hour_rate = function (doc) { erpnext.bom.calculate_op_cost(doc); erpnext.bom.calculate_total(doc); }; cur_frm.cscript.time_in_mins = cur_frm.cscript.hour_rate; -cur_frm.cscript.bom_no = function(doc, cdt, cdn) { +cur_frm.cscript.bom_no = function (doc, cdt, cdn) { get_bom_material_detail(doc, cdt, cdn, false); }; -cur_frm.cscript.is_default = function(doc) { +cur_frm.cscript.is_default = function (doc) { if (doc.is_default) cur_frm.set_value("is_active", 1); }; -var get_bom_material_detail = function(doc, cdt, cdn, scrap_items) { +var get_bom_material_detail = function (doc, cdt, cdn, scrap_items) { if (!doc.company) { - frappe.throw({message: __("Please select a Company first."), title: __("Mandatory")}); + frappe.throw({ message: __("Please select a Company first."), title: __("Mandatory") }); } var d = locals[cdt][cdn]; @@ -488,20 +505,20 @@ var get_bom_material_detail = function(doc, cdt, cdn, scrap_items) { doc: doc, method: "get_bom_material_detail", args: { - "company": doc.company, - "item_code": d.item_code, - "bom_no": d.bom_no != null ? d.bom_no: '', - "scrap_items": scrap_items, - "qty": d.qty, - "stock_qty": d.stock_qty, - "include_item_in_manufacturing": d.include_item_in_manufacturing, - "uom": d.uom, - "stock_uom": d.stock_uom, - "conversion_factor": d.conversion_factor, - "sourced_by_supplier": d.sourced_by_supplier, - "do_not_explode": d.do_not_explode + company: doc.company, + item_code: d.item_code, + bom_no: d.bom_no != null ? d.bom_no : "", + scrap_items: scrap_items, + qty: d.qty, + stock_qty: d.stock_qty, + include_item_in_manufacturing: d.include_item_in_manufacturing, + uom: d.uom, + stock_uom: d.stock_uom, + conversion_factor: d.conversion_factor, + sourced_by_supplier: d.sourced_by_supplier, + do_not_explode: d.do_not_explode, }, - callback: function(r) { + callback: function (r) { d = locals[cdt][cdn]; $.extend(d, r.message); @@ -513,18 +530,18 @@ var get_bom_material_detail = function(doc, cdt, cdn, scrap_items) { erpnext.bom.calculate_scrap_materials_cost(doc); erpnext.bom.calculate_total(doc); }, - freeze: true + freeze: true, }); } }; -cur_frm.cscript.qty = function(doc) { +cur_frm.cscript.qty = function (doc) { erpnext.bom.calculate_rm_cost(doc); erpnext.bom.calculate_scrap_materials_cost(doc); erpnext.bom.calculate_total(doc); }; -cur_frm.cscript.rate = function(doc, cdt, cdn) { +cur_frm.cscript.rate = function (doc, cdt, cdn) { var d = locals[cdt][cdn]; const is_scrap_item = cdt == "BOM Scrap Item"; @@ -538,52 +555,60 @@ cur_frm.cscript.rate = function(doc, cdt, cdn) { } }; -erpnext.bom.update_cost = function(doc) { +erpnext.bom.update_cost = function (doc) { erpnext.bom.calculate_op_cost(doc); erpnext.bom.calculate_rm_cost(doc); erpnext.bom.calculate_scrap_materials_cost(doc); erpnext.bom.calculate_total(doc); }; -erpnext.bom.calculate_op_cost = function(doc) { +erpnext.bom.calculate_op_cost = function (doc) { doc.operating_cost = 0.0; doc.base_operating_cost = 0.0; - if(doc.with_operations) { + if (doc.with_operations) { doc.operations.forEach((item) => { - let operating_cost = flt(flt(item.hour_rate) * flt(item.time_in_mins) / 60, 2); + let operating_cost = flt((flt(item.hour_rate) * flt(item.time_in_mins)) / 60, 2); let base_operating_cost = flt(operating_cost * doc.conversion_rate, 2); - frappe.model.set_value('BOM Operation',item.name, { - "operating_cost": operating_cost, - "base_operating_cost": base_operating_cost + frappe.model.set_value("BOM Operation", item.name, { + operating_cost: operating_cost, + base_operating_cost: base_operating_cost, }); doc.operating_cost += operating_cost; doc.base_operating_cost += base_operating_cost; }); - } else if(doc.fg_based_operating_cost) { + } else if (doc.fg_based_operating_cost) { let total_operating_cost = doc.quantity * flt(doc.operating_cost_per_bom_quantity); doc.operating_cost = total_operating_cost; doc.base_operating_cost = flt(total_operating_cost * doc.conversion_rate, 2); } - refresh_field(['operating_cost', 'base_operating_cost']); + refresh_field(["operating_cost", "base_operating_cost"]); }; // rm : raw material -erpnext.bom.calculate_rm_cost = function(doc) { +erpnext.bom.calculate_rm_cost = function (doc) { var rm = doc.items || []; var total_rm_cost = 0; var base_total_rm_cost = 0; - for(var i=0;i { - d.allow_alternative_item = r.allow_alternative_item - }) + frappe.db.get_value("Item", { name: d.item_code }, "allow_alternative_item", (r) => { + d.allow_alternative_item = r.allow_alternative_item; + }); refresh_field("allow_alternative_item", d.name, d.parentfield); }); -frappe.ui.form.on("BOM Item", "sourced_by_supplier", function(frm, cdt, cdn) { +frappe.ui.form.on("BOM Item", "sourced_by_supplier", function (frm, cdt, cdn) { var d = locals[cdt][cdn]; if (d.sourced_by_supplier) { d.rate = 0; @@ -700,7 +729,7 @@ frappe.ui.form.on("BOM Item", "sourced_by_supplier", function(frm, cdt, cdn) { } }); -frappe.ui.form.on("BOM Item", "rate", function(frm, cdt, cdn) { +frappe.ui.form.on("BOM Item", "rate", function (frm, cdt, cdn) { var d = locals[cdt][cdn]; if (d.sourced_by_supplier) { d.rate = 0; @@ -708,37 +737,41 @@ frappe.ui.form.on("BOM Item", "rate", function(frm, cdt, cdn) { } }); -frappe.ui.form.on("BOM Operation", "operations_remove", function(frm) { +frappe.ui.form.on("BOM Operation", "operations_remove", function (frm) { erpnext.bom.calculate_op_cost(frm.doc); erpnext.bom.calculate_total(frm.doc); }); -frappe.ui.form.on("BOM Item", "items_remove", function(frm) { +frappe.ui.form.on("BOM Item", "items_remove", function (frm) { erpnext.bom.calculate_rm_cost(frm.doc); erpnext.bom.calculate_total(frm.doc); }); -frappe.tour['BOM'] = [ +frappe.tour["BOM"] = [ { fieldname: "item", title: "Item", - description: __("Select the Item to be manufactured. The Item name, UoM, Company, and Currency will be fetched automatically.") + description: __( + "Select the Item to be manufactured. The Item name, UoM, Company, and Currency will be fetched automatically." + ), }, { fieldname: "quantity", title: "Quantity", - description: __("Enter the quantity of the Item that will be manufactured from this Bill of Materials.") + description: __( + "Enter the quantity of the Item that will be manufactured from this Bill of Materials." + ), }, { fieldname: "with_operations", title: "With Operations", - description: __("To add Operations tick the 'With Operations' checkbox.") + description: __("To add Operations tick the 'With Operations' checkbox."), }, { fieldname: "items", title: "Raw Materials", - description: __("Select the raw materials (Items) required to manufacture the Item") - } + description: __("Select the raw materials (Items) required to manufacture the Item"), + }, ]; frappe.ui.form.on("BOM Scrap Item", { diff --git a/erpnext/manufacturing/doctype/bom/bom_list.js b/erpnext/manufacturing/doctype/bom/bom_list.js index 4b5887f180cb..a26df545f85d 100644 --- a/erpnext/manufacturing/doctype/bom/bom_list.js +++ b/erpnext/manufacturing/doctype/bom/bom_list.js @@ -1,16 +1,16 @@ -frappe.listview_settings['BOM'] = { +frappe.listview_settings["BOM"] = { add_fields: ["is_active", "is_default", "total_cost", "has_variants"], - get_indicator: function(doc) { - if(doc.is_active && doc.has_variants) { + get_indicator: function (doc) { + if (doc.is_active && doc.has_variants) { return [__("Template"), "orange", "has_variants,=,Yes"]; - } else if(doc.is_default) { + } else if (doc.is_default) { return [__("Default"), "green", "is_default,=,Yes"]; - } else if(doc.is_active) { + } else if (doc.is_active) { return [__("Active"), "blue", "is_active,=,Yes"]; - } else if(!doc.is_active) { + } else if (!doc.is_active) { return [__("Not active"), "gray", "is_active,=,No"]; } - } + }, }; frappe.help.youtube_id["BOM"] = "hDV0c1OeWLo"; diff --git a/erpnext/manufacturing/doctype/bom/bom_tree.js b/erpnext/manufacturing/doctype/bom/bom_tree.js index fb99add12cf8..534de0e654bc 100644 --- a/erpnext/manufacturing/doctype/bom/bom_tree.js +++ b/erpnext/manufacturing/doctype/bom/bom_tree.js @@ -1,12 +1,12 @@ frappe.treeview_settings["BOM"] = { - get_tree_nodes: 'erpnext.manufacturing.doctype.bom.bom.get_children', + get_tree_nodes: "erpnext.manufacturing.doctype.bom.bom.get_children", filters: [ { fieldname: "bom", - fieldtype:"Link", + fieldtype: "Link", options: "BOM", - label: __("BOM") - } + label: __("BOM"), + }, ], title: "BOM", breadcrumb: "Manufacturing", @@ -14,21 +14,21 @@ frappe.treeview_settings["BOM"] = { root_label: "BOM", //fieldname from filters get_tree_root: false, show_expand_all: false, - get_label: function(node) { - if(node.data.qty) { + get_label: function (node) { + if (node.data.qty) { return node.data.qty + " x " + node.data.item_code; } else { return node.data.item_code || node.data.value; } }, - onload: function(me) { + onload: function (me) { var label = frappe.get_route()[0] + "/" + frappe.get_route()[1]; - if(frappe.pages[label]) { + if (frappe.pages[label]) { delete frappe.pages[label]; } var filter = me.opts.filters[0]; - if(frappe.route_options && frappe.route_options[filter.fieldname]) { + if (frappe.route_options && frappe.route_options[filter.fieldname]) { var val = frappe.route_options[filter.fieldname]; delete frappe.route_options[filter.fieldname]; filter.default = ""; @@ -41,28 +41,27 @@ frappe.treeview_settings["BOM"] = { toolbar: [ { toggle_btn: true }, { - label:__("Edit"), - condition: function(node) { + label: __("Edit"), + condition: function (node) { return node.expandable; }, - click: function(node) { - + click: function (node) { frappe.set_route("Form", "BOM", node.data.value); - } - } + }, + }, ], menu_items: [ { label: __("New BOM"), - action: function() { - frappe.new_doc("BOM", true) + action: function () { + frappe.new_doc("BOM", true); }, - condition: 'frappe.boot.user.can_create.indexOf("BOM") !== -1' - } + condition: 'frappe.boot.user.can_create.indexOf("BOM") !== -1', + }, ], - onrender: function(node) { - if(node.is_root && node.data.value!="BOM") { - frappe.model.with_doc("BOM", node.data.value, function() { + onrender: function (node) { + if (node.is_root && node.data.value != "BOM") { + frappe.model.with_doc("BOM", node.data.value, function () { var bom = frappe.model.get_doc("BOM", node.data.value); node.data.image = escape(bom.image) || ""; node.data.description = bom.description || ""; @@ -70,5 +69,5 @@ frappe.treeview_settings["BOM"] = { }); } }, - view_template: 'bom_item_preview' -} + view_template: "bom_item_preview", +}; diff --git a/erpnext/manufacturing/doctype/bom_update_log/bom_update_log.js b/erpnext/manufacturing/doctype/bom_update_log/bom_update_log.js index 6da808e26d12..7664c299b1a0 100644 --- a/erpnext/manufacturing/doctype/bom_update_log/bom_update_log.js +++ b/erpnext/manufacturing/doctype/bom_update_log/bom_update_log.js @@ -1,8 +1,7 @@ // Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('BOM Update Log', { +frappe.ui.form.on("BOM Update Log", { // refresh: function(frm) { - // } }); diff --git a/erpnext/manufacturing/doctype/bom_update_log/bom_update_log_list.js b/erpnext/manufacturing/doctype/bom_update_log/bom_update_log_list.js index bc709d8fc439..cdaee70860ba 100644 --- a/erpnext/manufacturing/doctype/bom_update_log/bom_update_log_list.js +++ b/erpnext/manufacturing/doctype/bom_update_log/bom_update_log_list.js @@ -1,11 +1,11 @@ -frappe.listview_settings['BOM Update Log'] = { +frappe.listview_settings["BOM Update Log"] = { add_fields: ["status"], get_indicator: (doc) => { let status_map = { - "Queued": "orange", + Queued: "orange", "In Progress": "blue", - "Completed": "green", - "Failed": "red" + Completed: "green", + Failed: "red", }; return [__(doc.status), status_map[doc.status], "status,=," + doc.status]; @@ -15,16 +15,14 @@ frappe.listview_settings['BOM Update Log'] = { return; } - let sidebar_entry = $( - '' - ).appendTo(cur_list.page.sidebar); + let sidebar_entry = $('').appendTo( + cur_list.page.sidebar + ); let message = __("Note: Automatic log deletion only applies to logs of type Update Cost"); $(`
    ${message}
    `).appendTo(sidebar_entry); frappe.require("logtypes.bundle.js", () => { frappe.utils.logtypes.show_log_retention_message(cur_list.doctype); }); - - }, -}; \ No newline at end of file +}; diff --git a/erpnext/manufacturing/doctype/bom_update_tool/bom_update_tool.js b/erpnext/manufacturing/doctype/bom_update_tool/bom_update_tool.js index 7ba6517a4fbc..5cdb425bffce 100644 --- a/erpnext/manufacturing/doctype/bom_update_tool/bom_update_tool.js +++ b/erpnext/manufacturing/doctype/bom_update_tool/bom_update_tool.js @@ -1,24 +1,24 @@ // Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('BOM Update Tool', { - setup: function(frm) { - frm.set_query("current_bom", function() { +frappe.ui.form.on("BOM Update Tool", { + setup: function (frm) { + frm.set_query("current_bom", function () { return { query: "erpnext.controllers.queries.bom", - filters: {name: "!" + frm.doc.new_bom} + filters: { name: "!" + frm.doc.new_bom }, }; }); - frm.set_query("new_bom", function() { + frm.set_query("new_bom", function () { return { query: "erpnext.controllers.queries.bom", - filters: {name: "!" + frm.doc.current_bom} + filters: { name: "!" + frm.doc.current_bom }, }; }); }, - refresh: function(frm) { + refresh: function (frm) { frm.disable_save(); frm.events.disable_button(frm, "replace"); @@ -27,7 +27,7 @@ frappe.ui.form.on('BOM Update Tool', { }); }, - disable_button: (frm, field, disable=true) => { + disable_button: (frm, field, disable = true) => { frm.get_field(field).input.disabled = disable; }, @@ -50,15 +50,15 @@ frappe.ui.form.on('BOM Update Tool', { freeze: true, args: { boms: { - "current_bom": frm.doc.current_bom, - "new_bom": frm.doc.new_bom - } + current_bom: frm.doc.current_bom, + new_bom: frm.doc.new_bom, + }, }, - callback: result => { + callback: (result) => { if (result && result.message && !result.exc) { frm.events.confirm_job_start(frm, result.message); } - } + }, }); } }, @@ -67,20 +67,22 @@ frappe.ui.form.on('BOM Update Tool', { frappe.call({ method: "erpnext.manufacturing.doctype.bom_update_tool.bom_update_tool.enqueue_update_cost", freeze: true, - callback: result => { + callback: (result) => { if (result && result.message && !result.exc) { frm.events.confirm_job_start(frm, result.message); } - } + }, }); }, confirm_job_start: (frm, log_data) => { let log_link = frappe.utils.get_form_link("BOM Update Log", log_data.name, true); frappe.msgprint({ - "message": __("BOM Updation is queued and may take a few minutes. Check {0} for progress.", [log_link]), - "title": __("BOM Update Initiated"), - "indicator": "blue" + message: __("BOM Updation is queued and may take a few minutes. Check {0} for progress.", [ + log_link, + ]), + title: __("BOM Update Initiated"), + indicator: "blue", }); - } + }, }); diff --git a/erpnext/manufacturing/doctype/downtime_entry/downtime_entry.js b/erpnext/manufacturing/doctype/downtime_entry/downtime_entry.js index 3b7f5ba8d7f5..516e33c7a3b3 100644 --- a/erpnext/manufacturing/doctype/downtime_entry/downtime_entry.js +++ b/erpnext/manufacturing/doctype/downtime_entry/downtime_entry.js @@ -1,8 +1,7 @@ // Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Downtime Entry', { +frappe.ui.form.on("Downtime Entry", { // refresh: function(frm) { - // } }); diff --git a/erpnext/manufacturing/doctype/job_card/job_card.js b/erpnext/manufacturing/doctype/job_card/job_card.js index 4a46d5774450..db9c8849f459 100644 --- a/erpnext/manufacturing/doctype/job_card/job_card.js +++ b/erpnext/manufacturing/doctype/job_card/job_card.js @@ -1,29 +1,27 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Job Card', { - setup: function(frm) { - frm.set_query('operation', function() { +frappe.ui.form.on("Job Card", { + setup: function (frm) { + frm.set_query("operation", function () { return { - query: 'erpnext.manufacturing.doctype.job_card.job_card.get_operations', + query: "erpnext.manufacturing.doctype.job_card.job_card.get_operations", filters: { - 'work_order': frm.doc.work_order - } + work_order: frm.doc.work_order, + }, }; }); - frm.set_indicator_formatter('sub_operation', - function(doc) { - if (doc.status == "Pending") { - return "red"; - } else { - return doc.status === "Complete" ? "green" : "orange"; - } + frm.set_indicator_formatter("sub_operation", function (doc) { + if (doc.status == "Pending") { + return "red"; + } else { + return doc.status === "Complete" ? "green" : "orange"; } - ); + }); }, - refresh: function(frm) { + refresh: function (frm) { frappe.flags.pause_job = 0; frappe.flags.resume_job = 0; let has_items = frm.doc.items && frm.doc.items.length; @@ -33,8 +31,7 @@ frappe.ui.form.on('Job Card', { return; } - let has_stock_entry = frm.doc.__onload && - frm.doc.__onload.has_stock_entry ? true : false; + let has_stock_entry = frm.doc.__onload && frm.doc.__onload.has_stock_entry ? true : false; frm.toggle_enable("for_quantity", !has_stock_entry); @@ -60,33 +57,45 @@ frappe.ui.form.on('Job Card', { } if (frm.doc.docstatus == 1 && !frm.doc.is_corrective_job_card) { - frm.trigger('setup_corrective_job_card'); + frm.trigger("setup_corrective_job_card"); } - frm.set_query("quality_inspection", function() { + frm.set_query("quality_inspection", function () { return { query: "erpnext.stock.doctype.quality_inspection.quality_inspection.quality_inspection_query", filters: { - "item_code": frm.doc.production_item, - "reference_name": frm.doc.name - } + item_code: frm.doc.production_item, + reference_name: frm.doc.name, + }, }; }); frm.trigger("toggle_operation_number"); - if (frm.doc.docstatus == 0 && !frm.is_new() && - (frm.doc.for_quantity > frm.doc.total_completed_qty || !frm.doc.for_quantity) - && (frm.doc.items || !frm.doc.items.length || frm.doc.for_quantity == frm.doc.transferred_qty)) { - + if ( + frm.doc.docstatus == 0 && + !frm.is_new() && + (frm.doc.for_quantity > frm.doc.total_completed_qty || !frm.doc.for_quantity) && + (frm.doc.items || !frm.doc.items.length || frm.doc.for_quantity == frm.doc.transferred_qty) + ) { // if Job Card is link to Work Order, the job card must not be able to start if Work Order not "Started" // and if stock mvt for WIP is required if (frm.doc.work_order) { - frappe.db.get_value('Work Order', frm.doc.work_order, ['skip_transfer', 'status'], (result) => { - if (result.skip_transfer === 1 || result.status == 'In Process' || frm.doc.transferred_qty > 0 || !frm.doc.items.length) { - frm.trigger("prepare_timer_buttons"); + frappe.db.get_value( + "Work Order", + frm.doc.work_order, + ["skip_transfer", "status"], + (result) => { + if ( + result.skip_transfer === 1 || + result.status == "In Process" || + frm.doc.transferred_qty > 0 || + !frm.doc.items.length + ) { + frm.trigger("prepare_timer_buttons"); + } } - }); + ); } else { frm.trigger("prepare_timer_buttons"); } @@ -95,89 +104,103 @@ frappe.ui.form.on('Job Card', { frm.trigger("setup_quality_inspection"); if (frm.doc.work_order) { - frappe.db.get_value('Work Order', frm.doc.work_order, - 'transfer_material_against').then((r) => { - if (r.message.transfer_material_against == 'Work Order') { - frm.set_df_property('items', 'hidden', 1); + frappe.db.get_value("Work Order", frm.doc.work_order, "transfer_material_against").then((r) => { + if (r.message.transfer_material_against == "Work Order") { + frm.set_df_property("items", "hidden", 1); } }); } }, - setup_quality_inspection: function(frm) { + setup_quality_inspection: function (frm) { let quality_inspection_field = frm.get_docfield("quality_inspection"); - quality_inspection_field.get_route_options_for_new_doc = function(frm) { - return { - "inspection_type": "In Process", - "reference_type": "Job Card", - "reference_name": frm.doc.name, - "item_code": frm.doc.production_item, - "item_name": frm.doc.item_name, - "item_serial_no": frm.doc.serial_no, - "batch_no": frm.doc.batch_no, - "quality_inspection_template": frm.doc.quality_inspection_template, + quality_inspection_field.get_route_options_for_new_doc = function (frm) { + return { + inspection_type: "In Process", + reference_type: "Job Card", + reference_name: frm.doc.name, + item_code: frm.doc.production_item, + item_name: frm.doc.item_name, + item_serial_no: frm.doc.serial_no, + batch_no: frm.doc.batch_no, + quality_inspection_template: frm.doc.quality_inspection_template, }; }; }, - setup_corrective_job_card: function(frm) { - frm.add_custom_button(__('Corrective Job Card'), () => { - let operations = frm.doc.sub_operations.map(d => d.sub_operation).concat(frm.doc.operation); - - let fields = [ - { - fieldtype: 'Link', label: __('Corrective Operation'), options: 'Operation', - fieldname: 'operation', get_query() { - return { - filters: { - "is_corrective_operation": 1 - } - }; - } - }, { - fieldtype: 'Link', label: __('For Operation'), options: 'Operation', - fieldname: 'for_operation', get_query() { - return { - filters: { - "name": ["in", operations] - } - }; - } - } - ]; - - frappe.prompt(fields, d => { - frm.events.make_corrective_job_card(frm, d.operation, d.for_operation); - }, __("Select Corrective Operation")); - }, __('Make')); + setup_corrective_job_card: function (frm) { + frm.add_custom_button( + __("Corrective Job Card"), + () => { + let operations = frm.doc.sub_operations.map((d) => d.sub_operation).concat(frm.doc.operation); + + let fields = [ + { + fieldtype: "Link", + label: __("Corrective Operation"), + options: "Operation", + fieldname: "operation", + get_query() { + return { + filters: { + is_corrective_operation: 1, + }, + }; + }, + }, + { + fieldtype: "Link", + label: __("For Operation"), + options: "Operation", + fieldname: "for_operation", + get_query() { + return { + filters: { + name: ["in", operations], + }, + }; + }, + }, + ]; + + frappe.prompt( + fields, + (d) => { + frm.events.make_corrective_job_card(frm, d.operation, d.for_operation); + }, + __("Select Corrective Operation") + ); + }, + __("Make") + ); }, - make_corrective_job_card: function(frm, operation, for_operation) { + make_corrective_job_card: function (frm, operation, for_operation) { frappe.call({ - method: 'erpnext.manufacturing.doctype.job_card.job_card.make_corrective_job_card', + method: "erpnext.manufacturing.doctype.job_card.job_card.make_corrective_job_card", args: { source_name: frm.doc.name, operation: operation, - for_operation: for_operation + for_operation: for_operation, }, - callback: function(r) { + callback: function (r) { if (r.message) { frappe.model.sync(r.message); frappe.set_route("Form", r.message.doctype, r.message.name); } - } + }, }); }, - operation: function(frm) { + operation: function (frm) { frm.trigger("toggle_operation_number"); if (frm.doc.operation && frm.doc.work_order) { frappe.call({ method: "erpnext.manufacturing.doctype.job_card.job_card.get_operation_details", args: { - "work_order":frm.doc.work_order, - "operation":frm.doc.operation + work_order: frm.doc.work_order, + operation: frm.doc.operation, }, callback: function (r) { if (r.message) { @@ -187,11 +210,13 @@ frappe.ui.form.on('Job Card', { let args = []; r.message.forEach((row) => { - args.push({ "label": row.idx, "value": row.name }); + args.push({ label: row.idx, value: row.name }); }); - let description = __("Operation {0} added multiple times in the work order {1}", - [frm.doc.operation, frm.doc.work_order]); + let description = __("Operation {0} added multiple times in the work order {1}", [ + frm.doc.operation, + frm.doc.work_order, + ]); frm.set_df_property("operation_row_number", "options", args); frm.set_df_property("operation_row_number", "description", description); @@ -199,8 +224,8 @@ frappe.ui.form.on('Job Card', { frm.trigger("toggle_operation_number"); } - } - }) + }, + }); } }, @@ -215,16 +240,24 @@ frappe.ui.form.on('Job Card', { frm.toggle_reqd("operation_row_number", !frm.doc.operation_id && frm.doc.operation); }, - prepare_timer_buttons: function(frm) { + prepare_timer_buttons: function (frm) { frm.trigger("make_dashboard"); if (!frm.doc.started_time && !frm.doc.current_time) { frm.add_custom_button(__("Start Job"), () => { if ((frm.doc.employee && !frm.doc.employee.length) || !frm.doc.employee) { - frappe.prompt({fieldtype: 'Table MultiSelect', label: __('Select Employees'), - options: "Job Card Time Log", fieldname: 'employees'}, d => { - frm.events.start_job(frm, "Work In Progress", d.employees); - }, __("Assign Job to Employee")); + frappe.prompt( + { + fieldtype: "Table MultiSelect", + label: __("Select Employees"), + options: "Job Card Time Log", + fieldname: "employees", + }, + (d) => { + frm.events.start_job(frm, "Work In Progress", d.employees); + }, + __("Assign Job to Employee") + ); } else { frm.events.start_job(frm, "Work In Progress", frm.doc.employee); } @@ -246,16 +279,24 @@ frappe.ui.form.on('Job Card', { set_qty = false; let last_op_row = sub_operations[sub_operations.length - 2]; - if (last_op_row.status == 'Complete') { + if (last_op_row.status == "Complete") { set_qty = true; } } if (set_qty) { - frappe.prompt({fieldtype: 'Float', label: __('Completed Quantity'), - fieldname: 'qty', default: frm.doc.for_quantity}, data => { - frm.events.complete_job(frm, "Complete", data.qty); - }, __("Enter Value")); + frappe.prompt( + { + fieldtype: "Float", + label: __("Completed Quantity"), + fieldname: "qty", + default: frm.doc.for_quantity, + }, + (data) => { + frm.events.complete_job(frm, "Complete", data.qty); + }, + __("Enter Value") + ); } else { frm.events.complete_job(frm, "Complete", 0.0); } @@ -263,64 +304,63 @@ frappe.ui.form.on('Job Card', { } }, - start_job: function(frm, status, employee) { + start_job: function (frm, status, employee) { const args = { job_card_id: frm.doc.name, start_time: frappe.datetime.now_datetime(), employees: employee, - status: status + status: status, }; frm.events.make_time_log(frm, args); }, - complete_job: function(frm, status, completed_qty) { + complete_job: function (frm, status, completed_qty) { const args = { job_card_id: frm.doc.name, complete_time: frappe.datetime.now_datetime(), status: status, - completed_qty: completed_qty + completed_qty: completed_qty, }; frm.events.make_time_log(frm, args); }, - make_time_log: function(frm, args) { + make_time_log: function (frm, args) { frm.events.update_sub_operation(frm, args); frappe.call({ method: "erpnext.manufacturing.doctype.job_card.job_card.make_time_log", args: { - args: args + args: args, }, freeze: true, callback: function () { frm.reload_doc(); frm.trigger("make_dashboard"); - } + }, }); }, - update_sub_operation: function(frm, args) { + update_sub_operation: function (frm, args) { if (frm.doc.sub_operations && frm.doc.sub_operations.length) { - let sub_operations = frm.doc.sub_operations.filter(d => d.status != 'Complete'); + let sub_operations = frm.doc.sub_operations.filter((d) => d.status != "Complete"); if (sub_operations && sub_operations.length) { args["sub_operation"] = sub_operations[0].sub_operation; } } }, - validate: function(frm) { + validate: function (frm) { if ((!frm.doc.time_logs || !frm.doc.time_logs.length) && frm.doc.started_time) { frm.trigger("reset_timer"); } }, - reset_timer: function(frm) { - frm.set_value('started_time' , ''); + reset_timer: function (frm) { + frm.set_value("started_time", ""); }, - make_dashboard: function(frm) { - if(frm.doc.__islocal) - return; + make_dashboard: function (frm) { + if (frm.doc.__islocal) return; frm.dashboard.refresh(); const timer = ` @@ -340,12 +380,15 @@ frappe.ui.form.on('Job Card', { if (frm.doc.status == "On Hold") { updateStopwatch(currentIncrement); } else { - currentIncrement += moment(frappe.datetime.now_datetime()).diff(moment(frm.doc.started_time),"seconds"); + currentIncrement += moment(frappe.datetime.now_datetime()).diff( + moment(frm.doc.started_time), + "seconds" + ); initialiseTimer(); } function initialiseTimer() { - const interval = setInterval(function() { + const interval = setInterval(function () { var current = setCurrentIncrement(); updateStopwatch(current); }, 1000); @@ -353,12 +396,18 @@ frappe.ui.form.on('Job Card', { function updateStopwatch(increment) { var hours = Math.floor(increment / 3600); - var minutes = Math.floor((increment - (hours * 3600)) / 60); - var seconds = increment - (hours * 3600) - (minutes * 60); - - $(section).find(".hours").text(hours < 10 ? ("0" + hours.toString()) : hours.toString()); - $(section).find(".minutes").text(minutes < 10 ? ("0" + minutes.toString()) : minutes.toString()); - $(section).find(".seconds").text(seconds < 10 ? ("0" + seconds.toString()) : seconds.toString()); + var minutes = Math.floor((increment - hours * 3600) / 60); + var seconds = increment - hours * 3600 - minutes * 60; + + $(section) + .find(".hours") + .text(hours < 10 ? "0" + hours.toString() : hours.toString()); + $(section) + .find(".minutes") + .text(minutes < 10 ? "0" + minutes.toString() : minutes.toString()); + $(section) + .find(".seconds") + .text(seconds < 10 ? "0" + seconds.toString() : seconds.toString()); } function setCurrentIncrement() { @@ -368,69 +417,67 @@ frappe.ui.form.on('Job Card', { } }, - hide_timer: function(frm) { + hide_timer: function (frm) { frm.toolbar.page.inner_toolbar.find(".stopwatch").remove(); }, - for_quantity: function(frm) { + for_quantity: function (frm) { frm.doc.items = []; frm.call({ method: "get_required_items", doc: frm.doc, - callback: function() { + callback: function () { refresh_field("items"); - } - }) + }, + }); }, - make_material_request: function(frm) { + make_material_request: function (frm) { frappe.model.open_mapped_doc({ method: "erpnext.manufacturing.doctype.job_card.job_card.make_material_request", frm: frm, - run_link_triggers: true + run_link_triggers: true, }); }, - make_stock_entry: function(frm) { + make_stock_entry: function (frm) { frappe.model.open_mapped_doc({ method: "erpnext.manufacturing.doctype.job_card.job_card.make_stock_entry", frm: frm, - run_link_triggers: true + run_link_triggers: true, }); }, - timer: function(frm) { - return `` + timer: function (frm) { + return ``; }, - set_total_completed_qty: function(frm) { + set_total_completed_qty: function (frm) { frm.doc.total_completed_qty = 0; - frm.doc.time_logs.forEach(d => { + frm.doc.time_logs.forEach((d) => { if (d.completed_qty) { frm.doc.total_completed_qty += d.completed_qty; } }); if (frm.doc.total_completed_qty && frm.doc.for_quantity > frm.doc.total_completed_qty) { - let flt_precision = precision('for_quantity', frm.doc); - let process_loss_qty = ( - flt(frm.doc.for_quantity, flt_precision) - - flt(frm.doc.total_completed_qty, flt_precision) - ); + let flt_precision = precision("for_quantity", frm.doc); + let process_loss_qty = + flt(frm.doc.for_quantity, flt_precision) - flt(frm.doc.total_completed_qty, flt_precision); - frm.set_value('process_loss_qty', process_loss_qty); + frm.set_value("process_loss_qty", process_loss_qty); } refresh_field("total_completed_qty"); - } + }, }); -frappe.ui.form.on('Job Card Time Log', { - completed_qty: function(frm) { +frappe.ui.form.on("Job Card Time Log", { + completed_qty: function (frm) { frm.events.set_total_completed_qty(frm); }, - to_time: function(frm) { - frm.set_value('started_time', ''); - } -}) + to_time: function (frm) { + frm.set_value("started_time", ""); + }, +}); diff --git a/erpnext/manufacturing/doctype/job_card/job_card_calendar.js b/erpnext/manufacturing/doctype/job_card/job_card_calendar.js index 9e3208535149..7b32a6ee289f 100644 --- a/erpnext/manufacturing/doctype/job_card/job_card_calendar.js +++ b/erpnext/manufacturing/doctype/job_card/job_card_calendar.js @@ -1,31 +1,31 @@ frappe.views.calendar["Job Card"] = { field_map: { - "start": "from_time", - "end": "to_time", - "id": "name", - "title": "subject", - "color": "color", - "allDay": "allDay", - "progress": "progress" + start: "from_time", + end: "to_time", + id: "name", + title: "subject", + color: "color", + allDay: "allDay", + progress: "progress", }, gantt: { field_map: { - "start": "expected_start_date", - "end": "expected_end_date", - "id": "name", - "title": "subject", - "color": "color", - "allDay": "allDay", - "progress": "progress" - } + start: "expected_start_date", + end: "expected_end_date", + id: "name", + title: "subject", + color: "color", + allDay: "allDay", + progress: "progress", + }, }, filters: [ { - "fieldtype": "Link", - "fieldname": "employee", - "options": "Employee", - "label": __("Employee") - } + fieldtype: "Link", + fieldname: "employee", + options: "Employee", + label: __("Employee"), + }, ], - get_events_method: "erpnext.manufacturing.doctype.job_card.job_card.get_job_details" + get_events_method: "erpnext.manufacturing.doctype.job_card.job_card.get_job_details", }; diff --git a/erpnext/manufacturing/doctype/job_card/job_card_list.js b/erpnext/manufacturing/doctype/job_card/job_card_list.js index 99fca9570f71..e417b7f576d0 100644 --- a/erpnext/manufacturing/doctype/job_card/job_card_list.js +++ b/erpnext/manufacturing/doctype/job_card/job_card_list.js @@ -1,17 +1,17 @@ -frappe.listview_settings['Job Card'] = { +frappe.listview_settings["Job Card"] = { has_indicator_for_draft: true, add_fields: ["expected_start_date", "expected_end_date"], - get_indicator: function(doc) { + get_indicator: function (doc) { const status_colors = { "Work In Progress": "orange", - "Completed": "green", - "Cancelled": "red", + Completed: "green", + Cancelled: "red", "Material Transferred": "blue", - "Open": "red", + Open: "red", }; const status = doc.status || "Open"; const color = status_colors[status] || "blue"; return [__(status), color, `status,=,${status}`]; - } + }, }; diff --git a/erpnext/manufacturing/doctype/manufacturing_settings/manufacturing_settings.js b/erpnext/manufacturing/doctype/manufacturing_settings/manufacturing_settings.js index a0122a473858..f54478a1c10b 100644 --- a/erpnext/manufacturing/doctype/manufacturing_settings/manufacturing_settings.js +++ b/erpnext/manufacturing/doctype/manufacturing_settings/manufacturing_settings.js @@ -1,33 +1,40 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Manufacturing Settings', { -}); +frappe.ui.form.on("Manufacturing Settings", {}); frappe.tour["Manufacturing Settings"] = [ { fieldname: "material_consumption", title: __("Allow Multiple Material Consumption"), - description: __("If ticked, multiple materials can be used for a single Work Order. This is useful if one or more time consuming products are being manufactured.") + description: __( + "If ticked, multiple materials can be used for a single Work Order. This is useful if one or more time consuming products are being manufactured." + ), }, { fieldname: "backflush_raw_materials_based_on", title: __("Backflush Raw Materials"), - description: __("The Stock Entry of type 'Manufacture' is known as backflush. Raw materials being consumed to manufacture finished goods is known as backflushing.

    When creating Manufacture Entry, raw-material items are backflushed based on BOM of production item. If you want raw-material items to be backflushed based on Material Transfer entry made against that Work Order instead, then you can set it under this field.") + description: __( + "The Stock Entry of type 'Manufacture' is known as backflush. Raw materials being consumed to manufacture finished goods is known as backflushing.

    When creating Manufacture Entry, raw-material items are backflushed based on BOM of production item. If you want raw-material items to be backflushed based on Material Transfer entry made against that Work Order instead, then you can set it under this field." + ), }, { fieldname: "default_wip_warehouse", title: __("Work In Progress Warehouse"), - description: __("This Warehouse will be auto-updated in the Work In Progress Warehouse field of Work Orders.") + description: __( + "This Warehouse will be auto-updated in the Work In Progress Warehouse field of Work Orders." + ), }, { fieldname: "default_fg_warehouse", title: __("Finished Goods Warehouse"), - description: __("This Warehouse will be auto-updated in the Target Warehouse field of Work Order.") + description: __("This Warehouse will be auto-updated in the Target Warehouse field of Work Order."), }, { fieldname: "update_bom_costs_automatically", title: __("Update BOM Cost Automatically"), - description: __("If ticked, the BOM cost will be automatically updated based on Valuation Rate / Price List Rate / last purchase rate of raw materials.") - } + description: __( + "If ticked, the BOM cost will be automatically updated based on Valuation Rate / Price List Rate / last purchase rate of raw materials." + ), + }, ]; diff --git a/erpnext/manufacturing/doctype/material_request_plan_item/material_request_plan_item.js b/erpnext/manufacturing/doctype/material_request_plan_item/material_request_plan_item.js index 61c0a997a423..7a9e2b901209 100644 --- a/erpnext/manufacturing/doctype/material_request_plan_item/material_request_plan_item.js +++ b/erpnext/manufacturing/doctype/material_request_plan_item/material_request_plan_item.js @@ -1,8 +1,6 @@ // Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Material Request Plan Item', { - refresh: function() { - - } +frappe.ui.form.on("Material Request Plan Item", { + refresh: function () {}, }); diff --git a/erpnext/manufacturing/doctype/operation/operation.js b/erpnext/manufacturing/doctype/operation/operation.js index ea73fd6e2734..c51ea72c8a42 100644 --- a/erpnext/manufacturing/doctype/operation/operation.js +++ b/erpnext/manufacturing/doctype/operation/operation.js @@ -1,32 +1,34 @@ // Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Operation', { - setup: function(frm) { - frm.set_query('operation', 'sub_operations', function() { +frappe.ui.form.on("Operation", { + setup: function (frm) { + frm.set_query("operation", "sub_operations", function () { return { filters: { - 'name': ['not in', [frm.doc.name]] - } + name: ["not in", [frm.doc.name]], + }, }; }); - } + }, }); -frappe.tour['Operation'] = [ +frappe.tour["Operation"] = [ { fieldname: "__newname", title: "Operation Name", - description: __("Enter a name for the Operation, for example, Cutting.") + description: __("Enter a name for the Operation, for example, Cutting."), }, { fieldname: "workstation", title: "Default Workstation", - description: __("Select the Default Workstation where the Operation will be performed. This will be fetched in BOMs and Work Orders.") + description: __( + "Select the Default Workstation where the Operation will be performed. This will be fetched in BOMs and Work Orders." + ), }, { fieldname: "sub_operations", title: "Sub Operations", - description: __("If an operation is divided into sub operations, they can be added here.") - } + description: __("If an operation is divided into sub operations, they can be added here."), + }, ]; diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.js b/erpnext/manufacturing/doctype/production_plan/production_plan.js index 667ece2077ec..54d1414c8145 100644 --- a/erpnext/manufacturing/doctype/production_plan/production_plan.js +++ b/erpnext/manufacturing/doctype/production_plan/production_plan.js @@ -1,11 +1,10 @@ // Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Production Plan', { - +frappe.ui.form.on("Production Plan", { before_save(frm) { // preserve temporary names on production plan item to re-link sub-assembly items - frm.doc.po_items.forEach(item => { + frm.doc.po_items.forEach((item) => { item.temporary_name = item.name; }); }, @@ -14,8 +13,8 @@ frappe.ui.form.on('Production Plan', { frm.trigger("setup_queries"); frm.custom_make_buttons = { - 'Work Order': 'Work Order / Subcontract PO', - 'Material Request': 'Material Request', + "Work Order": "Work Order / Subcontract PO", + "Material Request": "Material Request", }; }, @@ -25,36 +24,36 @@ frappe.ui.form.on('Production Plan', { query: "erpnext.manufacturing.doctype.production_plan.production_plan.sales_order_query", filters: { company: frm.doc.company, - } - } + }, + }; }); - frm.set_query('for_warehouse', function(doc) { + frm.set_query("for_warehouse", function (doc) { return { filters: { company: doc.company, - is_group: 0 - } - } + is_group: 0, + }, + }; }); - frm.set_query('material_request', 'material_requests', function() { + frm.set_query("material_request", "material_requests", function () { return { filters: { material_request_type: "Manufacture", docstatus: 1, status: ["!=", "Stopped"], - } + }, }; }); frm.set_query("item_code", "po_items", (doc, cdt, cdn) => { return { query: "erpnext.controllers.queries.item_query", - filters:{ - 'is_stock_item': 1, - } - } + filters: { + is_stock_item: 1, + }, + }; }); frm.set_query("bom_no", "po_items", (doc, cdt, cdn) => { @@ -62,25 +61,25 @@ frappe.ui.form.on('Production Plan', { if (d.item_code) { return { query: "erpnext.controllers.queries.bom", - filters:{'item': d.item_code, 'docstatus': 1} - } + filters: { item: d.item_code, docstatus: 1 }, + }; } else frappe.msgprint(__("Please enter Item first")); }); frm.set_query("warehouse", "mr_items", (doc) => { return { filters: { - company: doc.company - } - } + company: doc.company, + }, + }; }); frm.set_query("warehouse", "po_items", (doc) => { return { filters: { - company: doc.company - } - } + company: doc.company, + }, + }; }); }, @@ -89,36 +88,62 @@ frappe.ui.form.on('Production Plan', { frm.trigger("show_progress"); if (frm.doc.status !== "Completed") { - frm.add_custom_button(__("Production Plan Summary"), ()=> { - frappe.set_route('query-report', 'Production Plan Summary', {production_plan: frm.doc.name}); - }, __('View')); - - if (frm.doc.status === "Closed") { - frm.add_custom_button(__("Re-open"), function() { - frm.events.close_open_production_plan(frm, false); - }, __("Status")); + frm.add_custom_button( + __("Production Plan Summary"), + () => { + frappe.set_route("query-report", "Production Plan Summary", { + production_plan: frm.doc.name, + }); + }, + __("View") + ); + + if (frm.doc.status === "Closed") { + frm.add_custom_button( + __("Re-open"), + function () { + frm.events.close_open_production_plan(frm, false); + }, + __("Status") + ); } else { - frm.add_custom_button(__("Close"), function() { - frm.events.close_open_production_plan(frm, true); - }, __("Status")); + frm.add_custom_button( + __("Close"), + function () { + frm.events.close_open_production_plan(frm, true); + }, + __("Status") + ); } if (frm.doc.po_items && frm.doc.status !== "Closed") { - frm.add_custom_button(__("Work Order / Subcontract PO"), ()=> { - frm.trigger("make_work_order"); - }, __('Create')); + frm.add_custom_button( + __("Work Order / Subcontract PO"), + () => { + frm.trigger("make_work_order"); + }, + __("Create") + ); } - if (frm.doc.mr_items && frm.doc.mr_items.length && !in_list(['Material Requested', 'Closed'], frm.doc.status)) { - frm.add_custom_button(__("Material Request"), ()=> { - frm.trigger("make_material_request"); - }, __('Create')); + if ( + frm.doc.mr_items && + frm.doc.mr_items.length && + !in_list(["Material Requested", "Closed"], frm.doc.status) + ) { + frm.add_custom_button( + __("Material Request"), + () => { + frm.trigger("make_material_request"); + }, + __("Create") + ); } } } if (frm.doc.status !== "Closed") { - frm.page.set_inner_btn_group_as_primary(__('Create')); + frm.page.set_inner_btn_group_as_primary(__("Create")); } frm.trigger("material_requirement"); @@ -145,19 +170,19 @@ frappe.ui.form.on('Production Plan', { ${__("Planned Qty: Quantity, for which, Work Order has been raised, but is pending to be manufactured.")}
  • - ${__('Requested Qty: Quantity requested for purchase, but not ordered.')} + ${__("Requested Qty: Quantity requested for purchase, but not ordered.")}
  • - ${__('Ordered Qty: Quantity ordered for purchase, but not received.')} + ${__("Ordered Qty: Quantity ordered for purchase, but not received.")}
  • ${__("Reserved Qty: Quantity ordered for sale, but not delivered.")}
  • - ${__('Reserved Qty for Production: Raw materials quantity to make manufacturing items.')} + ${__("Reserved Qty for Production: Raw materials quantity to make manufacturing items.")}
  • - ${__('Reserved Qty for Subcontract: Raw materials quantity to make subcontracted items.')} + ${__("Reserved Qty for Subcontract: Raw materials quantity to make subcontracted items.")}
  • @@ -168,15 +193,15 @@ frappe.ui.form.on('Production Plan', { set_field_options("projected_qty_formula", projected_qty_formula); }, - close_open_production_plan(frm, close=false) { + close_open_production_plan(frm, close = false) { frappe.call({ method: "set_status", freeze: true, doc: frm.doc, - args: {close : close, update_bin: true}, - callback: function() { + args: { close: close, update_bin: true }, + callback: function () { frm.reload_doc(); - } + }, }); }, @@ -185,19 +210,19 @@ frappe.ui.form.on('Production Plan', { method: "make_work_order", freeze: true, doc: frm.doc, - callback: function() { + callback: function () { frm.reload_doc(); - } + }, }); }, make_material_request(frm) { - - frappe.confirm(__("Do you want to submit the material request"), - function() { + frappe.confirm( + __("Do you want to submit the material request"), + function () { frm.events.create_material_request(frm, 1); }, - function() { + function () { frm.events.create_material_request(frm, 0); } ); @@ -210,9 +235,9 @@ frappe.ui.form.on('Production Plan', { method: "make_material_request", freeze: true, doc: frm.doc, - callback: function(r) { + callback: function (r) { frm.reload_doc(); - } + }, }); }, @@ -220,9 +245,9 @@ frappe.ui.form.on('Production Plan', { frappe.call({ method: "get_open_sales_orders", doc: frm.doc, - callback: function(r) { + callback: function (r) { refresh_field("sales_orders"); - } + }, }); }, @@ -230,22 +255,22 @@ frappe.ui.form.on('Production Plan', { frappe.call({ method: "get_pending_material_requests", doc: frm.doc, - callback: function() { - refresh_field('material_requests'); - } + callback: function () { + refresh_field("material_requests"); + }, }); }, get_items(frm) { - frm.clear_table('prod_plan_references'); + frm.clear_table("prod_plan_references"); frappe.call({ method: "get_items", freeze: true, doc: frm.doc, callback: function () { - refresh_field('po_items'); - } + refresh_field("po_items"); + }, }); }, combine_items(frm) { @@ -255,12 +280,12 @@ frappe.ui.form.on('Production Plan', { method: "get_items", freeze: true, doc: frm.doc, - callback: function() { + callback: function () { frm.refresh_field("po_items"); if (frm.doc.sub_assembly_items.length > 0) { frm.trigger("get_sub_assembly_items"); } - } + }, }); }, @@ -278,9 +303,9 @@ frappe.ui.form.on('Production Plan', { method: "get_sub_assembly_items", freeze: true, doc: frm.doc, - callback: function() { + callback: function () { refresh_field("sub_assembly_items"); - } + }, }); }, @@ -294,9 +319,11 @@ frappe.ui.form.on('Production Plan', { frappe.throw(__("Select the Warehouse")); } - frm.events.get_items_for_material_requests(frm, [{ - warehouse: frm.doc.for_warehouse - }]); + frm.events.get_items_for_material_requests(frm, [ + { + warehouse: frm.doc.for_warehouse, + }, + ]); }, transfer_materials(frm) { @@ -315,26 +342,26 @@ frappe.ui.form.on('Production Plan', { title: title, fields: [ { - 'label': __('Transfer From Warehouses'), - 'fieldtype': 'Table MultiSelect', - 'fieldname': 'warehouses', - 'options': 'Production Plan Material Request Warehouse', + label: __("Transfer From Warehouses"), + fieldtype: "Table MultiSelect", + fieldname: "warehouses", + options: "Production Plan Material Request Warehouse", get_query: function () { return { filters: { - company: frm.doc.company - } + company: frm.doc.company, + }, }; }, }, { - 'label': __('For Warehouse'), - 'fieldtype': 'Link', - 'fieldname': 'target_warehouse', - 'read_only': true, - 'default': frm.doc.for_warehouse - } - ] + label: __("For Warehouse"), + fieldtype: "Link", + fieldname: "target_warehouse", + read_only: true, + default: frm.doc.for_warehouse, + }, + ], }); dialog.show(); @@ -353,82 +380,90 @@ frappe.ui.form.on('Production Plan', { freeze: true, args: { doc: frm.doc, - warehouses: warehouses || [] + warehouses: warehouses || [], }, - callback: function(r) { - if(r.message) { - frm.set_value('mr_items', []); - r.message.forEach(row => { - let d = frm.add_child('mr_items'); + callback: function (r) { + if (r.message) { + frm.set_value("mr_items", []); + r.message.forEach((row) => { + let d = frm.add_child("mr_items"); for (let field in row) { - if (field !== 'name') { + if (field !== "name") { d[field] = row[field]; } } }); } - refresh_field('mr_items'); - } + refresh_field("mr_items"); + }, }); }, download_materials_required(frm) { - const fields = [{ - fieldname: 'warehouses', - fieldtype: 'Table MultiSelect', - label: __('Warehouses'), - default: frm.doc.from_warehouse, - options: "Production Plan Material Request Warehouse", - get_query: function () { - return { - filters: { - company: frm.doc.company - } - }; + const fields = [ + { + fieldname: "warehouses", + fieldtype: "Table MultiSelect", + label: __("Warehouses"), + default: frm.doc.from_warehouse, + options: "Production Plan Material Request Warehouse", + get_query: function () { + return { + filters: { + company: frm.doc.company, + }, + }; + }, }, - }]; - - frappe.prompt(fields, (row) => { - let get_template_url = 'erpnext.manufacturing.doctype.production_plan.production_plan.download_raw_materials'; - open_url_post(frappe.request.url, { - cmd: get_template_url, - doc: frm.doc, - warehouses: row.warehouses - }); - }, __('Select Warehouses to get Stock for Materials Planning'), __('Get Stock')); + ]; + + frappe.prompt( + fields, + (row) => { + let get_template_url = + "erpnext.manufacturing.doctype.production_plan.production_plan.download_raw_materials"; + open_url_post(frappe.request.url, { + cmd: get_template_url, + doc: frm.doc, + warehouses: row.warehouses, + }); + }, + __("Select Warehouses to get Stock for Materials Planning"), + __("Get Stock") + ); }, show_progress(frm) { var bars = []; - var message = ''; - var title = ''; + var message = ""; + var title = ""; // produced qty let item_wise_qty = {}; frm.doc.po_items.forEach((data) => { - if(!item_wise_qty[data.item_code]) { + if (!item_wise_qty[data.item_code]) { item_wise_qty[data.item_code] = data.produced_qty; } else { item_wise_qty[data.item_code] += data.produced_qty; } - }) + }); if (item_wise_qty) { for (var key in item_wise_qty) { - title += __('Item {0}: {1} qty produced. ', [key, item_wise_qty[key]]); + title += __("Item {0}: {1} qty produced. ", [key, item_wise_qty[key]]); } } bars.push({ - 'title': title, - 'width': (frm.doc.total_produced_qty / frm.doc.total_planned_qty * 100) + '%', - 'progress_class': 'progress-bar-success' + title: title, + width: (frm.doc.total_produced_qty / frm.doc.total_planned_qty) * 100 + "%", + progress_class: "progress-bar-success", }); - if (bars[0].width == '0%') { - bars[0].width = '0.5%'; + if (bars[0].width == "0%") { + bars[0].width = "0.5%"; } message = title; - frm.dashboard.add_progress(__('Status'), bars, message); + frm.dashboard.add_progress(__("Status"), bars, message); }, }); @@ -439,13 +474,13 @@ frappe.ui.form.on("Production Plan Item", { frappe.call({ method: "erpnext.manufacturing.doctype.production_plan.production_plan.get_item_data", args: { - item_code: row.item_code + item_code: row.item_code, }, - callback: function(r) { + callback: function (r) { for (let key in r.message) { frappe.model.set_value(cdt, cdn, key, r.message[key]); } - } + }, }); } }, @@ -460,30 +495,29 @@ frappe.ui.form.on("Material Request Plan Item", { args: { row: row, company: frm.doc.company, - for_warehouse: row.warehouse + for_warehouse: row.warehouse, }, - callback: function(r) { + callback: function (r) { if (r.message) { - let {projected_qty, actual_qty} = r.message[0]; + let { projected_qty, actual_qty } = r.message[0]; frappe.model.set_value(cdt, cdn, { - 'projected_qty': projected_qty, - 'actual_qty': actual_qty + projected_qty: projected_qty, + actual_qty: actual_qty, }); } - } - }) + }, + }); } }, material_request_type(frm, cdt, cdn) { let row = locals[cdt][cdn]; - if (row.from_warehouse && - row.material_request_type !== "Material Transfer") { - frappe.model.set_value(cdt, cdn, 'from_warehouse', ''); + if (row.from_warehouse && row.material_request_type !== "Material Transfer") { + frappe.model.set_value(cdt, cdn, "from_warehouse", ""); } - } + }, }); frappe.ui.form.on("Production Plan Sales Order", { @@ -506,53 +540,61 @@ frappe.ui.form.on("Production Plan Sales Order", { method: "erpnext.manufacturing.doctype.production_plan.production_plan.get_so_details", args: { sales_order }, callback(r) { - const {transaction_date, customer, grand_total} = r.message; - frappe.model.set_value(cdt, cdn, 'sales_order_date', transaction_date); - frappe.model.set_value(cdt, cdn, 'customer', customer); - frappe.model.set_value(cdt, cdn, 'grand_total', grand_total); - } + const { transaction_date, customer, grand_total } = r.message; + frappe.model.set_value(cdt, cdn, "sales_order_date", transaction_date); + frappe.model.set_value(cdt, cdn, "customer", customer); + frappe.model.set_value(cdt, cdn, "grand_total", grand_total); + }, }); - } + }, }); } - } + }, }); frappe.ui.form.on("Production Plan Sub Assembly Item", { fg_warehouse(frm, cdt, cdn) { erpnext.utils.copy_value_in_all_rows(frm.doc, cdt, cdn, "sub_assembly_items", "fg_warehouse"); }, -}) +}); -frappe.tour['Production Plan'] = [ +frappe.tour["Production Plan"] = [ { fieldname: "get_items_from", title: "Get Items From", - description: __("Select whether to get items from a Sales Order or a Material Request. For now select Sales Order.\n A Production Plan can also be created manually where you can select the Items to manufacture.") + description: __( + "Select whether to get items from a Sales Order or a Material Request. For now select Sales Order.\n A Production Plan can also be created manually where you can select the Items to manufacture." + ), }, { fieldname: "get_sales_orders", title: "Get Sales Orders", - description: __("Click on Get Sales Orders to fetch sales orders based on the above filters.") + description: __("Click on Get Sales Orders to fetch sales orders based on the above filters."), }, { fieldname: "get_items", title: "Get Finished Goods for Manufacture", - description: __("Click on 'Get Finished Goods for Manufacture' to fetch the items from the above Sales Orders. Items only for which a BOM is present will be fetched.") + description: __( + "Click on 'Get Finished Goods for Manufacture' to fetch the items from the above Sales Orders. Items only for which a BOM is present will be fetched." + ), }, { fieldname: "po_items", title: "Finished Goods", - description: __("On expanding a row in the Items to Manufacture table, you'll see an option to 'Include Exploded Items'. Ticking this includes raw materials of the sub-assembly items in the production process.") + description: __( + "On expanding a row in the Items to Manufacture table, you'll see an option to 'Include Exploded Items'. Ticking this includes raw materials of the sub-assembly items in the production process." + ), }, { fieldname: "include_non_stock_items", title: "Include Non Stock Items", - description: __("To include non-stock items in the material request planning. i.e. Items for which 'Maintain Stock' checkbox is unticked.") + description: __( + "To include non-stock items in the material request planning. i.e. Items for which 'Maintain Stock' checkbox is unticked." + ), }, { fieldname: "include_subcontracted_items", title: "Include Subcontracted Items", - description: __("To add subcontracted Item's raw materials if include exploded items is disabled.") - } + description: __("To add subcontracted Item's raw materials if include exploded items is disabled."), + }, ]; diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan_list.js b/erpnext/manufacturing/doctype/production_plan/production_plan_list.js index 8f946866247a..bfef6e1220f3 100644 --- a/erpnext/manufacturing/doctype/production_plan/production_plan_list.js +++ b/erpnext/manufacturing/doctype/production_plan/production_plan_list.js @@ -1,4 +1,4 @@ -frappe.listview_settings['Production Plan'] = { +frappe.listview_settings["Production Plan"] = { hide_name_column: true, add_fields: ["status"], filters: [["status", "!=", "Closed"]], @@ -6,14 +6,18 @@ frappe.listview_settings['Production Plan'] = { if (doc.status === "Submitted") { return [__("Not Started"), "orange", "status,=,Submitted"]; } else { - return [__(doc.status), { - "Draft": "red", - "In Process": "orange", - "Completed": "green", - "Material Requested": "yellow", - "Cancelled": "gray", - "Closed": "grey" - }[doc.status], "status,=," + doc.status]; + return [ + __(doc.status), + { + Draft: "red", + "In Process": "orange", + Completed: "green", + "Material Requested": "yellow", + Cancelled: "gray", + Closed: "grey", + }[doc.status], + "status,=," + doc.status, + ]; } - } + }, }; diff --git a/erpnext/manufacturing/doctype/production_plan_material_request_warehouse/production_plan_material_request_warehouse.js b/erpnext/manufacturing/doctype/production_plan_material_request_warehouse/production_plan_material_request_warehouse.js index 53f87582d10e..d4e74fa3ec7b 100644 --- a/erpnext/manufacturing/doctype/production_plan_material_request_warehouse/production_plan_material_request_warehouse.js +++ b/erpnext/manufacturing/doctype/production_plan_material_request_warehouse/production_plan_material_request_warehouse.js @@ -1,8 +1,7 @@ // Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Production Plan Material Request Warehouse', { +frappe.ui.form.on("Production Plan Material Request Warehouse", { // refresh: function(frm) { - // } }); diff --git a/erpnext/manufacturing/doctype/routing/routing.js b/erpnext/manufacturing/doctype/routing/routing.js index b480c70ad56c..67e1bc713d02 100644 --- a/erpnext/manufacturing/doctype/routing/routing.js +++ b/erpnext/manufacturing/doctype/routing/routing.js @@ -1,38 +1,39 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Routing', { - refresh: function(frm) { +frappe.ui.form.on("Routing", { + refresh: function (frm) { frm.trigger("display_sequence_id_column"); }, - onload: function(frm) { + onload: function (frm) { frm.trigger("display_sequence_id_column"); }, - display_sequence_id_column: function(frm) { - frm.fields_dict.operations.grid.update_docfield_property( - 'sequence_id', 'in_list_view', 1 - ); + display_sequence_id_column: function (frm) { + frm.fields_dict.operations.grid.update_docfield_property("sequence_id", "in_list_view", 1); }, - calculate_operating_cost: function(frm, child) { - const operating_cost = flt(flt(child.hour_rate) * flt(child.time_in_mins) / 60, precision("operating_cost", child)); + calculate_operating_cost: function (frm, child) { + const operating_cost = flt( + (flt(child.hour_rate) * flt(child.time_in_mins)) / 60, + precision("operating_cost", child) + ); frappe.model.set_value(child.doctype, child.name, "operating_cost", operating_cost); - } + }, }); -frappe.ui.form.on('BOM Operation', { - operation: function(frm, cdt, cdn) { +frappe.ui.form.on("BOM Operation", { + operation: function (frm, cdt, cdn) { const d = locals[cdt][cdn]; - if(!d.operation) return; + if (!d.operation) return; frappe.call({ - "method": "frappe.client.get", + method: "frappe.client.get", args: { doctype: "Operation", - name: d.operation + name: d.operation, }, callback: function (data) { if (data.message.description) { @@ -44,41 +45,43 @@ frappe.ui.form.on('BOM Operation', { } frm.events.calculate_operating_cost(frm, d); - } + }, }); }, - workstation: function(frm, cdt, cdn) { + workstation: function (frm, cdt, cdn) { const d = locals[cdt][cdn]; frappe.call({ - "method": "frappe.client.get", + method: "frappe.client.get", args: { doctype: "Workstation", - name: d.workstation + name: d.workstation, }, callback: function (data) { frappe.model.set_value(d.doctype, d.name, "hour_rate", data.message.hour_rate); frm.events.calculate_operating_cost(frm, d); - } + }, }); }, - time_in_mins: function(frm, cdt, cdn) { + time_in_mins: function (frm, cdt, cdn) { const d = locals[cdt][cdn]; frm.events.calculate_operating_cost(frm, d); - } + }, }); -frappe.tour['Routing'] = [ +frappe.tour["Routing"] = [ { fieldname: "routing_name", title: "Routing Name", - description: __("Enter a name for Routing.") + description: __("Enter a name for Routing."), }, { fieldname: "operations", title: "BOM Operations", - description: __("Enter the Operation, the table will fetch the Operation details like Hourly Rate, Workstation automatically.\n\n After that, set the Operation Time in minutes and the table will calculate the Operation Costs based on the Hourly Rate and Operation Time.") - } + description: __( + "Enter the Operation, the table will fetch the Operation details like Hourly Rate, Workstation automatically.\n\n After that, set the Operation Time in minutes and the table will calculate the Operation Costs based on the Hourly Rate and Operation Time." + ), + }, ]; diff --git a/erpnext/manufacturing/doctype/sub_operation/sub_operation.js b/erpnext/manufacturing/doctype/sub_operation/sub_operation.js index be9db6a4089b..8d6d3ddb879b 100644 --- a/erpnext/manufacturing/doctype/sub_operation/sub_operation.js +++ b/erpnext/manufacturing/doctype/sub_operation/sub_operation.js @@ -1,8 +1,7 @@ // Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Sub Operation', { +frappe.ui.form.on("Sub Operation", { // refresh: function(frm) { - // } }); diff --git a/erpnext/manufacturing/doctype/work_order/work_order.js b/erpnext/manufacturing/doctype/work_order/work_order.js index 88747b8f7a6d..5e3860355146 100644 --- a/erpnext/manufacturing/doctype/work_order/work_order.js +++ b/erpnext/manufacturing/doctype/work_order/work_order.js @@ -2,70 +2,70 @@ // For license information, please see license.txt frappe.ui.form.on("Work Order", { - setup: function(frm) { + setup: function (frm) { frm.custom_make_buttons = { - 'Stock Entry': 'Start', - 'Pick List': 'Create Pick List', - 'Job Card': 'Create Job Card' + "Stock Entry": "Start", + "Pick List": "Create Pick List", + "Job Card": "Create Job Card", }; // Set query for warehouses - frm.set_query("wip_warehouse", function() { + frm.set_query("wip_warehouse", function () { return { filters: { - 'company': frm.doc.company, - } + company: frm.doc.company, + }, }; }); - frm.set_query("source_warehouse", function() { + frm.set_query("source_warehouse", function () { return { filters: { - 'company': frm.doc.company, - } + company: frm.doc.company, + }, }; }); - frm.set_query("source_warehouse", "required_items", function() { + frm.set_query("source_warehouse", "required_items", function () { return { filters: { - 'company': frm.doc.company, - } + company: frm.doc.company, + }, }; }); - frm.set_query("sales_order", function() { + frm.set_query("sales_order", function () { return { filters: { - "status": ["not in", ["Closed", "On Hold"]] - } + status: ["not in", ["Closed", "On Hold"]], + }, }; }); - frm.set_query("fg_warehouse", function() { + frm.set_query("fg_warehouse", function () { return { filters: { - 'company': frm.doc.company, - 'is_group': 0 - } + company: frm.doc.company, + is_group: 0, + }, }; }); - frm.set_query("scrap_warehouse", function() { + frm.set_query("scrap_warehouse", function () { return { filters: { - 'company': frm.doc.company, - 'is_group': 0 - } + company: frm.doc.company, + is_group: 0, + }, }; }); // Set query for BOM - frm.set_query("bom_no", function() { + frm.set_query("bom_no", function () { if (frm.doc.production_item) { return { query: "erpnext.controllers.queries.bom", - filters: {item: cstr(frm.doc.production_item)} + filters: { item: cstr(frm.doc.production_item) }, }; } else { frappe.msgprint(__("Please enter Production Item first")); @@ -73,60 +73,62 @@ frappe.ui.form.on("Work Order", { }); // Set query for FG Item - frm.set_query("production_item", function() { + frm.set_query("production_item", function () { return { query: "erpnext.controllers.queries.item_query", filters: { - "is_stock_item": 1, - } + is_stock_item: 1, + }, }; }); // Set query for FG Item - frm.set_query("project", function() { - return{ - filters:[ - ['Project', 'status', 'not in', 'Completed, Cancelled'] - ] + frm.set_query("project", function () { + return { + filters: [["Project", "status", "not in", "Completed, Cancelled"]], }; }); - frm.set_query("operation", "required_items", function() { + frm.set_query("operation", "required_items", function () { return { query: "erpnext.manufacturing.doctype.work_order.work_order.get_bom_operations", filters: { - 'parent': frm.doc.bom_no, - 'parenttype': 'BOM' - } + parent: frm.doc.bom_no, + parenttype: "BOM", + }, }; }); // formatter for work order operation - frm.set_indicator_formatter('operation', - function(doc) { return (frm.doc.qty==doc.completed_qty) ? "green" : "orange"; }); + frm.set_indicator_formatter("operation", function (doc) { + return frm.doc.qty == doc.completed_qty ? "green" : "orange"; + }); }, - onload: function(frm) { - if (!frm.doc.status) - frm.doc.status = 'Draft'; + onload: function (frm) { + if (!frm.doc.status) frm.doc.status = "Draft"; frm.add_fetch("sales_order", "project", "project"); - if(frm.doc.__islocal) { + if (frm.doc.__islocal) { frm.set_value({ - "actual_start_date": "", - "actual_end_date": "" + actual_start_date: "", + actual_end_date: "", }); erpnext.work_order.set_default_warehouse(frm); } }, - source_warehouse: function(frm) { + source_warehouse: function (frm) { let transaction_controller = new erpnext.TransactionController(); - transaction_controller.autofill_warehouse(frm.doc.required_items, "source_warehouse", frm.doc.source_warehouse); + transaction_controller.autofill_warehouse( + frm.doc.required_items, + "source_warehouse", + frm.doc.source_warehouse + ); }, - refresh: function(frm) { + refresh: function (frm) { erpnext.toggle_naming_series(); erpnext.work_order.set_custom_buttons(frm); frm.set_intro(""); @@ -139,27 +141,30 @@ frappe.ui.form.on("Work Order", { } if (frm.doc.status != "Closed") { - if (frm.doc.docstatus === 1 && frm.doc.status !== "Completed" - && frm.doc.operations && frm.doc.operations.length) { - - const not_completed = frm.doc.operations.filter(d => { - if (d.status != 'Completed') { + if ( + frm.doc.docstatus === 1 && + frm.doc.status !== "Completed" && + frm.doc.operations && + frm.doc.operations.length + ) { + const not_completed = frm.doc.operations.filter((d) => { + if (d.status != "Completed") { return true; } }); if (not_completed && not_completed.length) { - frm.add_custom_button(__('Create Job Card'), () => { + frm.add_custom_button(__("Create Job Card"), () => { frm.trigger("make_job_card"); - }).addClass('btn-primary'); + }).addClass("btn-primary"); } } } - if(frm.doc.required_items && frm.doc.allow_alternative_item) { - const has_alternative = frm.doc.required_items.find(i => i.allow_alternative_item === 1); + if (frm.doc.required_items && frm.doc.allow_alternative_item) { + const has_alternative = frm.doc.required_items.find((i) => i.allow_alternative_item === 1); if (frm.doc.docstatus == 0 && has_alternative) { - frm.add_custom_button(__('Alternate Item'), () => { + frm.add_custom_button(__("Alternate Item"), () => { erpnext.utils.select_alternate_items({ frm: frm, child_docname: "required_items", @@ -167,16 +172,20 @@ frappe.ui.form.on("Work Order", { child_doctype: "Work Order Item", original_item_field: "original_item", condition: (d) => { - if (d.allow_alternative_item) {return true;} - } + if (d.allow_alternative_item) { + return true; + } + }, }); }); } } - if (frm.doc.status == "Completed" && - frm.doc.__onload.backflush_raw_materials_based_on == "Material Transferred for Manufacture") { - frm.add_custom_button(__('Create BOM'), () => { + if ( + frm.doc.status == "Completed" && + frm.doc.__onload.backflush_raw_materials_based_on == "Material Transferred for Manufacture" + ) { + frm.add_custom_button(__("Create BOM"), () => { frm.trigger("make_bom"); }); } @@ -184,120 +193,128 @@ frappe.ui.form.on("Work Order", { frm.trigger("add_custom_button_to_return_components"); }, - add_custom_button_to_return_components: function(frm) { + add_custom_button_to_return_components: function (frm) { if (frm.doc.docstatus === 1 && in_list(["Closed", "Completed"], frm.doc.status)) { - let non_consumed_items = frm.doc.required_items.filter(d =>{ - return flt(d.consumed_qty) < flt(d.transferred_qty - d.returned_qty) + let non_consumed_items = frm.doc.required_items.filter((d) => { + return flt(d.consumed_qty) < flt(d.transferred_qty - d.returned_qty); }); if (non_consumed_items && non_consumed_items.length) { - frm.add_custom_button(__("Return Components"), function() { + frm.add_custom_button(__("Return Components"), function () { frm.trigger("create_stock_return_entry"); }).addClass("btn-primary"); } } }, - create_stock_return_entry: function(frm) { + create_stock_return_entry: function (frm) { frappe.call({ method: "erpnext.manufacturing.doctype.work_order.work_order.make_stock_return_entry", args: { - "work_order": frm.doc.name, + work_order: frm.doc.name, }, - callback: function(r) { - if(!r.exc) { + callback: function (r) { + if (!r.exc) { let doc = frappe.model.sync(r.message); frappe.set_route("Form", doc[0].doctype, doc[0].name); } - } + }, }); }, - make_job_card: function(frm) { + make_job_card: function (frm) { let qty = 0; let operations_data = []; - const dialog = frappe.prompt({fieldname: 'operations', fieldtype: 'Table', label: __('Operations'), - fields: [ - { - fieldtype: 'Link', - fieldname: 'operation', - label: __('Operation'), - read_only: 1, - in_list_view: 1 + const dialog = frappe.prompt( + { + fieldname: "operations", + fieldtype: "Table", + label: __("Operations"), + fields: [ + { + fieldtype: "Link", + fieldname: "operation", + label: __("Operation"), + read_only: 1, + in_list_view: 1, + }, + { + fieldtype: "Link", + fieldname: "workstation", + label: __("Workstation"), + read_only: 1, + in_list_view: 1, + }, + { + fieldtype: "Data", + fieldname: "name", + label: __("Operation Id"), + }, + { + fieldtype: "Float", + fieldname: "pending_qty", + label: __("Pending Qty"), + }, + { + fieldtype: "Float", + fieldname: "qty", + label: __("Quantity to Manufacture"), + read_only: 0, + in_list_view: 1, + }, + { + fieldtype: "Float", + fieldname: "batch_size", + label: __("Batch Size"), + read_only: 1, + }, + { + fieldtype: "Int", + fieldname: "sequence_id", + label: __("Sequence Id"), + read_only: 1, + }, + ], + data: operations_data, + in_place_edit: true, + get_data: function () { + return operations_data; }, - { - fieldtype: 'Link', - fieldname: 'workstation', - label: __('Workstation'), - read_only: 1, - in_list_view: 1 - }, - { - fieldtype: 'Data', - fieldname: 'name', - label: __('Operation Id') - }, - { - fieldtype: 'Float', - fieldname: 'pending_qty', - label: __('Pending Qty'), - }, - { - fieldtype: 'Float', - fieldname: 'qty', - label: __('Quantity to Manufacture'), - read_only: 0, - in_list_view: 1, - }, - { - fieldtype: 'Float', - fieldname: 'batch_size', - label: __('Batch Size'), - read_only: 1 - }, - { - fieldtype: 'Int', - fieldname: 'sequence_id', - label: __('Sequence Id'), - read_only: 1 - }, - ], - data: operations_data, - in_place_edit: true, - get_data: function() { - return operations_data; - } - }, function(data) { - frappe.call({ - method: "erpnext.manufacturing.doctype.work_order.work_order.make_job_card", - freeze: true, - args: { - work_order: frm.doc.name, - operations: data.operations, - }, - callback: function() { - frm.reload_doc(); - } - }); - }, __("Job Card"), __("Create")); + }, + function (data) { + frappe.call({ + method: "erpnext.manufacturing.doctype.work_order.work_order.make_job_card", + freeze: true, + args: { + work_order: frm.doc.name, + operations: data.operations, + }, + callback: function () { + frm.reload_doc(); + }, + }); + }, + __("Job Card"), + __("Create") + ); - dialog.fields_dict["operations"].grid.wrapper.find('.grid-add-row').hide(); + dialog.fields_dict["operations"].grid.wrapper.find(".grid-add-row").hide(); var pending_qty = 0; - frm.doc.operations.forEach(data => { - if(data.completed_qty + data.process_loss_qty != frm.doc.qty) { + frm.doc.operations.forEach((data) => { + if (data.completed_qty + data.process_loss_qty != frm.doc.qty) { pending_qty = frm.doc.qty - flt(data.completed_qty) - flt(data.process_loss_qty); if (pending_qty) { dialog.fields_dict.operations.df.data.push({ - 'name': data.name, - 'operation': data.operation, - 'workstation': data.workstation, - 'batch_size': data.batch_size, - 'qty': pending_qty, - 'pending_qty': pending_qty, - 'sequence_id': data.sequence_id + name: data.name, + operation: data.operation, + workstation: data.workstation, + batch_size: data.batch_size, + qty: pending_qty, + pending_qty: pending_qty, + sequence_id: data.sequence_id, }); } } @@ -305,202 +322,212 @@ frappe.ui.form.on("Work Order", { dialog.fields_dict.operations.grid.refresh(); }, - make_bom: function(frm) { + make_bom: function (frm) { frappe.call({ method: "make_bom", doc: frm.doc, - callback: function(r){ + callback: function (r) { if (r.message) { var doc = frappe.model.sync(r.message)[0]; frappe.set_route("Form", doc.doctype, doc.name); } - } + }, }); }, - show_progress_for_items: function(frm) { + show_progress_for_items: function (frm) { var bars = []; - var message = ''; + var message = ""; var added_min = false; // produced qty - var title = __('{0} items produced', [frm.doc.produced_qty]); + var title = __("{0} items produced", [frm.doc.produced_qty]); bars.push({ - 'title': title, - 'width': (frm.doc.produced_qty / frm.doc.qty * 100) + '%', - 'progress_class': 'progress-bar-success' + title: title, + width: (frm.doc.produced_qty / frm.doc.qty) * 100 + "%", + progress_class: "progress-bar-success", }); - if (bars[0].width == '0%') { - bars[0].width = '0.5%'; + if (bars[0].width == "0%") { + bars[0].width = "0.5%"; added_min = 0.5; } message = title; // pending qty - if(!frm.doc.skip_transfer){ + if (!frm.doc.skip_transfer) { var pending_complete = frm.doc.material_transferred_for_manufacturing - frm.doc.produced_qty; - if(pending_complete) { - var width = ((pending_complete / frm.doc.qty * 100) - added_min); - title = __('{0} items in progress', [pending_complete]); + if (pending_complete) { + var width = (pending_complete / frm.doc.qty) * 100 - added_min; + title = __("{0} items in progress", [pending_complete]); bars.push({ - 'title': title, - 'width': (width > 100 ? "99.5" : width) + '%', - 'progress_class': 'progress-bar-warning' + title: title, + width: (width > 100 ? "99.5" : width) + "%", + progress_class: "progress-bar-warning", }); - message = message + '. ' + title; + message = message + ". " + title; } } - frm.dashboard.add_progress(__('Status'), bars, message); + frm.dashboard.add_progress(__("Status"), bars, message); }, - show_progress_for_operations: function(frm) { + show_progress_for_operations: function (frm) { if (frm.doc.operations && frm.doc.operations.length) { - let progress_class = { "Work in Progress": "progress-bar-warning", - "Completed": "progress-bar-success" + Completed: "progress-bar-success", }; let bars = []; - let message = ''; - let title = ''; + let message = ""; + let title = ""; let status_wise_oprtation_data = {}; let total_completed_qty = frm.doc.qty * frm.doc.operations.length; - frm.doc.operations.forEach(d => { + frm.doc.operations.forEach((d) => { if (!status_wise_oprtation_data[d.status]) { status_wise_oprtation_data[d.status] = [d.completed_qty, d.operation]; } else { status_wise_oprtation_data[d.status][0] += d.completed_qty; - status_wise_oprtation_data[d.status][1] += ', ' + d.operation; + status_wise_oprtation_data[d.status][1] += ", " + d.operation; } }); for (let key in status_wise_oprtation_data) { title = __("{0} Operations: {1}", [key, status_wise_oprtation_data[key][1].bold()]); bars.push({ - 'title': title, - 'width': status_wise_oprtation_data[key][0] / total_completed_qty * 100 + '%', - 'progress_class': progress_class[key] + title: title, + width: (status_wise_oprtation_data[key][0] / total_completed_qty) * 100 + "%", + progress_class: progress_class[key], }); - message += title + '. '; + message += title + ". "; } - frm.dashboard.add_progress(__('Status'), bars, message); + frm.dashboard.add_progress(__("Status"), bars, message); } }, - production_item: function(frm) { + production_item: function (frm) { if (frm.doc.production_item) { frappe.call({ method: "erpnext.manufacturing.doctype.work_order.work_order.get_item_details", args: { item: frm.doc.production_item, - project: frm.doc.project + project: frm.doc.project, }, freeze: true, - callback: function(r) { - if(r.message) { - frm.set_value('sales_order', ""); - frm.trigger('set_sales_order'); + callback: function (r) { + if (r.message) { + frm.set_value("sales_order", ""); + frm.trigger("set_sales_order"); erpnext.in_production_item_onchange = true; - $.each(["description", "stock_uom", "project", "bom_no", "allow_alternative_item", - "transfer_material_against", "item_name"], function(i, field) { - frm.set_value(field, r.message[field]); - }); + $.each( + [ + "description", + "stock_uom", + "project", + "bom_no", + "allow_alternative_item", + "transfer_material_against", + "item_name", + ], + function (i, field) { + frm.set_value(field, r.message[field]); + } + ); - if(r.message["set_scrap_wh_mandatory"]){ + if (r.message["set_scrap_wh_mandatory"]) { frm.toggle_reqd("scrap_warehouse", true); } erpnext.in_production_item_onchange = false; } - } + }, }); } }, - project: function(frm) { - if(!erpnext.in_production_item_onchange && !frm.doc.bom_no) { + project: function (frm) { + if (!erpnext.in_production_item_onchange && !frm.doc.bom_no) { frm.trigger("production_item"); } }, - bom_no: function(frm) { + bom_no: function (frm) { return frm.call({ doc: frm.doc, method: "get_items_and_operations_from_bom", freeze: true, - callback: function(r) { - if(r.message["set_scrap_wh_mandatory"]){ + callback: function (r) { + if (r.message["set_scrap_wh_mandatory"]) { frm.toggle_reqd("scrap_warehouse", true); } - } + }, }); }, - use_multi_level_bom: function(frm) { - if(frm.doc.bom_no) { + use_multi_level_bom: function (frm) { + if (frm.doc.bom_no) { frm.trigger("bom_no"); } }, - qty: function(frm) { - frm.trigger('bom_no'); + qty: function (frm) { + frm.trigger("bom_no"); }, - before_submit: function(frm) { + before_submit: function (frm) { frm.fields_dict.required_items.grid.toggle_reqd("source_warehouse", true); - frm.toggle_reqd("transfer_material_against", - frm.doc.operations && frm.doc.operations.length > 0); + frm.toggle_reqd("transfer_material_against", frm.doc.operations && frm.doc.operations.length > 0); }, - set_sales_order: function(frm) { - if(frm.doc.production_item) { + set_sales_order: function (frm) { + if (frm.doc.production_item) { frappe.call({ method: "erpnext.manufacturing.doctype.work_order.work_order.query_sales_order", args: { production_item: frm.doc.production_item }, - callback: function(r) { - frm.set_query("sales_order", function() { + callback: function (r) { + frm.set_query("sales_order", function () { erpnext.in_production_item_onchange = true; return { - filters: [ - ["Sales Order","name", "in", r.message] - ] + filters: [["Sales Order", "name", "in", r.message]], }; }); - } + }, }); } }, - additional_operating_cost: function(frm) { + additional_operating_cost: function (frm) { erpnext.work_order.calculate_cost(frm.doc); erpnext.work_order.calculate_total_cost(frm); }, }); frappe.ui.form.on("Work Order Item", { - source_warehouse: function(frm, cdt, cdn) { + source_warehouse: function (frm, cdt, cdn) { var row = locals[cdt][cdn]; - if(!row.item_code) { + if (!row.item_code) { frappe.throw(__("Please set the Item Code first")); - } else if(row.source_warehouse) { + } else if (row.source_warehouse) { frappe.call({ - "method": "erpnext.stock.utils.get_latest_stock_qty", + method: "erpnext.stock.utils.get_latest_stock_qty", args: { item_code: row.item_code, - warehouse: row.source_warehouse + warehouse: row.source_warehouse, }, callback: function (r) { - frappe.model.set_value(row.doctype, row.name, - "available_qty_at_source_warehouse", r.message); - } + frappe.model.set_value( + row.doctype, + row.name, + "available_qty_at_source_warehouse", + r.message + ); + }, }); } }, - item_code: function(frm, cdt, cdn) { + item_code: function (frm, cdt, cdn) { let row = locals[cdt][cdn]; if (row.item_code) { @@ -508,94 +535,104 @@ frappe.ui.form.on("Work Order Item", { method: "erpnext.stock.doctype.item.item.get_item_details", args: { item_code: row.item_code, - company: frm.doc.company + company: frm.doc.company, }, - callback: function(r) { + callback: function (r) { if (r.message) { frappe.model.set_value(cdt, cdn, { - "required_qty": row.required_qty || 1, - "item_name": r.message.item_name, - "description": r.message.description, - "source_warehouse": r.message.default_warehouse, - "allow_alternative_item": r.message.allow_alternative_item, - "include_item_in_manufacturing": r.message.include_item_in_manufacturing + required_qty: row.required_qty || 1, + item_name: r.message.item_name, + description: r.message.description, + source_warehouse: r.message.default_warehouse, + allow_alternative_item: r.message.allow_alternative_item, + include_item_in_manufacturing: r.message.include_item_in_manufacturing, }); } - } + }, }); } - } + }, }); frappe.ui.form.on("Work Order Operation", { - workstation: function(frm, cdt, cdn) { + workstation: function (frm, cdt, cdn) { var d = locals[cdt][cdn]; if (d.workstation) { frappe.call({ - "method": "frappe.client.get", + method: "frappe.client.get", args: { doctype: "Workstation", - name: d.workstation + name: d.workstation, }, callback: function (data) { frappe.model.set_value(d.doctype, d.name, "hour_rate", data.message.hour_rate); erpnext.work_order.calculate_cost(frm.doc); erpnext.work_order.calculate_total_cost(frm); - } + }, }); } }, - time_in_mins: function(frm, cdt, cdn) { + time_in_mins: function (frm, cdt, cdn) { erpnext.work_order.calculate_cost(frm.doc); erpnext.work_order.calculate_total_cost(frm); }, }); erpnext.work_order = { - set_custom_buttons: function(frm) { + set_custom_buttons: function (frm) { var doc = frm.doc; if (doc.status !== "Closed") { - frm.add_custom_button(__('Close'), function() { - frappe.confirm(__("Once the Work Order is Closed. It can't be resumed."), - () => { + frm.add_custom_button( + __("Close"), + function () { + frappe.confirm(__("Once the Work Order is Closed. It can't be resumed."), () => { erpnext.work_order.change_work_order_status(frm, "Closed"); - } - ); - }, __("Status")); + }); + }, + __("Status") + ); } if (doc.docstatus === 1 && !in_list(["Closed", "Completed"], doc.status)) { - if (doc.status != 'Stopped' && doc.status != 'Completed') { - frm.add_custom_button(__('Stop'), function() { - erpnext.work_order.change_work_order_status(frm, "Stopped"); - }, __("Status")); - } else if (doc.status == 'Stopped') { - frm.add_custom_button(__('Re-open'), function() { - erpnext.work_order.change_work_order_status(frm, "Resumed"); - }, __("Status")); + if (doc.status != "Stopped" && doc.status != "Completed") { + frm.add_custom_button( + __("Stop"), + function () { + erpnext.work_order.change_work_order_status(frm, "Stopped"); + }, + __("Status") + ); + } else if (doc.status == "Stopped") { + frm.add_custom_button( + __("Re-open"), + function () { + erpnext.work_order.change_work_order_status(frm, "Resumed"); + }, + __("Status") + ); } - const show_start_btn = (frm.doc.skip_transfer - || frm.doc.transfer_material_against == 'Job Card') ? 0 : 1; + const show_start_btn = + frm.doc.skip_transfer || frm.doc.transfer_material_against == "Job Card" ? 0 : 1; if (show_start_btn) { let pending_to_transfer = frm.doc.required_items.some( - item => flt(item.transferred_qty) < flt(item.required_qty) + (item) => flt(item.transferred_qty) < flt(item.required_qty) ); - if (pending_to_transfer && frm.doc.status != 'Stopped') { + if (pending_to_transfer && frm.doc.status != "Stopped") { frm.has_start_btn = true; - frm.add_custom_button(__('Create Pick List'), function() { + frm.add_custom_button(__("Create Pick List"), function () { erpnext.work_order.create_pick_list(frm); }); - var start_btn = frm.add_custom_button(__('Start'), function() { - erpnext.work_order.make_se(frm, 'Material Transfer for Manufacture'); + var start_btn = frm.add_custom_button(__("Start"), function () { + erpnext.work_order.make_se(frm, "Material Transfer for Manufacture"); }); - start_btn.addClass('btn-primary'); + start_btn.addClass("btn-primary"); } } - if (frm.doc.status != 'Stopped') { + if (frm.doc.status != "Stopped") { // If "Material Consumption is check in Manufacturing Settings, allow Material Consumption if (frm.doc.__onload && frm.doc.__onload.material_consumption == 1) { if (flt(doc.material_transferred_for_manufacturing) > 0 || frm.doc.skip_transfer) { @@ -604,89 +641,102 @@ erpnext.work_order = { var tbl = frm.doc.required_items || []; var tbl_lenght = tbl.length; for (var i = 0, len = tbl_lenght; i < len; i++) { - let wo_item_qty = frm.doc.required_items[i].transferred_qty || frm.doc.required_items[i].required_qty; + let wo_item_qty = + frm.doc.required_items[i].transferred_qty || + frm.doc.required_items[i].required_qty; if (flt(wo_item_qty) > flt(frm.doc.required_items[i].consumed_qty)) { counter += 1; } } if (counter > 0) { - var consumption_btn = frm.add_custom_button(__('Material Consumption'), function() { - const backflush_raw_materials_based_on = frm.doc.__onload.backflush_raw_materials_based_on; - erpnext.work_order.make_consumption_se(frm, backflush_raw_materials_based_on); - }); - consumption_btn.addClass('btn-primary'); + var consumption_btn = frm.add_custom_button( + __("Material Consumption"), + function () { + const backflush_raw_materials_based_on = + frm.doc.__onload.backflush_raw_materials_based_on; + erpnext.work_order.make_consumption_se( + frm, + backflush_raw_materials_based_on + ); + } + ); + consumption_btn.addClass("btn-primary"); } } } - if(!frm.doc.skip_transfer){ + if (!frm.doc.skip_transfer) { if (flt(doc.material_transferred_for_manufacturing) > 0) { - if ((flt(doc.produced_qty) < flt(doc.material_transferred_for_manufacturing))) { + if (flt(doc.produced_qty) < flt(doc.material_transferred_for_manufacturing)) { frm.has_finish_btn = true; - var finish_btn = frm.add_custom_button(__('Finish'), function() { - erpnext.work_order.make_se(frm, 'Manufacture'); + var finish_btn = frm.add_custom_button(__("Finish"), function () { + erpnext.work_order.make_se(frm, "Manufacture"); }); - if(doc.material_transferred_for_manufacturing>=doc.qty) { + if (doc.material_transferred_for_manufacturing >= doc.qty) { // all materials transferred for manufacturing, make this primary - finish_btn.addClass('btn-primary'); + finish_btn.addClass("btn-primary"); } } else if (frm.doc.__onload && frm.doc.__onload.overproduction_percentage) { let allowance_percentage = frm.doc.__onload.overproduction_percentage; if (allowance_percentage > 0) { - let allowed_qty = frm.doc.qty + ((allowance_percentage / 100) * frm.doc.qty); + let allowed_qty = frm.doc.qty + (allowance_percentage / 100) * frm.doc.qty; - if ((flt(doc.produced_qty) < allowed_qty)) { - frm.add_custom_button(__('Finish'), function() { - erpnext.work_order.make_se(frm, 'Manufacture'); + if (flt(doc.produced_qty) < allowed_qty) { + frm.add_custom_button(__("Finish"), function () { + erpnext.work_order.make_se(frm, "Manufacture"); }); } } } } } else { - if ((flt(doc.produced_qty) < flt(doc.qty))) { - var finish_btn = frm.add_custom_button(__('Finish'), function() { - erpnext.work_order.make_se(frm, 'Manufacture'); + if (flt(doc.produced_qty) < flt(doc.qty)) { + var finish_btn = frm.add_custom_button(__("Finish"), function () { + erpnext.work_order.make_se(frm, "Manufacture"); }); - finish_btn.addClass('btn-primary'); + finish_btn.addClass("btn-primary"); } } } } }, - calculate_cost: function(doc) { - if (doc.operations){ + calculate_cost: function (doc) { + if (doc.operations) { var op = doc.operations; doc.planned_operating_cost = 0.0; - for(var i=0;i { - frappe.prompt({ - fieldtype: 'Float', - label: __('Qty for {0}', [__(purpose)]), - fieldname: 'qty', - description: __('Max: {0}', [max]), - default: max - }, data => { - max += (frm.doc.qty * (frm.doc.__onload.overproduction_percentage || 0.0)) / 100; - - if (data.qty > max) { - frappe.msgprint(__('Quantity must not be more than {0}', [max])); - reject(); - } - data.purpose = purpose; - resolve(data); - }, __('Select Quantity'), __('Create')); + frappe.prompt( + { + fieldtype: "Float", + label: __("Qty for {0}", [__(purpose)]), + fieldname: "qty", + description: __("Max: {0}", [max]), + default: max, + }, + (data) => { + max += (frm.doc.qty * (frm.doc.__onload.overproduction_percentage || 0.0)) / 100; + + if (data.qty > max) { + frappe.msgprint(__("Quantity must not be more than {0}", [max])); + reject(); + } + data.purpose = purpose; + resolve(data); + }, + __("Select Quantity"), + __("Create") + ); }); }, - make_se: function(frm, purpose) { + make_se: function (frm, purpose) { this.show_prompt_for_qty_input(frm, purpose) - .then(data => { - return frappe.xcall('erpnext.manufacturing.doctype.work_order.work_order.make_stock_entry', { - 'work_order_id': frm.doc.name, - 'purpose': purpose, - 'qty': data.qty + .then((data) => { + return frappe.xcall("erpnext.manufacturing.doctype.work_order.work_order.make_stock_entry", { + work_order_id: frm.doc.name, + purpose: purpose, + qty: data.qty, }); - }).then(stock_entry => { + }) + .then((stock_entry) => { frappe.model.sync(stock_entry); - frappe.set_route('Form', stock_entry.doctype, stock_entry.name); + frappe.set_route("Form", stock_entry.doctype, stock_entry.name); }); - }, - create_pick_list: function(frm, purpose='Material Transfer for Manufacture') { + create_pick_list: function (frm, purpose = "Material Transfer for Manufacture") { this.show_prompt_for_qty_input(frm, purpose) - .then(data => { - return frappe.xcall('erpnext.manufacturing.doctype.work_order.work_order.create_pick_list', { - 'source_name': frm.doc.name, - 'for_qty': data.qty + .then((data) => { + return frappe.xcall("erpnext.manufacturing.doctype.work_order.work_order.create_pick_list", { + source_name: frm.doc.name, + for_qty: data.qty, }); - }).then(pick_list => { + }) + .then((pick_list) => { frappe.model.sync(pick_list); - frappe.set_route('Form', pick_list.doctype, pick_list.name); + frappe.set_route("Form", pick_list.doctype, pick_list.name); }); }, - make_consumption_se: function(frm, backflush_raw_materials_based_on) { - if(!frm.doc.skip_transfer){ - var max = (backflush_raw_materials_based_on === "Material Transferred for Manufacture") ? - flt(frm.doc.material_transferred_for_manufacturing) - flt(frm.doc.produced_qty) : - flt(frm.doc.qty) - flt(frm.doc.produced_qty); - // flt(frm.doc.qty) - flt(frm.doc.material_transferred_for_manufacturing); + make_consumption_se: function (frm, backflush_raw_materials_based_on) { + if (!frm.doc.skip_transfer) { + var max = + backflush_raw_materials_based_on === "Material Transferred for Manufacture" + ? flt(frm.doc.material_transferred_for_manufacturing) - flt(frm.doc.produced_qty) + : flt(frm.doc.qty) - flt(frm.doc.produced_qty); + // flt(frm.doc.qty) - flt(frm.doc.material_transferred_for_manufacturing); } else { var max = flt(frm.doc.qty) - flt(frm.doc.produced_qty); } frappe.call({ - method:"erpnext.manufacturing.doctype.work_order.work_order.make_stock_entry", + method: "erpnext.manufacturing.doctype.work_order.work_order.make_stock_entry", args: { - "work_order_id": frm.doc.name, - "purpose": "Material Consumption for Manufacture", - "qty": max + work_order_id: frm.doc.name, + purpose: "Material Consumption for Manufacture", + qty: max, }, - callback: function(r) { + callback: function (r) { var doclist = frappe.model.sync(r.message); frappe.set_route("Form", doclist[0].doctype, doclist[0].name); - } + }, }); }, - change_work_order_status: function(frm, status) { - let method_name = status=="Closed" ? "close_work_order" : "stop_unstop"; + change_work_order_status: function (frm, status) { + let method_name = status == "Closed" ? "close_work_order" : "stop_unstop"; frappe.call({ method: `erpnext.manufacturing.doctype.work_order.work_order.${method_name}`, freeze: true, freeze_message: __("Updating Work Order status"), args: { work_order: frm.doc.name, - status: status + status: status, }, - callback: function(r) { - if(r.message) { + callback: function (r) { + if (r.message) { frm.set_value("status", r.message); frm.reload_doc(); } - } + }, }); - } + }, }; -frappe.tour['Work Order'] = [ +frappe.tour["Work Order"] = [ { fieldname: "production_item", title: "Item to Manufacture", - description: __("Select the Item to be manufactured.") + description: __("Select the Item to be manufactured."), }, { fieldname: "bom_no", title: "BOM No", - description: __("The default BOM for that item will be fetched by the system. You can also change the BOM.") + description: __( + "The default BOM for that item will be fetched by the system. You can also change the BOM." + ), }, { fieldname: "qty", title: "Qty to Manufacture", - description: __("Enter the quantity to manufacture. Raw material Items will be fetched only when this is set.") + description: __( + "Enter the quantity to manufacture. Raw material Items will be fetched only when this is set." + ), }, { fieldname: "use_multi_level_bom", title: "Use Multi-Level BOM", - description: __("This is enabled by default. If you want to plan materials for sub-assemblies of the Item you're manufacturing leave this enabled. If you plan and manufacture the sub-assemblies separately, you can disable this checkbox.") + description: __( + "This is enabled by default. If you want to plan materials for sub-assemblies of the Item you're manufacturing leave this enabled. If you plan and manufacture the sub-assemblies separately, you can disable this checkbox." + ), }, { fieldname: "source_warehouse", title: "Source Warehouse", - description: __("The warehouse where you store your raw materials. Each required item can have a separate source warehouse. Group warehouse also can be selected as source warehouse. On submission of the Work Order, the raw materials will be reserved in these warehouses for production usage.") + description: __( + "The warehouse where you store your raw materials. Each required item can have a separate source warehouse. Group warehouse also can be selected as source warehouse. On submission of the Work Order, the raw materials will be reserved in these warehouses for production usage." + ), }, { fieldname: "fg_warehouse", title: "Target Warehouse", - description: __("The warehouse where you store finished Items before they are shipped.") + description: __("The warehouse where you store finished Items before they are shipped."), }, { fieldname: "wip_warehouse", title: "Work-in-Progress Warehouse", - description: __("The warehouse where your Items will be transferred when you begin production. Group Warehouse can also be selected as a Work in Progress warehouse.") + description: __( + "The warehouse where your Items will be transferred when you begin production. Group Warehouse can also be selected as a Work in Progress warehouse." + ), }, { fieldname: "scrap_warehouse", title: "Scrap Warehouse", - description: __("If the BOM results in Scrap material, the Scrap Warehouse needs to be selected.") + description: __("If the BOM results in Scrap material, the Scrap Warehouse needs to be selected."), }, { fieldname: "required_items", title: "Required Items", - description: __("All the required items (raw materials) will be fetched from BOM and populated in this table. Here you can also change the Source Warehouse for any item. And during the production, you can track transferred raw materials from this table.") + description: __( + "All the required items (raw materials) will be fetched from BOM and populated in this table. Here you can also change the Source Warehouse for any item. And during the production, you can track transferred raw materials from this table." + ), }, { fieldname: "planned_start_date", title: "Planned Start Date", - description: __("Set the Planned Start Date (an Estimated Date at which you want the Production to begin)") + description: __( + "Set the Planned Start Date (an Estimated Date at which you want the Production to begin)" + ), }, { fieldname: "operations", title: "Operations", - description: __("If the selected BOM has Operations mentioned in it, the system will fetch all Operations from BOM, these values can be changed.") + description: __( + "If the selected BOM has Operations mentioned in it, the system will fetch all Operations from BOM, these values can be changed." + ), }, - - ]; diff --git a/erpnext/manufacturing/doctype/work_order/work_order_calendar.js b/erpnext/manufacturing/doctype/work_order/work_order_calendar.js index 7ce05e9b8814..90ce74ce232c 100644 --- a/erpnext/manufacturing/doctype/work_order/work_order_calendar.js +++ b/erpnext/manufacturing/doctype/work_order/work_order_calendar.js @@ -2,23 +2,23 @@ // For license information, please see license.txt frappe.views.calendar["Work Order"] = { - fields: ["planned_start_date", "planned_end_date", "status", "produced_qty", "qty", "name", "name"], + fields: ["planned_start_date", "planned_end_date", "status", "produced_qty", "qty", "name", "name"], field_map: { - "start": "planned_start_date", - "end": "planned_end_date", - "id": "name", - "title": "name", - "status": "status", - "allDay": "allDay", - "progress": function(data) { - return flt(data.produced_qty) / data.qty * 100; - } + start: "planned_start_date", + end: "planned_end_date", + id: "name", + title: "name", + status: "status", + allDay: "allDay", + progress: function (data) { + return (flt(data.produced_qty) / data.qty) * 100; + }, }, gantt: true, - get_css_class: function(data) { - if(data.status==="Completed") { + get_css_class: function (data) { + if (data.status === "Completed") { return "success"; - } else if(data.status==="In Process") { + } else if (data.status === "In Process") { return "warning"; } else { return "danger"; @@ -26,23 +26,23 @@ frappe.views.calendar["Work Order"] = { }, filters: [ { - "fieldtype": "Link", - "fieldname": "sales_order", - "options": "Sales Order", - "label": __("Sales Order") + fieldtype: "Link", + fieldname: "sales_order", + options: "Sales Order", + label: __("Sales Order"), }, { - "fieldtype": "Link", - "fieldname": "production_item", - "options": "Item", - "label": __("Production Item") + fieldtype: "Link", + fieldname: "production_item", + options: "Item", + label: __("Production Item"), }, { - "fieldtype": "Link", - "fieldname": "wip_warehouse", - "options": "Warehouse", - "label": __("WIP Warehouse") - } + fieldtype: "Link", + fieldname: "wip_warehouse", + options: "Warehouse", + label: __("WIP Warehouse"), + }, ], - get_events_method: "frappe.desk.calendar.get_events" -} + get_events_method: "frappe.desk.calendar.get_events", +}; diff --git a/erpnext/manufacturing/doctype/work_order/work_order_list.js b/erpnext/manufacturing/doctype/work_order/work_order_list.js index 81c23bb71044..1e1e5661fe58 100644 --- a/erpnext/manufacturing/doctype/work_order/work_order_list.js +++ b/erpnext/manufacturing/doctype/work_order/work_order_list.js @@ -1,19 +1,31 @@ -frappe.listview_settings['Work Order'] = { - add_fields: ["bom_no", "status", "sales_order", "qty", - "produced_qty", "expected_delivery_date", "planned_start_date", "planned_end_date"], +frappe.listview_settings["Work Order"] = { + add_fields: [ + "bom_no", + "status", + "sales_order", + "qty", + "produced_qty", + "expected_delivery_date", + "planned_start_date", + "planned_end_date", + ], filters: [["status", "!=", "Stopped"]], - get_indicator: function(doc) { - if(doc.status==="Submitted") { + get_indicator: function (doc) { + if (doc.status === "Submitted") { return [__("Not Started"), "orange", "status,=,Submitted"]; } else { - return [__(doc.status), { - "Draft": "red", - "Stopped": "red", - "Not Started": "red", - "In Process": "orange", - "Completed": "green", - "Cancelled": "gray" - }[doc.status], "status,=," + doc.status]; + return [ + __(doc.status), + { + Draft: "red", + Stopped: "red", + "Not Started": "red", + "In Process": "orange", + Completed: "green", + Cancelled: "gray", + }[doc.status], + "status,=," + doc.status, + ]; } - } + }, }; diff --git a/erpnext/manufacturing/doctype/workstation/_test_workstation.js b/erpnext/manufacturing/doctype/workstation/_test_workstation.js index 0f09bd1c61f3..44050d0a85a4 100644 --- a/erpnext/manufacturing/doctype/workstation/_test_workstation.js +++ b/erpnext/manufacturing/doctype/workstation/_test_workstation.js @@ -8,16 +8,16 @@ QUnit.test("test: Workstation", function (assert) { // number of asserts assert.expect(1); - frappe.run_serially('Workstation', [ + frappe.run_serially("Workstation", [ // insert a new Workstation - () => frappe.tests.make([ - // values to be set - {key: 'value'} - ]), + () => + frappe.tests.make([ + // values to be set + { key: "value" }, + ]), () => { - assert.equal(cur_frm.doc.key, 'value'); + assert.equal(cur_frm.doc.key, "value"); }, - () => done() + () => done(), ]); - }); diff --git a/erpnext/manufacturing/doctype/workstation/workstation.js b/erpnext/manufacturing/doctype/workstation/workstation.js index f830b170ed0e..5381e4402707 100644 --- a/erpnext/manufacturing/doctype/workstation/workstation.js +++ b/erpnext/manufacturing/doctype/workstation/workstation.js @@ -3,17 +3,16 @@ frappe.ui.form.on("Workstation", { onload(frm) { - if(frm.is_new()) - { + if (frm.is_new()) { frappe.call({ - type:"GET", - method:"erpnext.manufacturing.doctype.workstation.workstation.get_default_holiday_list", - callback: function(r) { - if(!r.exe && r.message){ + type: "GET", + method: "erpnext.manufacturing.doctype.workstation.workstation.get_default_holiday_list", + callback: function (r) { + if (!r.exe && r.message) { cur_frm.set_value("holiday_list", r.message); } - } - }) + }, + }); } }, @@ -22,35 +21,39 @@ frappe.ui.form.on("Workstation", { frm.call({ method: "set_data_based_on_workstation_type", doc: frm.doc, - callback: function(r) { + callback: function (r) { frm.refresh_fields(); - } - }) + }, + }); } - } + }, }); -frappe.tour['Workstation'] = [ +frappe.tour["Workstation"] = [ { fieldname: "workstation_name", title: "Workstation Name", - description: __("You can set it as a machine name or operation type. For example, stiching machine 12") + description: __( + "You can set it as a machine name or operation type. For example, stiching machine 12" + ), }, { fieldname: "production_capacity", title: "Production Capacity", - description: __("No. of parallel job cards which can be allowed on this workstation. Example: 2 would mean this workstation can process production for two Work Orders at a time.") + description: __( + "No. of parallel job cards which can be allowed on this workstation. Example: 2 would mean this workstation can process production for two Work Orders at a time." + ), }, { fieldname: "holiday_list", title: "Holiday List", - description: __("A Holiday List can be added to exclude counting these days for the Workstation.") + description: __("A Holiday List can be added to exclude counting these days for the Workstation."), }, { fieldname: "working_hours", title: "Working Hours", - description: __("Under Working Hours table, you can add start and end times for a Workstation. For example, a Workstation may be active from 9 am to 1 pm, then 2 pm to 5 pm. You can also specify the working hours based on shifts. While scheduling a Work Order, the system will check for the availability of the Workstation based on the working hours specified.") + description: __( + "Under Working Hours table, you can add start and end times for a Workstation. For example, a Workstation may be active from 9 am to 1 pm, then 2 pm to 5 pm. You can also specify the working hours based on shifts. While scheduling a Work Order, the system will check for the availability of the Workstation based on the working hours specified." + ), }, - - ]; diff --git a/erpnext/manufacturing/doctype/workstation/workstation_list.js b/erpnext/manufacturing/doctype/workstation/workstation_list.js index 6a89d21e1efa..77af49acf190 100644 --- a/erpnext/manufacturing/doctype/workstation/workstation_list.js +++ b/erpnext/manufacturing/doctype/workstation/workstation_list.js @@ -1,5 +1,5 @@ /* eslint-disable */ -frappe.listview_settings['Workstation'] = { +frappe.listview_settings["Workstation"] = { // add_fields: ["status"], // filters:[["status","=", "Open"]] }; diff --git a/erpnext/manufacturing/doctype/workstation_type/workstation_type.js b/erpnext/manufacturing/doctype/workstation_type/workstation_type.js index 419fa6c10ad5..f0b3ed36a5e4 100644 --- a/erpnext/manufacturing/doctype/workstation_type/workstation_type.js +++ b/erpnext/manufacturing/doctype/workstation_type/workstation_type.js @@ -1,8 +1,7 @@ // Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Workstation Type', { +frappe.ui.form.on("Workstation Type", { // refresh: function(frm) { - // } }); diff --git a/erpnext/manufacturing/page/bom_comparison_tool/bom_comparison_tool.js b/erpnext/manufacturing/page/bom_comparison_tool/bom_comparison_tool.js index 1bcb1efdaadf..fcb7e884ecc3 100644 --- a/erpnext/manufacturing/page/bom_comparison_tool/bom_comparison_tool.js +++ b/erpnext/manufacturing/page/bom_comparison_tool/bom_comparison_tool.js @@ -1,12 +1,12 @@ -frappe.pages['bom-comparison-tool'].on_page_load = function(wrapper) { +frappe.pages["bom-comparison-tool"].on_page_load = function (wrapper) { var page = frappe.ui.make_app_page({ parent: wrapper, - title: __('BOM Comparison Tool'), - single_column: true + title: __("BOM Comparison Tool"), + single_column: true, }); new erpnext.BOMComparisonTool(page); -} +}; erpnext.BOMComparisonTool = class BOMComparisonTool { constructor(page) { @@ -18,45 +18,45 @@ erpnext.BOMComparisonTool = class BOMComparisonTool { this.form = new frappe.ui.FieldGroup({ fields: [ { - label: __('BOM 1'), - fieldname: 'name1', - fieldtype: 'Link', - options: 'BOM', + label: __("BOM 1"), + fieldname: "name1", + fieldtype: "Link", + options: "BOM", change: () => this.fetch_and_render(), get_query: () => { return { filters: { - "name": ["not in", [this.form.get_value("name2") || ""]] - } - } - } + name: ["not in", [this.form.get_value("name2") || ""]], + }, + }; + }, }, { - fieldtype: 'Column Break' + fieldtype: "Column Break", }, { - label: __('BOM 2'), - fieldname: 'name2', - fieldtype: 'Link', - options: 'BOM', + label: __("BOM 2"), + fieldname: "name2", + fieldtype: "Link", + options: "BOM", change: () => this.fetch_and_render(), get_query: () => { return { filters: { - "name": ["not in", [this.form.get_value("name1") || ""]] - } - } - } + name: ["not in", [this.form.get_value("name1") || ""]], + }, + }; + }, }, { - fieldtype: 'Section Break' + fieldtype: "Section Break", }, { - fieldtype: 'HTML', - fieldname: 'preview' - } + fieldtype: "HTML", + fieldname: "preview", + }, ], - body: this.page.body + body: this.page.body, }); this.form.make(); } @@ -64,33 +64,34 @@ erpnext.BOMComparisonTool = class BOMComparisonTool { fetch_and_render() { let { name1, name2 } = this.form.get_values(); if (!(name1 && name2)) { - this.form.get_field('preview').html(''); + this.form.get_field("preview").html(""); return; } // set working state - this.form.get_field('preview').html(` + this.form.get_field("preview").html(`
    ${__("Fetching...")}
    `); - frappe.call('erpnext.manufacturing.doctype.bom.bom.get_bom_diff', { - bom1: name1, - bom2: name2 - }).then(r => { - let diff = r.message; - frappe.model.with_doctype('BOM', () => { - this.render('BOM', name1, name2, diff); + frappe + .call("erpnext.manufacturing.doctype.bom.bom.get_bom_diff", { + bom1: name1, + bom2: name2, + }) + .then((r) => { + let diff = r.message; + frappe.model.with_doctype("BOM", () => { + this.render("BOM", name1, name2, diff); + }); }); - }); } render(doctype, name1, name2, diff) { - let change_html = (title, doctype, changed) => { let values_changed = this.get_changed_values(doctype, changed) - .map(change => { + .map((change) => { let [fieldname, value1, value2] = change; return `
    @@ -100,14 +101,14 @@ erpnext.BOMComparisonTool = class BOMComparisonTool { `; }) - .join(''); + .join(""); return `

    ${title}

    - ${__('Notes')} + ${__("Notes")}

    • - ${__("Loyalty Points will be calculated from the spent done (via the Sales Invoice), based on collection factor mentioned.")} + ${__( + "Loyalty Points will be calculated from the spent done (via the Sales Invoice), based on collection factor mentioned." + )}
    • - ${__("There can be multiple tiered collection factor based on the total spent. But the conversion factor for redemption will always be same for all the tier.")} + ${__( + "There can be multiple tiered collection factor based on the total spent. But the conversion factor for redemption will always be same for all the tier." + )}
    • - ${__("In the case of multi-tier program, Customers will be auto assigned to the concerned tier as per their spent")} + ${__( + "In the case of multi-tier program, Customers will be auto assigned to the concerned tier as per their spent" + )}
    • ${__("If unlimited expiry for the Loyalty Points, keep the Expiry Duration empty or 0.")}
    • - ${__("If Auto Opt In is checked, then the customers will be automatically linked with the concerned Loyalty Program (on save)")} + ${__( + "If Auto Opt In is checked, then the customers will be automatically linked with the concerned Loyalty Program (on save)" + )}
    • ${__("One customer can be part of only single Loyalty Program.")} @@ -37,14 +44,14 @@ frappe.ui.form.on('Loyalty Program', { set_field_options("loyalty_program_help", help_content); }, - onload: function(frm) { - frm.set_query("expense_account", function(doc) { + onload: function (frm) { + frm.set_query("expense_account", function (doc) { return { filters: { - "root_type": "Expense", - 'is_group': 0, - 'company': doc.company - } + root_type: "Expense", + is_group: 0, + company: doc.company, + }, }; }); @@ -52,13 +59,15 @@ frappe.ui.form.on('Loyalty Program', { erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype); }, - refresh: function(frm) { + refresh: function (frm) { if (frm.doc.loyalty_program_type === "Single Tier Program" && frm.doc.collection_rules.length > 1) { - frappe.throw(__("Please select the Multiple Tier Program type for more than one collection rules.")); + frappe.throw( + __("Please select the Multiple Tier Program type for more than one collection rules.") + ); } }, - company: function(frm) { + company: function (frm) { erpnext.accounts.dimensions.update_dimension(frm, frm.doctype); - } + }, }); diff --git a/erpnext/accounts/doctype/mode_of_payment/mode_of_payment.js b/erpnext/accounts/doctype/mode_of_payment/mode_of_payment.js index 103fa96d02d6..25d437f154f9 100644 --- a/erpnext/accounts/doctype/mode_of_payment/mode_of_payment.js +++ b/erpnext/accounts/doctype/mode_of_payment/mode_of_payment.js @@ -1,16 +1,16 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -frappe.ui.form.on('Mode of Payment', { - setup: function(frm) { - frm.set_query("default_account", "accounts", function(doc, cdt, cdn) { +frappe.ui.form.on("Mode of Payment", { + setup: function (frm) { + frm.set_query("default_account", "accounts", function (doc, cdt, cdn) { let d = locals[cdt][cdn]; return { filters: [ - ['Account', 'account_type', 'in', 'Bank, Cash, Receivable'], - ['Account', 'is_group', '=', 0], - ['Account', 'company', '=', d.company] - ] + ["Account", "account_type", "in", "Bank, Cash, Receivable"], + ["Account", "is_group", "=", 0], + ["Account", "company", "=", d.company], + ], }; }); }, diff --git a/erpnext/accounts/doctype/monthly_distribution/monthly_distribution.js b/erpnext/accounts/doctype/monthly_distribution/monthly_distribution.js index 569f0084c6a4..3383534f59e6 100644 --- a/erpnext/accounts/doctype/monthly_distribution/monthly_distribution.js +++ b/erpnext/accounts/doctype/monthly_distribution/monthly_distribution.js @@ -1,16 +1,16 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -frappe.ui.form.on('Monthly Distribution', { +frappe.ui.form.on("Monthly Distribution", { onload(frm) { - if(frm.doc.__islocal) { - return frm.call('get_months').then(() => { - frm.refresh_field('percentages'); + if (frm.doc.__islocal) { + return frm.call("get_months").then(() => { + frm.refresh_field("percentages"); }); } }, refresh(frm) { - frm.toggle_display('distribution_id', frm.doc.__islocal); - } + frm.toggle_display("distribution_id", frm.doc.__islocal); + }, }); diff --git a/erpnext/accounts/doctype/opening_invoice_creation_tool/opening_invoice_creation_tool.js b/erpnext/accounts/doctype/opening_invoice_creation_tool/opening_invoice_creation_tool.js index 88867d11bb87..f1efba8a954f 100644 --- a/erpnext/accounts/doctype/opening_invoice_creation_tool/opening_invoice_creation_tool.js +++ b/erpnext/accounts/doctype/opening_invoice_creation_tool/opening_invoice_creation_tool.js @@ -1,48 +1,52 @@ // Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Opening Invoice Creation Tool', { - setup: function(frm) { - frm.set_query('party_type', 'invoices', function(doc, cdt, cdn) { +frappe.ui.form.on("Opening Invoice Creation Tool", { + setup: function (frm) { + frm.set_query("party_type", "invoices", function (doc, cdt, cdn) { return { filters: { - 'name': ['in', 'Customer, Supplier'] - } + name: ["in", "Customer, Supplier"], + }, }; }); if (frm.doc.company) { - frm.trigger('setup_company_filters'); + frm.trigger("setup_company_filters"); } - frappe.realtime.on('opening_invoice_creation_progress', data => { + frappe.realtime.on("opening_invoice_creation_progress", (data) => { if (!frm.doc.import_in_progress) { frm.dashboard.reset(); frm.doc.import_in_progress = true; } if (data.count == data.total) { - setTimeout(() => { - frm.doc.import_in_progress = false; - frm.clear_table("invoices"); - frm.refresh_fields(); - frm.page.clear_indicator(); - frm.dashboard.hide_progress(); - frappe.msgprint(__("Opening {0} Invoices created", [frm.doc.invoice_type])); - }, 1500, data.title); + setTimeout( + () => { + frm.doc.import_in_progress = false; + frm.clear_table("invoices"); + frm.refresh_fields(); + frm.page.clear_indicator(); + frm.dashboard.hide_progress(); + frappe.msgprint(__("Opening {0} Invoices created", [frm.doc.invoice_type])); + }, + 1500, + data.title + ); return; } frm.dashboard.show_progress(data.title, (data.count / data.total) * 100, data.message); - frm.page.set_indicator(__('In Progress'), 'orange'); + frm.page.set_indicator(__("In Progress"), "orange"); }); erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype); }, - refresh: function(frm) { + refresh: function (frm) { frm.disable_save(); !frm.doc.import_in_progress && frm.trigger("make_dashboard"); - frm.page.set_primary_action(__('Create Invoices'), () => { + frm.page.set_primary_action(__("Create Invoices"), () => { let btn_primary = frm.page.btn_primary.get(0); return frm.call({ doc: frm.doc, @@ -58,100 +62,98 @@ frappe.ui.form.on('Opening Invoice Creation Tool', { } }, - setup_company_filters: function(frm) { - frm.set_query('cost_center', 'invoices', function(doc, cdt, cdn) { + setup_company_filters: function (frm) { + frm.set_query("cost_center", "invoices", function (doc, cdt, cdn) { return { filters: { - 'company': doc.company - } + company: doc.company, + }, }; }); - frm.set_query('cost_center', function(doc) { + frm.set_query("cost_center", function (doc) { return { filters: { - 'company': doc.company - } + company: doc.company, + }, }; }); - frm.set_query('temporary_opening_account', 'invoices', function(doc, cdt, cdn) { + frm.set_query("temporary_opening_account", "invoices", function (doc, cdt, cdn) { return { filters: { - 'company': doc.company - } - } + company: doc.company, + }, + }; }); }, - company: function(frm) { + company: function (frm) { if (frm.doc.company) { - - frm.trigger('setup_company_filters'); + frm.trigger("setup_company_filters"); frappe.call({ - method: 'erpnext.accounts.doctype.opening_invoice_creation_tool.opening_invoice_creation_tool.get_temporary_opening_account', + method: "erpnext.accounts.doctype.opening_invoice_creation_tool.opening_invoice_creation_tool.get_temporary_opening_account", args: { - company: frm.doc.company + company: frm.doc.company, }, callback: (r) => { if (r.message) { frm.doc.__onload.temporary_opening_account = r.message; - frm.trigger('update_invoice_table'); + frm.trigger("update_invoice_table"); } - } - }) + }, + }); } erpnext.accounts.dimensions.update_dimension(frm, frm.doctype); }, - invoice_type: function(frm) { + invoice_type: function (frm) { $.each(frm.doc.invoices, (idx, row) => { - row.party_type = frm.doc.invoice_type == "Sales"? "Customer": "Supplier"; + row.party_type = frm.doc.invoice_type == "Sales" ? "Customer" : "Supplier"; row.party = ""; }); frm.refresh_fields(); }, - make_dashboard: function(frm) { + make_dashboard: function (frm) { let max_count = frm.doc.__onload.max_count; let opening_invoices_summary = frm.doc.__onload.opening_invoices_summary; - if(!$.isEmptyObject(opening_invoices_summary)) { + if (!$.isEmptyObject(opening_invoices_summary)) { let section = frm.dashboard.add_section( - frappe.render_template('opening_invoice_creation_tool_dashboard', { + frappe.render_template("opening_invoice_creation_tool_dashboard", { data: opening_invoices_summary, - max_count: max_count + max_count: max_count, }), __("Opening Invoices Summary") ); - section.on('click', '.invoice-link', function() { - let doctype = $(this).attr('data-type'); - let company = $(this).attr('data-company'); - frappe.set_route('List', doctype, - {'is_opening': 'Yes', 'company': company, 'docstatus': 1}); + section.on("click", ".invoice-link", function () { + let doctype = $(this).attr("data-type"); + let company = $(this).attr("data-company"); + frappe.set_route("List", doctype, { is_opening: "Yes", company: company, docstatus: 1 }); }); frm.dashboard.show(); } }, - update_invoice_table: function(frm) { + update_invoice_table: function (frm) { $.each(frm.doc.invoices, (idx, row) => { if (!row.temporary_opening_account) { row.temporary_opening_account = frm.doc.__onload.temporary_opening_account; } - if(!row.cost_center) { + if (!row.cost_center) { row.cost_center = frm.doc.cost_center; } - row.party_type = frm.doc.invoice_type == "Sales"? "Customer": "Supplier"; + row.party_type = frm.doc.invoice_type == "Sales" ? "Customer" : "Supplier"; }); - } + }, }); -frappe.ui.form.on('Opening Invoice Creation Tool Item', { +frappe.ui.form.on("Opening Invoice Creation Tool Item", { invoices_add: (frm) => { - frm.trigger('update_invoice_table'); - } + frm.trigger("update_invoice_table"); + }, }); diff --git a/erpnext/accounts/doctype/party_link/party_link.js b/erpnext/accounts/doctype/party_link/party_link.js index 6da9291d64db..dfa02c4be9ae 100644 --- a/erpnext/accounts/doctype/party_link/party_link.js +++ b/erpnext/accounts/doctype/party_link/party_link.js @@ -1,33 +1,34 @@ // Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Party Link', { - refresh: function(frm) { - frm.set_query('primary_role', () => { +frappe.ui.form.on("Party Link", { + refresh: function (frm) { + frm.set_query("primary_role", () => { return { filters: { - name: ['in', ['Customer', 'Supplier']] - } + name: ["in", ["Customer", "Supplier"]], + }, }; }); - frm.set_query('secondary_role', () => { - let party_types = Object.keys(frappe.boot.party_account_types) - .filter(p => p != frm.doc.primary_role); + frm.set_query("secondary_role", () => { + let party_types = Object.keys(frappe.boot.party_account_types).filter( + (p) => p != frm.doc.primary_role + ); return { filters: { - name: ['in', party_types] - } + name: ["in", party_types], + }, }; }); }, primary_role(frm) { - frm.set_value('primary_party', ''); - frm.set_value('secondary_role', ''); + frm.set_value("primary_party", ""); + frm.set_value("secondary_role", ""); }, secondary_role(frm) { - frm.set_value('secondary_party', ''); - } + frm.set_value("secondary_party", ""); + }, }); diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry_list.js b/erpnext/accounts/doctype/payment_entry/payment_entry_list.js index 2d76fe69ef98..6974e58c78cf 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry_list.js +++ b/erpnext/accounts/doctype/payment_entry/payment_entry_list.js @@ -1,14 +1,13 @@ -frappe.listview_settings['Payment Entry'] = { - - onload: function(listview) { +frappe.listview_settings["Payment Entry"] = { + onload: function (listview) { if (listview.page.fields_dict.party_type) { - listview.page.fields_dict.party_type.get_query = function() { + listview.page.fields_dict.party_type.get_query = function () { return { - "filters": { - "name": ["in", Object.keys(frappe.boot.party_account_types)], - } + filters: { + name: ["in", Object.keys(frappe.boot.party_account_types)], + }, }; }; } - } + }, }; diff --git a/erpnext/accounts/doctype/payment_gateway_account/payment_gateway_account.js b/erpnext/accounts/doctype/payment_gateway_account/payment_gateway_account.js index aff067eab893..f15c2bdab21b 100644 --- a/erpnext/accounts/doctype/payment_gateway_account/payment_gateway_account.js +++ b/erpnext/accounts/doctype/payment_gateway_account/payment_gateway_account.js @@ -1,11 +1,11 @@ // Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -frappe.ui.form.on('Payment Gateway Account', { +frappe.ui.form.on("Payment Gateway Account", { refresh(frm) { erpnext.utils.check_payments_app(); - if(!frm.doc.__islocal) { - frm.set_df_property('payment_gateway', 'read_only', 1); + if (!frm.doc.__islocal) { + frm.set_df_property("payment_gateway", "read_only", 1); } - } + }, }); diff --git a/erpnext/accounts/doctype/payment_ledger_entry/payment_ledger_entry.js b/erpnext/accounts/doctype/payment_ledger_entry/payment_ledger_entry.js index 5a7be8e5ab23..07fe83177ba0 100644 --- a/erpnext/accounts/doctype/payment_ledger_entry/payment_ledger_entry.js +++ b/erpnext/accounts/doctype/payment_ledger_entry/payment_ledger_entry.js @@ -1,8 +1,7 @@ // Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Payment Ledger Entry', { +frappe.ui.form.on("Payment Ledger Entry", { // refresh: function(frm) { - // } }); diff --git a/erpnext/accounts/doctype/payment_order/payment_order.js b/erpnext/accounts/doctype/payment_order/payment_order.js index 7d85d89c452d..9d4988c19c9b 100644 --- a/erpnext/accounts/doctype/payment_order/payment_order.js +++ b/erpnext/accounts/doctype/payment_order/payment_order.js @@ -1,61 +1,69 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Payment Order', { - setup: function(frm) { - frm.set_query("company_bank_account", function() { +frappe.ui.form.on("Payment Order", { + setup: function (frm) { + frm.set_query("company_bank_account", function () { return { filters: { - "is_company_account":1 - } - } + is_company_account: 1, + }, + }; }); - frm.set_df_property('references', 'cannot_add_rows', true); + frm.set_df_property("references", "cannot_add_rows", true); }, - refresh: function(frm) { + refresh: function (frm) { if (frm.doc.docstatus == 0) { - frm.add_custom_button(__('Payment Request'), function() { - frm.trigger("get_from_payment_request"); - }, __("Get Payments from")); + frm.add_custom_button( + __("Payment Request"), + function () { + frm.trigger("get_from_payment_request"); + }, + __("Get Payments from") + ); - frm.add_custom_button(__('Payment Entry'), function() { - frm.trigger("get_from_payment_entry"); - }, __("Get Payments from")); + frm.add_custom_button( + __("Payment Entry"), + function () { + frm.trigger("get_from_payment_entry"); + }, + __("Get Payments from") + ); - frm.trigger('remove_button'); + frm.trigger("remove_button"); } // payment Entry - if (frm.doc.docstatus===1 && frm.doc.payment_order_type==='Payment Request') { - frm.add_custom_button(__('Create Payment Entries'), function() { + if (frm.doc.docstatus === 1 && frm.doc.payment_order_type === "Payment Request") { + frm.add_custom_button(__("Create Payment Entries"), function () { frm.trigger("make_payment_records"); }); } }, - remove_row_if_empty: function(frm) { + remove_row_if_empty: function (frm) { // remove if first row is empty if (frm.doc.references.length > 0 && !frm.doc.references[0].reference_name) { frm.doc.references = []; } }, - remove_button: function(frm) { + remove_button: function (frm) { // remove custom button of order type that is not imported let label = ["Payment Request", "Payment Entry"]; if (frm.doc.references.length > 0 && frm.doc.payment_order_type) { - label = label.reduce(x => { - x!= frm.doc.payment_order_type; + label = label.reduce((x) => { + x != frm.doc.payment_order_type; return x; }); frm.remove_custom_button(label, "Get from"); } }, - get_from_payment_entry: function(frm) { + get_from_payment_entry: function (frm) { frm.trigger("remove_row_if_empty"); erpnext.utils.map_current_doc({ method: "erpnext.accounts.doctype.payment_entry.payment_entry.make_payment_order", @@ -63,7 +71,7 @@ frappe.ui.form.on('Payment Order', { target: frm, date_field: "posting_date", setters: { - party: frm.doc.supplier || "" + party: frm.doc.supplier || "", }, get_query_filters: { bank: frm.doc.bank, @@ -71,70 +79,79 @@ frappe.ui.form.on('Payment Order', { payment_type: ["!=", "Receive"], bank_account: frm.doc.company_bank_account, paid_from: frm.doc.account, - payment_order_status: ["=", "Initiated"] - } + payment_order_status: ["=", "Initiated"], + }, }); }, - get_from_payment_request: function(frm) { + get_from_payment_request: function (frm) { frm.trigger("remove_row_if_empty"); erpnext.utils.map_current_doc({ method: "erpnext.accounts.doctype.payment_request.payment_request.make_payment_order", source_doctype: "Payment Request", target: frm, setters: { - party: frm.doc.supplier || "" + party: frm.doc.supplier || "", }, get_query_filters: { bank: frm.doc.bank, docstatus: 1, status: ["=", "Initiated"], - } + }, }); }, - make_payment_records: function(frm){ + make_payment_records: function (frm) { var dialog = new frappe.ui.Dialog({ title: __("For Supplier"), fields: [ - {"fieldtype": "Link", "label": __("Supplier"), "fieldname": "supplier", "options":"Supplier", - "get_query": function () { + { + fieldtype: "Link", + label: __("Supplier"), + fieldname: "supplier", + options: "Supplier", + get_query: function () { return { - query:"erpnext.accounts.doctype.payment_order.payment_order.get_supplier_query", - filters: {'parent': frm.doc.name} - } - }, "reqd": 1 + query: "erpnext.accounts.doctype.payment_order.payment_order.get_supplier_query", + filters: { parent: frm.doc.name }, + }; + }, + reqd: 1, }, - {"fieldtype": "Link", "label": __("Mode of Payment"), "fieldname": "mode_of_payment", "options":"Mode of Payment", - "get_query": function () { + { + fieldtype: "Link", + label: __("Mode of Payment"), + fieldname: "mode_of_payment", + options: "Mode of Payment", + get_query: function () { return { - query:"erpnext.accounts.doctype.payment_order.payment_order.get_mop_query", - filters: {'parent': frm.doc.name} - } - } - } - ] + query: "erpnext.accounts.doctype.payment_order.payment_order.get_mop_query", + filters: { parent: frm.doc.name }, + }; + }, + }, + ], }); - dialog.set_primary_action(__("Submit"), function() { + dialog.set_primary_action(__("Submit"), function () { var args = dialog.get_values(); - if(!args) return; + if (!args) return; return frappe.call({ method: "erpnext.accounts.doctype.payment_order.payment_order.make_payment_records", args: { - "name": me.frm.doc.name, - "supplier": args.supplier, - "mode_of_payment": args.mode_of_payment + name: me.frm.doc.name, + supplier: args.supplier, + mode_of_payment: args.mode_of_payment, }, freeze: true, - callback: function(r) { + callback: function (r) { dialog.hide(); frm.refresh(); - } - }) - }) + }, + }); + }); dialog.show(); }, diff --git a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js index 16d1839679c7..1e37f08bc777 100644 --- a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js +++ b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js @@ -2,85 +2,82 @@ // For license information, please see license.txt frappe.provide("erpnext.accounts"); -erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationController extends frappe.ui.form.Controller { +erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationController extends ( + frappe.ui.form.Controller +) { onload() { - const default_company = frappe.defaults.get_default('company'); - this.frm.set_value('company', default_company); + const default_company = frappe.defaults.get_default("company"); + this.frm.set_value("company", default_company); - this.frm.set_value('party_type', ''); - this.frm.set_value('party', ''); - this.frm.set_value('receivable_payable_account', ''); + this.frm.set_value("party_type", ""); + this.frm.set_value("party", ""); + this.frm.set_value("receivable_payable_account", ""); this.frm.set_query("party_type", () => { return { - "filters": { - "name": ["in", Object.keys(frappe.boot.party_account_types)], - } - } + filters: { + name: ["in", Object.keys(frappe.boot.party_account_types)], + }, + }; }); - this.frm.set_query('receivable_payable_account', () => { + this.frm.set_query("receivable_payable_account", () => { return { filters: { - "company": this.frm.doc.company, - "is_group": 0, - "account_type": frappe.boot.party_account_types[this.frm.doc.party_type] - } + company: this.frm.doc.company, + is_group: 0, + account_type: frappe.boot.party_account_types[this.frm.doc.party_type], + }, }; }); - this.frm.set_query('bank_cash_account', () => { + this.frm.set_query("bank_cash_account", () => { return { - filters:[ - ['Account', 'company', '=', this.frm.doc.company], - ['Account', 'is_group', '=', 0], - ['Account', 'account_type', 'in', ['Bank', 'Cash']] - ] + filters: [ + ["Account", "company", "=", this.frm.doc.company], + ["Account", "is_group", "=", 0], + ["Account", "account_type", "in", ["Bank", "Cash"]], + ], }; }); this.frm.set_query("cost_center", () => { return { - "filters": { - "company": this.frm.doc.company, - "is_group": 0 - } - } + filters: { + company: this.frm.doc.company, + is_group: 0, + }, + }; }); } refresh() { this.frm.disable_save(); - this.frm.set_df_property('invoices', 'cannot_delete_rows', true); - this.frm.set_df_property('payments', 'cannot_delete_rows', true); - this.frm.set_df_property('allocation', 'cannot_delete_rows', true); - - this.frm.set_df_property('invoices', 'cannot_add_rows', true); - this.frm.set_df_property('payments', 'cannot_add_rows', true); - this.frm.set_df_property('allocation', 'cannot_add_rows', true); + this.frm.set_df_property("invoices", "cannot_delete_rows", true); + this.frm.set_df_property("payments", "cannot_delete_rows", true); + this.frm.set_df_property("allocation", "cannot_delete_rows", true); + this.frm.set_df_property("invoices", "cannot_add_rows", true); + this.frm.set_df_property("payments", "cannot_add_rows", true); + this.frm.set_df_property("allocation", "cannot_add_rows", true); if (this.frm.doc.receivable_payable_account) { - this.frm.add_custom_button(__('Get Unreconciled Entries'), () => + this.frm.add_custom_button(__("Get Unreconciled Entries"), () => this.frm.trigger("get_unreconciled_entries") ); - this.frm.change_custom_button_type('Get Unreconciled Entries', null, 'primary'); + this.frm.change_custom_button_type("Get Unreconciled Entries", null, "primary"); } if (this.frm.doc.invoices.length && this.frm.doc.payments.length) { - this.frm.add_custom_button(__('Allocate'), () => - this.frm.trigger("allocate") - ); - this.frm.change_custom_button_type('Allocate', null, 'primary'); - this.frm.change_custom_button_type('Get Unreconciled Entries', null, 'default'); + this.frm.add_custom_button(__("Allocate"), () => this.frm.trigger("allocate")); + this.frm.change_custom_button_type("Allocate", null, "primary"); + this.frm.change_custom_button_type("Get Unreconciled Entries", null, "default"); } if (this.frm.doc.allocation.length) { - this.frm.add_custom_button(__('Reconcile'), () => - this.frm.trigger("reconcile") - ); - this.frm.change_custom_button_type('Reconcile', null, 'primary'); - this.frm.change_custom_button_type('Get Unreconciled Entries', null, 'default'); - this.frm.change_custom_button_type('Allocate', null, 'default'); + this.frm.add_custom_button(__("Reconcile"), () => this.frm.trigger("reconcile")); + this.frm.change_custom_button_type("Reconcile", null, "primary"); + this.frm.change_custom_button_type("Get Unreconciled Entries", null, "default"); + this.frm.change_custom_button_type("Allocate", null, "default"); } this.frm.trigger("set_query_for_dimension_filters"); @@ -89,31 +86,39 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo if (this.frm.doc.receivable_payable_account) { this.frm.call({ doc: this.frm.doc, - method: 'is_auto_process_enabled', + method: "is_auto_process_enabled", callback: (r) => { if (r.message) { - this.frm.call({ - 'method': "erpnext.accounts.doctype.process_payment_reconciliation.process_payment_reconciliation.is_any_doc_running", - "args": { - for_filter: { - company: this.frm.doc.company, - party_type: this.frm.doc.party_type, - party: this.frm.doc.party, - receivable_payable_account: this.frm.doc.receivable_payable_account + this.frm + .call({ + method: "erpnext.accounts.doctype.process_payment_reconciliation.process_payment_reconciliation.is_any_doc_running", + args: { + for_filter: { + company: this.frm.doc.company, + party_type: this.frm.doc.party_type, + party: this.frm.doc.party, + receivable_payable_account: this.frm.doc.receivable_payable_account, + }, + }, + }) + .then((r) => { + if (r.message) { + let doc_link = frappe.utils.get_form_link( + "Process Payment Reconciliation", + r.message, + true + ); + let msg = __( + "Payment Reconciliation Job: {0} is running for this party. Can't reconcile now.", + [doc_link] + ); + this.frm.dashboard.add_comment(msg, "yellow"); } - } - }).then(r => { - if (r.message) { - let doc_link = frappe.utils.get_form_link("Process Payment Reconciliation", r.message, true); - let msg = __("Payment Reconciliation Job: {0} is running for this party. Can't reconcile now.", [doc_link]); - this.frm.dashboard.add_comment(msg, "yellow"); - } - }); + }); } - } + }, }); } - } set_query_for_dimension_filters() { frappe.call({ @@ -123,29 +128,29 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo }, callback: (r) => { if (!r.exc && r.message) { - r.message.forEach(x => { + r.message.forEach((x) => { this.frm.set_query(x.fieldname, () => { return { - 'filters': x.filters + filters: x.filters, }; }); }); } - } + }, }); } company() { - this.frm.set_value('party', ''); - this.frm.set_value('receivable_payable_account', ''); + this.frm.set_value("party", ""); + this.frm.set_value("receivable_payable_account", ""); } party_type() { - this.frm.set_value('party', ''); + this.frm.set_value("party", ""); } party() { - this.frm.set_value('receivable_payable_account', ''); + this.frm.set_value("receivable_payable_account", ""); this.frm.trigger("clear_child_tables"); if (!this.frm.doc.receivable_payable_account && this.frm.doc.party_type && this.frm.doc.party) { @@ -154,15 +159,14 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo args: { company: this.frm.doc.company, party_type: this.frm.doc.party_type, - party: this.frm.doc.party + party: this.frm.doc.party, }, callback: (r) => { if (!r.exc && r.message) { this.frm.set_value("receivable_payable_account", r.message); } this.frm.refresh(); - - } + }, }); } } @@ -180,7 +184,6 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo this.frm.trigger("get_unreconciled_entries"); } - clear_child_tables() { this.frm.clear_table("invoices"); this.frm.clear_table("payments"); @@ -192,52 +195,52 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo this.frm.clear_table("allocation"); return this.frm.call({ doc: this.frm.doc, - method: 'get_unreconciled_entries', + method: "get_unreconciled_entries", callback: () => { if (!(this.frm.doc.payments.length || this.frm.doc.invoices.length)) { - frappe.throw({message: __("No Unreconciled Invoices and Payments found for this party and account")}); - } else if (!(this.frm.doc.invoices.length)) { - frappe.throw({message: __("No Outstanding Invoices found for this party")}); - } else if (!(this.frm.doc.payments.length)) { - frappe.throw({message: __("No Unreconciled Payments found for this party")}); + frappe.throw({ + message: __("No Unreconciled Invoices and Payments found for this party and account"), + }); + } else if (!this.frm.doc.invoices.length) { + frappe.throw({ message: __("No Outstanding Invoices found for this party") }); + } else if (!this.frm.doc.payments.length) { + frappe.throw({ message: __("No Unreconciled Payments found for this party") }); } this.frm.refresh(); - } + }, }); - } allocate() { let payments = this.frm.fields_dict.payments.grid.get_selected_children(); - if (!(payments.length)) { + if (!payments.length) { payments = this.frm.doc.payments; } let invoices = this.frm.fields_dict.invoices.grid.get_selected_children(); - if (!(invoices.length)) { + if (!invoices.length) { invoices = this.frm.doc.invoices; } return this.frm.call({ doc: this.frm.doc, - method: 'allocate_entries', + method: "allocate_entries", args: { payments: payments, - invoices: invoices + invoices: invoices, }, callback: () => { this.frm.refresh(); - } + }, }); } reconcile() { - var show_dialog = this.frm.doc.allocation.filter(d => d.difference_amount); + var show_dialog = this.frm.doc.allocation.filter((d) => d.difference_amount); if (show_dialog && show_dialog.length) { - this.data = []; const dialog = new frappe.ui.Dialog({ title: __("Select Difference Account"), - size: 'extra-large', + size: "extra-large", fields: [ { fieldname: "allocation", @@ -249,77 +252,89 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo get_data: () => { return this.data; }, - fields: [{ - fieldtype:'Data', - fieldname:"docname", - in_list_view: 1, - hidden: 1 - }, { - fieldtype:'Data', - fieldname:"reference_name", - label: __("Voucher No"), - in_list_view: 1, - read_only: 1 - }, { - fieldtype:'Date', - fieldname:"gain_loss_posting_date", - label: __("Posting Date"), - in_list_view: 1, - reqd: 1, - }, { - - fieldtype:'Link', - options: 'Account', - in_list_view: 1, - label: __("Difference Account"), - fieldname: 'difference_account', - reqd: 1, - get_query: () => { - return { - filters: { - company: this.frm.doc.company, - is_group: 0 - } - } - } - }, { - fieldtype:'Currency', - in_list_view: 1, - label: __("Difference Amount"), - fieldname: 'difference_amount', - read_only: 1 - }] + fields: [ + { + fieldtype: "Data", + fieldname: "docname", + in_list_view: 1, + hidden: 1, + }, + { + fieldtype: "Data", + fieldname: "reference_name", + label: __("Voucher No"), + in_list_view: 1, + read_only: 1, + }, + { + fieldtype: "Date", + fieldname: "gain_loss_posting_date", + label: __("Posting Date"), + in_list_view: 1, + reqd: 1, + }, + { + fieldtype: "Link", + options: "Account", + in_list_view: 1, + label: __("Difference Account"), + fieldname: "difference_account", + reqd: 1, + get_query: () => { + return { + filters: { + company: this.frm.doc.company, + is_group: 0, + }, + }; + }, + }, + { + fieldtype: "Currency", + in_list_view: 1, + label: __("Difference Amount"), + fieldname: "difference_amount", + read_only: 1, + }, + ], }, { - fieldtype: 'HTML', - options: " New Journal Entry will be posted for the difference amount " - } + fieldtype: "HTML", + options: " New Journal Entry will be posted for the difference amount ", + }, ], primary_action: () => { const args = dialog.get_values()["allocation"]; - args.forEach(d => { - frappe.model.set_value("Payment Reconciliation Allocation", d.docname, - "difference_account", d.difference_account); - frappe.model.set_value("Payment Reconciliation Allocation", d.docname, - "gain_loss_posting_date", d.gain_loss_posting_date); - + args.forEach((d) => { + frappe.model.set_value( + "Payment Reconciliation Allocation", + d.docname, + "difference_account", + d.difference_account + ); + frappe.model.set_value( + "Payment Reconciliation Allocation", + d.docname, + "gain_loss_posting_date", + d.gain_loss_posting_date + ); }); this.reconcile_payment_entries(); dialog.hide(); }, - primary_action_label: __('Reconcile Entries') + primary_action_label: __("Reconcile Entries"), }); - this.frm.doc.allocation.forEach(d => { + this.frm.doc.allocation.forEach((d) => { if (d.difference_amount) { dialog.fields_dict.allocation.df.data.push({ - 'docname': d.name, - 'reference_name': d.reference_name, - 'difference_amount': d.difference_amount, - 'difference_account': d.difference_account, - 'gain_loss_posting_date': d.gain_loss_posting_date + docname: d.name, + reference_name: d.reference_name, + difference_amount: d.difference_amount, + difference_account: d.difference_account, + gain_loss_posting_date: d.gain_loss_posting_date, }); } }); @@ -335,41 +350,39 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo reconcile_payment_entries() { return this.frm.call({ doc: this.frm.doc, - method: 'reconcile', + method: "reconcile", callback: () => { this.frm.clear_table("allocation"); this.frm.refresh(); - } + }, }); } }; -frappe.ui.form.on('Payment Reconciliation Allocation', { - allocated_amount: function(frm, cdt, cdn) { +frappe.ui.form.on("Payment Reconciliation Allocation", { + allocated_amount: function (frm, cdt, cdn) { let row = locals[cdt][cdn]; // filter invoice - let invoice = frm.doc.invoices.filter((x) => (x.invoice_number == row.invoice_number)); + let invoice = frm.doc.invoices.filter((x) => x.invoice_number == row.invoice_number); // filter payment - let payment = frm.doc.payments.filter((x) => (x.reference_name == row.reference_name)); + let payment = frm.doc.payments.filter((x) => x.reference_name == row.reference_name); frm.call({ doc: frm.doc, - method: 'calculate_difference_on_allocation_change', + method: "calculate_difference_on_allocation_change", args: { payment_entry: payment, invoice: invoice, - allocated_amount: row.allocated_amount + allocated_amount: row.allocated_amount, }, callback: (r) => { if (r.message) { row.difference_amount = r.message; frm.refresh(); } - } + }, }); - } + }, }); - - -extend_cscript(cur_frm.cscript, new erpnext.accounts.PaymentReconciliationController({frm: cur_frm})); +extend_cscript(cur_frm.cscript, new erpnext.accounts.PaymentReconciliationController({ frm: cur_frm })); diff --git a/erpnext/accounts/doctype/payment_request/payment_request.js b/erpnext/accounts/doctype/payment_request/payment_request.js index e9139120283f..e5a6040c735e 100644 --- a/erpnext/accounts/doctype/payment_request/payment_request.js +++ b/erpnext/accounts/doctype/payment_request/payment_request.js @@ -1,83 +1,95 @@ -cur_frm.add_fetch("payment_gateway_account", "payment_account", "payment_account") -cur_frm.add_fetch("payment_gateway_account", "payment_gateway", "payment_gateway") -cur_frm.add_fetch("payment_gateway_account", "message", "message") +cur_frm.add_fetch("payment_gateway_account", "payment_account", "payment_account"); +cur_frm.add_fetch("payment_gateway_account", "payment_gateway", "payment_gateway"); +cur_frm.add_fetch("payment_gateway_account", "message", "message"); frappe.ui.form.on("Payment Request", { - setup: function(frm) { - frm.set_query("party_type", function() { + setup: function (frm) { + frm.set_query("party_type", function () { return { query: "erpnext.setup.doctype.party_type.party_type.get_party_type", }; }); - } -}) + }, +}); -frappe.ui.form.on("Payment Request", "onload", function(frm, dt, dn){ +frappe.ui.form.on("Payment Request", "onload", function (frm, dt, dn) { if (frm.doc.reference_doctype) { frappe.call({ - method:"erpnext.accounts.doctype.payment_request.payment_request.get_print_format_list", - args: {"ref_doctype": frm.doc.reference_doctype}, - callback:function(r){ - set_field_options("print_format", r.message["print_format"]) - } - }) + method: "erpnext.accounts.doctype.payment_request.payment_request.get_print_format_list", + args: { ref_doctype: frm.doc.reference_doctype }, + callback: function (r) { + set_field_options("print_format", r.message["print_format"]); + }, + }); } -}) +}); -frappe.ui.form.on("Payment Request", "refresh", function(frm) { - if(frm.doc.payment_request_type == 'Inward' && frm.doc.payment_channel !== "Phone" && - !in_list(["Initiated", "Paid"], frm.doc.status) && !frm.doc.__islocal && frm.doc.docstatus==1){ - frm.add_custom_button(__('Resend Payment Email'), function(){ +frappe.ui.form.on("Payment Request", "refresh", function (frm) { + if ( + frm.doc.payment_request_type == "Inward" && + frm.doc.payment_channel !== "Phone" && + !in_list(["Initiated", "Paid"], frm.doc.status) && + !frm.doc.__islocal && + frm.doc.docstatus == 1 + ) { + frm.add_custom_button(__("Resend Payment Email"), function () { frappe.call({ method: "erpnext.accounts.doctype.payment_request.payment_request.resend_payment_email", - args: {"docname": frm.doc.name}, + args: { docname: frm.doc.name }, freeze: true, freeze_message: __("Sending"), - callback: function(r){ - if(!r.exc) { + callback: function (r) { + if (!r.exc) { frappe.msgprint(__("Message Sent")); } - } + }, }); }); } - if((!frm.doc.payment_gateway_account || frm.doc.payment_request_type == "Outward") && frm.doc.status == "Initiated") { - frm.add_custom_button(__('Create Payment Entry'), function(){ + if ( + (!frm.doc.payment_gateway_account || frm.doc.payment_request_type == "Outward") && + frm.doc.status == "Initiated" + ) { + frm.add_custom_button(__("Create Payment Entry"), function () { frappe.call({ method: "erpnext.accounts.doctype.payment_request.payment_request.make_payment_entry", - args: {"docname": frm.doc.name}, + args: { docname: frm.doc.name }, freeze: true, - callback: function(r){ - if(!r.exc) { + callback: function (r) { + if (!r.exc) { var doc = frappe.model.sync(r.message); frappe.set_route("Form", r.message.doctype, r.message.name); } - } + }, }); }).addClass("btn-primary"); } }); -frappe.ui.form.on("Payment Request", "is_a_subscription", function(frm) { +frappe.ui.form.on("Payment Request", "is_a_subscription", function (frm) { frm.toggle_reqd("payment_gateway_account", frm.doc.is_a_subscription); frm.toggle_reqd("subscription_plans", frm.doc.is_a_subscription); if (frm.doc.is_a_subscription && frm.doc.reference_doctype && frm.doc.reference_name) { frappe.call({ method: "erpnext.accounts.doctype.payment_request.payment_request.get_subscription_details", - args: {"reference_doctype": frm.doc.reference_doctype, "reference_name": frm.doc.reference_name}, + args: { reference_doctype: frm.doc.reference_doctype, reference_name: frm.doc.reference_name }, freeze: true, - callback: function(data){ - if(!data.exc) { - $.each(data.message || [], function(i, v){ - var d = frappe.model.add_child(frm.doc, "Subscription Plan Detail", "subscription_plans"); + callback: function (data) { + if (!data.exc) { + $.each(data.message || [], function (i, v) { + var d = frappe.model.add_child( + frm.doc, + "Subscription Plan Detail", + "subscription_plans" + ); d.qty = v.qty; d.plan = v.plan; }); frm.refresh_field("subscription_plans"); } - } + }, }); } }); diff --git a/erpnext/accounts/doctype/payment_request/payment_request_list.js b/erpnext/accounts/doctype/payment_request/payment_request_list.js index 85d729cd61cc..183ca7c45849 100644 --- a/erpnext/accounts/doctype/payment_request/payment_request_list.js +++ b/erpnext/accounts/doctype/payment_request/payment_request_list.js @@ -1,23 +1,19 @@ -frappe.listview_settings['Payment Request'] = { +frappe.listview_settings["Payment Request"] = { add_fields: ["status"], - get_indicator: function(doc) { - if(doc.status == "Draft") { + get_indicator: function (doc) { + if (doc.status == "Draft") { return [__("Draft"), "gray", "status,=,Draft"]; } - if(doc.status == "Requested") { + if (doc.status == "Requested") { return [__("Requested"), "green", "status,=,Requested"]; - } - else if(doc.status == "Initiated") { + } else if (doc.status == "Initiated") { return [__("Initiated"), "green", "status,=,Initiated"]; - } - else if(doc.status == "Partially Paid") { + } else if (doc.status == "Partially Paid") { return [__("Partially Paid"), "orange", "status,=,Partially Paid"]; - } - else if(doc.status == "Paid") { + } else if (doc.status == "Paid") { return [__("Paid"), "blue", "status,=,Paid"]; - } - else if(doc.status == "Cancelled") { + } else if (doc.status == "Cancelled") { return [__("Cancelled"), "red", "status,=,Cancelled"]; } - } -} + }, +}; diff --git a/erpnext/accounts/doctype/payment_term/payment_term.js b/erpnext/accounts/doctype/payment_term/payment_term.js index feecf93484c7..c1c9d7c3258f 100644 --- a/erpnext/accounts/doctype/payment_term/payment_term.js +++ b/erpnext/accounts/doctype/payment_term/payment_term.js @@ -1,22 +1,24 @@ // Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Payment Term', { +frappe.ui.form.on("Payment Term", { onload(frm) { - frm.trigger('set_dynamic_description'); + frm.trigger("set_dynamic_description"); }, discount(frm) { - frm.trigger('set_dynamic_description'); + frm.trigger("set_dynamic_description"); }, discount_type(frm) { - frm.trigger('set_dynamic_description'); + frm.trigger("set_dynamic_description"); }, set_dynamic_description(frm) { if (frm.doc.discount) { - let description = __("{0}% of total invoice value will be given as discount.", [frm.doc.discount]); - if (frm.doc.discount_type == 'Amount') { + let description = __("{0}% of total invoice value will be given as discount.", [ + frm.doc.discount, + ]); + if (frm.doc.discount_type == "Amount") { description = __("{0} will be given as discount.", [fmt_money(frm.doc.discount)]); } frm.set_df_property("discount", "description", description); } - } + }, }); diff --git a/erpnext/accounts/doctype/payment_terms_template/payment_terms_template.js b/erpnext/accounts/doctype/payment_terms_template/payment_terms_template.js index 6046c13e1467..b766c3b412b4 100644 --- a/erpnext/accounts/doctype/payment_terms_template/payment_terms_template.js +++ b/erpnext/accounts/doctype/payment_terms_template/payment_terms_template.js @@ -1,12 +1,18 @@ // Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Payment Terms Template', { - refresh: function(frm) { - frm.fields_dict.terms.grid.toggle_reqd("payment_term", frm.doc.allocate_payment_based_on_payment_terms); +frappe.ui.form.on("Payment Terms Template", { + refresh: function (frm) { + frm.fields_dict.terms.grid.toggle_reqd( + "payment_term", + frm.doc.allocate_payment_based_on_payment_terms + ); }, - allocate_payment_based_on_payment_terms: function(frm) { - frm.fields_dict.terms.grid.toggle_reqd("payment_term", frm.doc.allocate_payment_based_on_payment_terms); - } + allocate_payment_based_on_payment_terms: function (frm) { + frm.fields_dict.terms.grid.toggle_reqd( + "payment_term", + frm.doc.allocate_payment_based_on_payment_terms + ); + }, }); diff --git a/erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.js b/erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.js index e923d4ed5e6d..82d8cb37fe7f 100644 --- a/erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.js +++ b/erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.js @@ -1,38 +1,41 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -frappe.ui.form.on('Period Closing Voucher', { - onload: function(frm) { +frappe.ui.form.on("Period Closing Voucher", { + onload: function (frm) { if (!frm.doc.transaction_date) frm.doc.transaction_date = frappe.datetime.obj_to_str(new Date()); }, - setup: function(frm) { - frm.set_query("closing_account_head", function() { + setup: function (frm) { + frm.set_query("closing_account_head", function () { return { filters: [ - ['Account', 'company', '=', frm.doc.company], - ['Account', 'is_group', '=', '0'], - ['Account', 'freeze_account', '=', 'No'], - ['Account', 'root_type', 'in', 'Liability, Equity'] - ] - } + ["Account", "company", "=", frm.doc.company], + ["Account", "is_group", "=", "0"], + ["Account", "freeze_account", "=", "No"], + ["Account", "root_type", "in", "Liability, Equity"], + ], + }; }); }, - refresh: function(frm) { - if(frm.doc.docstatus > 0) { - frm.add_custom_button(__('Ledger'), function() { - frappe.route_options = { - "voucher_no": frm.doc.name, - "from_date": frm.doc.posting_date, - "to_date": moment(frm.doc.modified).format('YYYY-MM-DD'), - "company": frm.doc.company, - "group_by": "", - "show_cancelled_entries": frm.doc.docstatus === 2 - }; - frappe.set_route("query-report", "General Ledger"); - }, "fa fa-table"); + refresh: function (frm) { + if (frm.doc.docstatus > 0) { + frm.add_custom_button( + __("Ledger"), + function () { + frappe.route_options = { + voucher_no: frm.doc.name, + from_date: frm.doc.posting_date, + to_date: moment(frm.doc.modified).format("YYYY-MM-DD"), + company: frm.doc.company, + group_by: "", + show_cancelled_entries: frm.doc.docstatus === 2, + }; + frappe.set_route("query-report", "General Ledger"); + }, + "fa fa-table" + ); } - } - -}) + }, +}); diff --git a/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.js b/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.js index 91e71e90dd80..715800a7c169 100644 --- a/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.js +++ b/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.js @@ -1,36 +1,37 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('POS Closing Entry', { - onload: function(frm) { - frm.ignore_doctypes_on_cancel_all = ['POS Invoice Merge Log']; - frm.set_query("pos_profile", function(doc) { +frappe.ui.form.on("POS Closing Entry", { + onload: function (frm) { + frm.ignore_doctypes_on_cancel_all = ["POS Invoice Merge Log"]; + frm.set_query("pos_profile", function (doc) { return { - filters: { 'user': doc.user } + filters: { user: doc.user }, }; }); - frm.set_query("user", function(doc) { + frm.set_query("user", function (doc) { return { query: "erpnext.accounts.doctype.pos_closing_entry.pos_closing_entry.get_cashiers", - filters: { 'parent': doc.pos_profile } + filters: { parent: doc.pos_profile }, }; }); - frm.set_query("pos_opening_entry", function(doc) { - return { filters: { 'status': 'Open', 'docstatus': 1 } }; + frm.set_query("pos_opening_entry", function (doc) { + return { filters: { status: "Open", docstatus: 1 } }; }); - if (frm.doc.docstatus === 0 && !frm.doc.amended_from) frm.set_value("period_end_date", frappe.datetime.now_datetime()); + if (frm.doc.docstatus === 0 && !frm.doc.amended_from) + frm.set_value("period_end_date", frappe.datetime.now_datetime()); - frappe.realtime.on('closing_process_complete', async function(data) { + frappe.realtime.on("closing_process_complete", async function (data) { await frm.reload_doc(); - if (frm.doc.status == 'Failed' && frm.doc.error_message) { + if (frm.doc.status == "Failed" && frm.doc.error_message) { frappe.msgprint({ - title: __('POS Closing Failed'), + title: __("POS Closing Failed"), message: frm.doc.error_message, - indicator: 'orange', - clear: true + indicator: "orange", + clear: true, }); } }); @@ -47,23 +48,23 @@ frappe.ui.form.on('POS Closing Entry', { } }, - refresh: function(frm) { - if (frm.doc.docstatus == 1 && frm.doc.status == 'Failed') { + refresh: function (frm) { + if (frm.doc.docstatus == 1 && frm.doc.status == "Failed") { const issue = 'issue'; frm.dashboard.set_headline( - __('POS Closing failed while running in a background process. You can resolve the {0} and retry the process again.', [issue])); + __( + "POS Closing failed while running in a background process. You can resolve the {0} and retry the process again.", + [issue] + ) + ); - $('#jump_to_error').on('click', (e) => { + $("#jump_to_error").on("click", (e) => { e.preventDefault(); - frappe.utils.scroll_to( - cur_frm.get_field("error_message").$wrapper, - true, - 30 - ); + frappe.utils.scroll_to(cur_frm.get_field("error_message").$wrapper, true, 30); }); - frm.add_custom_button(__('Retry'), function () { - frm.call('retry', {}, () => { + frm.add_custom_button(__("Retry"), function () { + frm.call("retry", {}, () => { frm.reload_doc(); }); }); @@ -71,48 +72,54 @@ frappe.ui.form.on('POS Closing Entry', { }, pos_opening_entry(frm) { - if (frm.doc.pos_opening_entry && frm.doc.period_start_date && frm.doc.period_end_date && frm.doc.user) { + if ( + frm.doc.pos_opening_entry && + frm.doc.period_start_date && + frm.doc.period_end_date && + frm.doc.user + ) { reset_values(frm); frappe.run_serially([ () => frm.trigger("set_opening_amounts"), - () => frm.trigger("get_pos_invoices") + () => frm.trigger("get_pos_invoices"), ]); } }, set_opening_amounts(frm) { - return frappe.db.get_doc("POS Opening Entry", frm.doc.pos_opening_entry) + return frappe.db + .get_doc("POS Opening Entry", frm.doc.pos_opening_entry) .then(({ balance_details }) => { - balance_details.forEach(detail => { + balance_details.forEach((detail) => { frm.add_child("payment_reconciliation", { mode_of_payment: detail.mode_of_payment, opening_amount: detail.opening_amount, - expected_amount: detail.opening_amount + expected_amount: detail.opening_amount, }); - }) + }); }); }, get_pos_invoices(frm) { return frappe.call({ - method: 'erpnext.accounts.doctype.pos_closing_entry.pos_closing_entry.get_pos_invoices', + method: "erpnext.accounts.doctype.pos_closing_entry.pos_closing_entry.get_pos_invoices", args: { start: frappe.datetime.get_datetime_as_string(frm.doc.period_start_date), end: frappe.datetime.get_datetime_as_string(frm.doc.period_end_date), pos_profile: frm.doc.pos_profile, - user: frm.doc.user + user: frm.doc.user, }, callback: (r) => { let pos_docs = r.message; set_form_data(pos_docs, frm); refresh_fields(frm); set_html_data(frm); - } + }, }); }, - before_save: async function(frm) { - frappe.dom.freeze(__('Processing Sales! Please Wait...')); + before_save: async function (frm) { + frappe.dom.freeze(__("Processing Sales! Please Wait...")); frm.set_value("grand_total", 0); frm.set_value("net_total", 0); @@ -125,12 +132,12 @@ frappe.ui.form.on('POS Closing Entry', { await Promise.all([ frappe.call({ - method: 'erpnext.accounts.doctype.pos_closing_entry.pos_closing_entry.get_pos_invoices', + method: "erpnext.accounts.doctype.pos_closing_entry.pos_closing_entry.get_pos_invoices", args: { start: frappe.datetime.get_datetime_as_string(frm.doc.period_start_date), end: frappe.datetime.get_datetime_as_string(frm.doc.period_end_date), pos_profile: frm.doc.pos_profile, - user: frm.doc.user + user: frm.doc.user, }, callback: (r) => { let pos_invoices = r.message; @@ -143,22 +150,22 @@ frappe.ui.form.on('POS Closing Entry', { refresh_fields(frm); set_html_data(frm); } - } - }) - ]) + }, + }), + ]); frappe.dom.unfreeze(); - } + }, }); -frappe.ui.form.on('POS Closing Entry Detail', { +frappe.ui.form.on("POS Closing Entry Detail", { closing_amount: (frm, cdt, cdn) => { const row = locals[cdt][cdn]; frappe.model.set_value(cdt, cdn, "difference", flt(row.closing_amount - row.expected_amount)); - } -}) + }, +}); function set_form_data(data, frm) { - data.forEach(d => { + data.forEach((d) => { add_to_pos_transaction(d, frm); frm.doc.grand_total += flt(d.grand_total); frm.doc.net_total += flt(d.net_total); @@ -173,13 +180,15 @@ function add_to_pos_transaction(d, frm) { pos_invoice: d.name, posting_date: d.posting_date, grand_total: d.grand_total, - customer: d.customer - }) + customer: d.customer, + }); } function refresh_payments(d, frm) { - d.payments.forEach(p => { - const payment = frm.doc.payment_reconciliation.find(pay => pay.mode_of_payment === p.mode_of_payment); + d.payments.forEach((p) => { + const payment = frm.doc.payment_reconciliation.find( + (pay) => pay.mode_of_payment === p.mode_of_payment + ); if (p.account == d.account_for_change_amount) { p.amount -= flt(d.change_amount); } @@ -191,25 +200,25 @@ function refresh_payments(d, frm) { mode_of_payment: p.mode_of_payment, opening_amount: 0, expected_amount: p.amount, - closing_amount: 0 - }) + closing_amount: 0, + }); } - }) + }); } function refresh_taxes(d, frm) { - d.taxes.forEach(t => { - const tax = frm.doc.taxes.find(tx => tx.account_head === t.account_head && tx.rate === t.rate); + d.taxes.forEach((t) => { + const tax = frm.doc.taxes.find((tx) => tx.account_head === t.account_head && tx.rate === t.rate); if (tax) { tax.amount += flt(t.tax_amount); } else { frm.add_child("taxes", { account_head: t.account_head, rate: t.rate, - amount: t.tax_amount - }) + amount: t.tax_amount, + }); } - }) + }); } function reset_values(frm) { @@ -231,13 +240,13 @@ function refresh_fields(frm) { } function set_html_data(frm) { - if (frm.doc.docstatus === 1 && frm.doc.status == 'Submitted') { + if (frm.doc.docstatus === 1 && frm.doc.status == "Submitted") { frappe.call({ method: "get_payment_reconciliation_details", doc: frm.doc, callback: (r) => { frm.get_field("payment_reconciliation_details").$wrapper.html(r.message); - } + }, }); } } diff --git a/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry_list.js b/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry_list.js index cffeb4d5351e..29f00fbff7b4 100644 --- a/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry_list.js +++ b/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry_list.js @@ -2,16 +2,15 @@ // License: GNU General Public License v3. See license.txt // render -frappe.listview_settings['POS Closing Entry'] = { - get_indicator: function(doc) { +frappe.listview_settings["POS Closing Entry"] = { + get_indicator: function (doc) { var status_color = { - "Draft": "red", - "Submitted": "blue", - "Queued": "orange", - "Failed": "red", - "Cancelled": "red" - + Draft: "red", + Submitted: "blue", + Queued: "orange", + Failed: "red", + Cancelled: "red", }; - return [__(doc.status), status_color[doc.status], "status,=,"+doc.status]; - } + return [__(doc.status), status_color[doc.status], "status,=," + doc.status]; + }, }; diff --git a/erpnext/accounts/doctype/pos_invoice/pos_invoice_list.js b/erpnext/accounts/doctype/pos_invoice/pos_invoice_list.js index 2dbf2a4fcd31..0379932bb7a8 100644 --- a/erpnext/accounts/doctype/pos_invoice/pos_invoice_list.js +++ b/erpnext/accounts/doctype/pos_invoice/pos_invoice_list.js @@ -2,40 +2,47 @@ // License: GNU General Public License v3. See license.txt // render -frappe.listview_settings['POS Invoice'] = { - add_fields: ["customer", "customer_name", "base_grand_total", "outstanding_amount", "due_date", "company", - "currency", "is_return"], - get_indicator: function(doc) { +frappe.listview_settings["POS Invoice"] = { + add_fields: [ + "customer", + "customer_name", + "base_grand_total", + "outstanding_amount", + "due_date", + "company", + "currency", + "is_return", + ], + get_indicator: function (doc) { var status_color = { - "Draft": "red", - "Unpaid": "orange", - "Paid": "green", - "Submitted": "blue", - "Consolidated": "green", - "Return": "darkgrey", + Draft: "red", + Unpaid: "orange", + Paid: "green", + Submitted: "blue", + Consolidated: "green", + Return: "darkgrey", "Unpaid and Discounted": "orange", "Overdue and Discounted": "red", - "Overdue": "red" - + Overdue: "red", }; - return [__(doc.status), status_color[doc.status], "status,=,"+doc.status]; + return [__(doc.status), status_color[doc.status], "status,=," + doc.status]; }, right_column: "grand_total", - onload: function(me) { - me.page.add_action_item('Make Merge Log', function() { + onload: function (me) { + me.page.add_action_item("Make Merge Log", function () { const invoices = me.get_checked_items(); frappe.call({ method: "erpnext.accounts.doctype.pos_invoice.pos_invoice.make_merge_log", freeze: true, - args:{ - "invoices": invoices + args: { + invoices: invoices, }, callback: function (r) { if (r.message) { var doc = frappe.model.sync(r.message)[0]; frappe.set_route("Form", doc.doctype, doc.name); } - } + }, }); }); }, diff --git a/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.js b/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.js index 73c6290d7b0e..8423987447ec 100644 --- a/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.js +++ b/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.js @@ -1,21 +1,21 @@ // Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('POS Invoice Merge Log', { - setup: function(frm) { - frm.set_query("pos_invoice", "pos_invoices", doc => { +frappe.ui.form.on("POS Invoice Merge Log", { + setup: function (frm) { + frm.set_query("pos_invoice", "pos_invoices", (doc) => { return { filters: { - 'docstatus': 1, - 'customer': doc.customer, - 'consolidated_invoice': '' - } - } + docstatus: 1, + customer: doc.customer, + consolidated_invoice: "", + }, + }; }); }, - merge_invoices_based_on: function(frm) { - frm.set_value('customer', ''); - frm.set_value('customer_group', ''); - } + merge_invoices_based_on: function (frm) { + frm.set_value("customer", ""); + frm.set_value("customer_group", ""); + }, }); diff --git a/erpnext/accounts/doctype/pos_opening_entry/pos_opening_entry.js b/erpnext/accounts/doctype/pos_opening_entry/pos_opening_entry.js index d23f348f04ee..6a316d55e6a6 100644 --- a/erpnext/accounts/doctype/pos_opening_entry/pos_opening_entry.js +++ b/erpnext/accounts/doctype/pos_opening_entry/pos_opening_entry.js @@ -1,56 +1,55 @@ // Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('POS Opening Entry', { +frappe.ui.form.on("POS Opening Entry", { setup(frm) { if (frm.doc.docstatus == 0) { - frm.trigger('set_posting_date_read_only'); - frm.set_value('period_start_date', frappe.datetime.now_datetime()); - frm.set_value('user', frappe.session.user); + frm.trigger("set_posting_date_read_only"); + frm.set_value("period_start_date", frappe.datetime.now_datetime()); + frm.set_value("user", frappe.session.user); } - frm.set_query("user", function(doc) { + frm.set_query("user", function (doc) { return { query: "erpnext.accounts.doctype.pos_closing_entry.pos_closing_entry.get_cashiers", - filters: { 'parent': doc.pos_profile } + filters: { parent: doc.pos_profile }, }; }); }, refresh(frm) { // set default posting date / time - if(frm.doc.docstatus == 0) { - if(!frm.doc.posting_date) { - frm.set_value('posting_date', frappe.datetime.nowdate()); + if (frm.doc.docstatus == 0) { + if (!frm.doc.posting_date) { + frm.set_value("posting_date", frappe.datetime.nowdate()); } - frm.trigger('set_posting_date_read_only'); + frm.trigger("set_posting_date_read_only"); } }, set_posting_date_read_only(frm) { - if(frm.doc.docstatus == 0 && frm.doc.set_posting_date) { - frm.set_df_property('posting_date', 'read_only', 0); + if (frm.doc.docstatus == 0 && frm.doc.set_posting_date) { + frm.set_df_property("posting_date", "read_only", 0); } else { - frm.set_df_property('posting_date', 'read_only', 1); + frm.set_df_property("posting_date", "read_only", 1); } }, set_posting_date(frm) { - frm.trigger('set_posting_date_read_only'); + frm.trigger("set_posting_date_read_only"); }, pos_profile: (frm) => { if (frm.doc.pos_profile) { - frappe.db.get_doc("POS Profile", frm.doc.pos_profile) - .then(({ payments }) => { - if (payments.length) { - frm.doc.balance_details = []; - payments.forEach(({ mode_of_payment }) => { - frm.add_child("balance_details", { mode_of_payment }); - }) - frm.refresh_field("balance_details"); - } - }); + frappe.db.get_doc("POS Profile", frm.doc.pos_profile).then(({ payments }) => { + if (payments.length) { + frm.doc.balance_details = []; + payments.forEach(({ mode_of_payment }) => { + frm.add_child("balance_details", { mode_of_payment }); + }); + frm.refresh_field("balance_details"); + } + }); } - } + }, }); diff --git a/erpnext/accounts/doctype/pos_opening_entry/pos_opening_entry_list.js b/erpnext/accounts/doctype/pos_opening_entry/pos_opening_entry_list.js index 1ad3c919b710..7ff9c4bbbc0c 100644 --- a/erpnext/accounts/doctype/pos_opening_entry/pos_opening_entry_list.js +++ b/erpnext/accounts/doctype/pos_opening_entry/pos_opening_entry_list.js @@ -2,15 +2,14 @@ // License: GNU General Public License v3. See license.txt // render -frappe.listview_settings['POS Opening Entry'] = { - get_indicator: function(doc) { +frappe.listview_settings["POS Opening Entry"] = { + get_indicator: function (doc) { var status_color = { - "Draft": "red", - "Open": "orange", - "Closed": "green", - "Cancelled": "red" - + Draft: "red", + Open: "orange", + Closed: "green", + Cancelled: "red", }; - return [__(doc.status), status_color[doc.status], "status,=,"+doc.status]; - } + return [__(doc.status), status_color[doc.status], "status,=," + doc.status]; + }, }; diff --git a/erpnext/accounts/doctype/pos_profile_user/pos_profile_user.js b/erpnext/accounts/doctype/pos_profile_user/pos_profile_user.js index f0884ebef5ee..63416745394a 100644 --- a/erpnext/accounts/doctype/pos_profile_user/pos_profile_user.js +++ b/erpnext/accounts/doctype/pos_profile_user/pos_profile_user.js @@ -1,6 +1,4 @@ // Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('POS Profile User', { - -}); +frappe.ui.form.on("POS Profile User", {}); diff --git a/erpnext/accounts/doctype/pos_settings/pos_settings.js b/erpnext/accounts/doctype/pos_settings/pos_settings.js index 7d8f3562c8c7..a2e5a57e5f72 100644 --- a/erpnext/accounts/doctype/pos_settings/pos_settings.js +++ b/erpnext/accounts/doctype/pos_settings/pos_settings.js @@ -1,57 +1,91 @@ // Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -let search_fields_datatypes = ['Data', 'Link', 'Dynamic Link', 'Long Text', 'Select', 'Small Text', 'Text', 'Text Editor']; -let do_not_include_fields = ["naming_series", "item_code", "item_name", "stock_uom", "asset_naming_series", - "default_material_request_type", "valuation_method", "warranty_period", "weight_uom", "batch_number_series", - "serial_no_series", "purchase_uom", "customs_tariff_number", "sales_uom", "deferred_revenue_account", - "deferred_expense_account", "quality_inspection_template", "route", "slideshow", "website_image_alt", "thumbnail", - "web_long_description"] +let search_fields_datatypes = [ + "Data", + "Link", + "Dynamic Link", + "Long Text", + "Select", + "Small Text", + "Text", + "Text Editor", +]; +let do_not_include_fields = [ + "naming_series", + "item_code", + "item_name", + "stock_uom", + "asset_naming_series", + "default_material_request_type", + "valuation_method", + "warranty_period", + "weight_uom", + "batch_number_series", + "serial_no_series", + "purchase_uom", + "customs_tariff_number", + "sales_uom", + "deferred_revenue_account", + "deferred_expense_account", + "quality_inspection_template", + "route", + "slideshow", + "website_image_alt", + "thumbnail", + "web_long_description", +]; -frappe.ui.form.on('POS Settings', { - onload: function(frm) { +frappe.ui.form.on("POS Settings", { + onload: function (frm) { frm.trigger("get_invoice_fields"); frm.trigger("add_search_options"); }, - get_invoice_fields: function(frm) { + get_invoice_fields: function (frm) { frappe.model.with_doctype("POS Invoice", () => { - var fields = $.map(frappe.get_doc("DocType", "POS Invoice").fields, function(d) { - if (frappe.model.no_value_type.indexOf(d.fieldtype) === -1 || ['Button'].includes(d.fieldtype)) { - return { label: d.label + ' (' + d.fieldtype + ')', value: d.fieldname }; + var fields = $.map(frappe.get_doc("DocType", "POS Invoice").fields, function (d) { + if ( + frappe.model.no_value_type.indexOf(d.fieldtype) === -1 || + ["Button"].includes(d.fieldtype) + ) { + return { label: d.label + " (" + d.fieldtype + ")", value: d.fieldname }; } else { return null; } }); frm.fields_dict.invoice_fields.grid.update_docfield_property( - 'fieldname', 'options', [""].concat(fields) + "fieldname", + "options", + [""].concat(fields) ); }); - }, - add_search_options: function(frm) { + add_search_options: function (frm) { frappe.model.with_doctype("Item", () => { - var fields = $.map(frappe.get_doc("DocType", "Item").fields, function(d) { - if (search_fields_datatypes.includes(d.fieldtype) && !(do_not_include_fields.includes(d.fieldname))) { + var fields = $.map(frappe.get_doc("DocType", "Item").fields, function (d) { + if ( + search_fields_datatypes.includes(d.fieldtype) && + !do_not_include_fields.includes(d.fieldname) + ) { return [d.label]; } else { return null; } }); - fields.unshift(''); - frm.fields_dict.pos_search_fields.grid.update_docfield_property('field', 'options', fields); + fields.unshift(""); + frm.fields_dict.pos_search_fields.grid.update_docfield_property("field", "options", fields); }); - - } + }, }); frappe.ui.form.on("POS Search Fields", { - field: function(frm, doctype, name) { + field: function (frm, doctype, name) { var doc = frappe.get_doc(doctype, name); - var df = $.map(frappe.get_doc("DocType", "Item").fields, function(d) { + var df = $.map(frappe.get_doc("DocType", "Item").fields, function (d) { if (doc.field == d.label && search_fields_datatypes.includes(d.fieldtype)) { return d; } else { @@ -61,13 +95,13 @@ frappe.ui.form.on("POS Search Fields", { doc.fieldname = df.fieldname; frm.refresh_field("fields"); - } + }, }); frappe.ui.form.on("POS Field", { - fieldname: function(frm, doctype, name) { + fieldname: function (frm, doctype, name) { var doc = frappe.get_doc(doctype, name); - var df = $.map(frappe.get_doc("DocType", "POS Invoice").fields, function(d) { + var df = $.map(frappe.get_doc("DocType", "POS Invoice").fields, function (d) { return doc.fieldname == d.fieldname ? d : null; })[0]; @@ -77,5 +111,5 @@ frappe.ui.form.on("POS Field", { doc.fieldtype = df.fieldtype; doc.default_value = df.default; frm.refresh_field("fields"); - } + }, }); diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.js b/erpnext/accounts/doctype/pricing_rule/pricing_rule.js index 826758245a38..cd5b00e6ad00 100644 --- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.js +++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.js @@ -1,44 +1,43 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -frappe.ui.form.on('Pricing Rule', { - setup: function(frm) { - frm.fields_dict["for_price_list"].get_query = function(doc){ +frappe.ui.form.on("Pricing Rule", { + setup: function (frm) { + frm.fields_dict["for_price_list"].get_query = function (doc) { return { filters: { - 'selling': doc.selling, - 'buying': doc.buying, - 'currency': doc.currency - } + selling: doc.selling, + buying: doc.buying, + currency: doc.currency, + }, }; }; - ['items', 'item_groups', 'brands'].forEach(d => { - frm.fields_dict[d].grid.get_field('uom').get_query = function(doc, cdt, cdn){ + ["items", "item_groups", "brands"].forEach((d) => { + frm.fields_dict[d].grid.get_field("uom").get_query = function (doc, cdt, cdn) { var row = locals[cdt][cdn]; return { - query:"erpnext.accounts.doctype.pricing_rule.pricing_rule.get_item_uoms", - filters: {'value': row[frappe.scrub(doc.apply_on)], apply_on: doc.apply_on} - } + query: "erpnext.accounts.doctype.pricing_rule.pricing_rule.get_item_uoms", + filters: { value: row[frappe.scrub(doc.apply_on)], apply_on: doc.apply_on }, + }; }; - }) + }); }, - onload: function(frm) { - if(frm.doc.__islocal && !frm.doc.applicable_for && (frm.doc.customer || frm.doc.supplier)) { - if(frm.doc.customer) { + onload: function (frm) { + if (frm.doc.__islocal && !frm.doc.applicable_for && (frm.doc.customer || frm.doc.supplier)) { + if (frm.doc.customer) { frm.doc.applicable_for = "Customer"; - frm.doc.selling = 1 + frm.doc.selling = 1; } else { frm.doc.applicable_for = "Supplier"; - frm.doc.buying = 1 + frm.doc.buying = 1; } } }, - refresh: function(frm) { - var help_content = - ` + refresh: function (frm) { + var help_content = `

      @@ -97,61 +96,70 @@ frappe.ui.form.on('Pricing Rule', {

      `; - frm.set_df_property('pricing_rule_help', 'options', help_content); + frm.set_df_property("pricing_rule_help", "options", help_content); frm.events.set_options_for_applicable_for(frm); frm.trigger("toggle_reqd_apply_on"); }, - apply_on: function(frm) { + apply_on: function (frm) { frm.trigger("toggle_reqd_apply_on"); }, - toggle_reqd_apply_on: function(frm) { + toggle_reqd_apply_on: function (frm) { const fields = { - 'Item Code': 'items', - 'Item Group': 'item_groups', - 'Brand': 'brands' - } + "Item Code": "items", + "Item Group": "item_groups", + Brand: "brands", + }; for (var key in fields) { - frm.toggle_reqd(fields[key], - frm.doc.apply_on === key ? 1 : 0); + frm.toggle_reqd(fields[key], frm.doc.apply_on === key ? 1 : 0); } }, - rate_or_discount: function(frm) { - if(frm.doc.rate_or_discount == 'Rate') { - frm.set_value('for_price_list', ""); + rate_or_discount: function (frm) { + if (frm.doc.rate_or_discount == "Rate") { + frm.set_value("for_price_list", ""); } }, - selling: function(frm) { + selling: function (frm) { frm.events.set_options_for_applicable_for(frm); }, - buying: function(frm) { + buying: function (frm) { frm.events.set_options_for_applicable_for(frm); }, //Dynamically change the description based on type of margin - margin_type: function(frm){ - frm.set_df_property('margin_rate_or_amount', 'description', frm.doc.margin_type=='Percentage'?'In Percentage %':'In Amount'); + margin_type: function (frm) { + frm.set_df_property( + "margin_rate_or_amount", + "description", + frm.doc.margin_type == "Percentage" ? "In Percentage %" : "In Amount" + ); }, - set_options_for_applicable_for: function(frm) { + set_options_for_applicable_for: function (frm) { var options = [""]; var applicable_for = frm.doc.applicable_for; - if(frm.doc.selling) { - options = $.merge(options, ["Customer", "Customer Group", "Territory", "Sales Partner", "Campaign"]); + if (frm.doc.selling) { + options = $.merge(options, [ + "Customer", + "Customer Group", + "Territory", + "Sales Partner", + "Campaign", + ]); } - if(frm.doc.buying) { + if (frm.doc.buying) { $.merge(options, ["Supplier", "Supplier Group"]); } set_field_options("applicable_for", options.join("\n")); - if(!in_list(options, applicable_for)) applicable_for = null; + if (!in_list(options, applicable_for)) applicable_for = null; frm.set_value("applicable_for", applicable_for); - } + }, }); diff --git a/erpnext/accounts/doctype/process_deferred_accounting/process_deferred_accounting.js b/erpnext/accounts/doctype/process_deferred_accounting/process_deferred_accounting.js index 1ec6805ae0c1..92a6c6259f0f 100644 --- a/erpnext/accounts/doctype/process_deferred_accounting/process_deferred_accounting.js +++ b/erpnext/accounts/doctype/process_deferred_accounting/process_deferred_accounting.js @@ -1,53 +1,58 @@ // Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Process Deferred Accounting', { - setup: function(frm) { - frm.set_query("document_type", function() { +frappe.ui.form.on("Process Deferred Accounting", { + setup: function (frm) { + frm.set_query("document_type", function () { return { filters: { - 'name': ['in', ['Sales Invoice', 'Purchase Invoice']] - } + name: ["in", ["Sales Invoice", "Purchase Invoice"]], + }, }; }); }, - type: function(frm) { + type: function (frm) { if (frm.doc.company && frm.doc.type) { - frm.set_query("account", function() { + frm.set_query("account", function () { return { filters: { - 'company': frm.doc.company, - 'root_type': frm.doc.type === 'Income' ? 'Liability' : 'Asset', - 'is_group': 0 - } + company: frm.doc.company, + root_type: frm.doc.type === "Income" ? "Liability" : "Asset", + is_group: 0, + }, }; }); } }, - validate: function() { + validate: function () { return new Promise((resolve) => { - return frappe.db.get_single_value('Accounts Settings', 'automatically_process_deferred_accounting_entry') - .then(value => { - if(value) { - frappe.throw(__('Manual entry cannot be created! Disable automatic entry for deferred accounting in accounts settings and try again')); + return frappe.db + .get_single_value("Accounts Settings", "automatically_process_deferred_accounting_entry") + .then((value) => { + if (value) { + frappe.throw( + __( + "Manual entry cannot be created! Disable automatic entry for deferred accounting in accounts settings and try again" + ) + ); } resolve(value); }); }); }, - end_date: function(frm) { + end_date: function (frm) { if (frm.doc.end_date && frm.doc.end_date < frm.doc.start_date) { frappe.throw(__("End date cannot be before start date")); } }, - onload: function(frm) { + onload: function (frm) { if (frm.doc.posting_date && frm.doc.docstatus === 0) { - frm.set_value('start_date', frappe.datetime.add_months(frm.doc.posting_date, -1)); - frm.set_value('end_date', frm.doc.posting_date); + frm.set_value("start_date", frappe.datetime.add_months(frm.doc.posting_date, -1)); + frm.set_value("end_date", frm.doc.posting_date); } - } + }, }); diff --git a/erpnext/accounts/doctype/process_payment_reconciliation/process_payment_reconciliation.js b/erpnext/accounts/doctype/process_payment_reconciliation/process_payment_reconciliation.js index dd601bfc4511..0f52a4d998e4 100644 --- a/erpnext/accounts/doctype/process_payment_reconciliation/process_payment_reconciliation.js +++ b/erpnext/accounts/doctype/process_payment_reconciliation/process_payment_reconciliation.js @@ -2,129 +2,128 @@ // For license information, please see license.txt frappe.ui.form.on("Process Payment Reconciliation", { - onload: function(frm) { + onload: function (frm) { // set queries - frm.set_query("party_type", function() { + frm.set_query("party_type", function () { return { - "filters": { - "name": ["in", Object.keys(frappe.boot.party_account_types)], - } - } + filters: { + name: ["in", Object.keys(frappe.boot.party_account_types)], + }, + }; }); - frm.set_query('receivable_payable_account', function(doc) { + frm.set_query("receivable_payable_account", function (doc) { return { filters: { - "company": doc.company, - "is_group": 0, - "account_type": frappe.boot.party_account_types[doc.party_type] - } + company: doc.company, + is_group: 0, + account_type: frappe.boot.party_account_types[doc.party_type], + }, }; }); - frm.set_query('cost_center', function(doc) { + frm.set_query("cost_center", function (doc) { return { filters: { - "company": doc.company, - "is_group": 0, - } + company: doc.company, + is_group: 0, + }, }; }); - frm.set_query('bank_cash_account', function(doc) { + frm.set_query("bank_cash_account", function (doc) { return { - filters:[ - ['Account', 'company', '=', doc.company], - ['Account', 'is_group', '=', 0], - ['Account', 'account_type', 'in', ['Bank', 'Cash']] - ] + filters: [ + ["Account", "company", "=", doc.company], + ["Account", "is_group", "=", 0], + ["Account", "account_type", "in", ["Bank", "Cash"]], + ], }; }); - }, - refresh: function(frm) { - if (frm.doc.docstatus==1 && ['Queued', 'Paused'].find(x => x == frm.doc.status)) { - let execute_btn = __("Start / Resume") + refresh: function (frm) { + if (frm.doc.docstatus == 1 && ["Queued", "Paused"].find((x) => x == frm.doc.status)) { + let execute_btn = __("Start / Resume"); frm.add_custom_button(execute_btn, () => { frm.call({ - method: 'erpnext.accounts.doctype.process_payment_reconciliation.process_payment_reconciliation.trigger_job_for_doc', + method: "erpnext.accounts.doctype.process_payment_reconciliation.process_payment_reconciliation.trigger_job_for_doc", args: { - docname: frm.doc.name - } - }).then(r => { - if(!r.exc) { + docname: frm.doc.name, + }, + }).then((r) => { + if (!r.exc) { frappe.show_alert(__("Job Started")); frm.reload_doc(); } }); }); } - if (frm.doc.docstatus==1 && ['Completed', 'Running', 'Paused', 'Partially Reconciled'].find(x => x == frm.doc.status)) { + if ( + frm.doc.docstatus == 1 && + ["Completed", "Running", "Paused", "Partially Reconciled"].find((x) => x == frm.doc.status) + ) { frm.call({ - 'method': "erpnext.accounts.doctype.process_payment_reconciliation.process_payment_reconciliation.get_reconciled_count", + method: "erpnext.accounts.doctype.process_payment_reconciliation.process_payment_reconciliation.get_reconciled_count", args: { - "docname": frm.docname, - } - }).then(r => { + docname: frm.docname, + }, + }).then((r) => { if (r.message) { let progress = 0; let description = ""; if (r.message.processed) { - progress = (r.message.processed/r.message.total) * 100; - description = r.message.processed + "/" + r.message.total + " processed"; + progress = (r.message.processed / r.message.total) * 100; + description = r.message.processed + "/" + r.message.total + " processed"; } else if (r.message.total == 0 && frm.doc.status == "Completed") { progress = 100; } - - frm.dashboard.add_progress('Reconciliation Progress', progress, description); + frm.dashboard.add_progress("Reconciliation Progress", progress, description); } - }) + }); } - if (frm.doc.docstatus==1 && frm.doc.status == 'Running') { - let execute_btn = __("Pause") + if (frm.doc.docstatus == 1 && frm.doc.status == "Running") { + let execute_btn = __("Pause"); frm.add_custom_button(execute_btn, () => { frm.call({ - 'method': "erpnext.accounts.doctype.process_payment_reconciliation.process_payment_reconciliation.pause_job_for_doc", + method: "erpnext.accounts.doctype.process_payment_reconciliation.process_payment_reconciliation.pause_job_for_doc", args: { - "docname": frm.docname, - } - }).then(r => { + docname: frm.docname, + }, + }).then((r) => { if (!r.exc) { frappe.show_alert(__("Job Paused")); - frm.reload_doc() + frm.reload_doc(); } }); - }); } }, company(frm) { - frm.set_value('party', ''); - frm.set_value('receivable_payable_account', ''); + frm.set_value("party", ""); + frm.set_value("receivable_payable_account", ""); }, party_type(frm) { - frm.set_value('party', ''); + frm.set_value("party", ""); }, party(frm) { - frm.set_value('receivable_payable_account', ''); + frm.set_value("receivable_payable_account", ""); if (!frm.doc.receivable_payable_account && frm.doc.party_type && frm.doc.party) { return frappe.call({ method: "erpnext.accounts.party.get_party_account", args: { company: frm.doc.company, party_type: frm.doc.party_type, - party: frm.doc.party + party: frm.doc.party, }, callback: (r) => { if (!r.exc && r.message) { frm.set_value("receivable_payable_account", r.message); } frm.refresh(); - - } + }, }); } - } + }, }); diff --git a/erpnext/accounts/doctype/process_payment_reconciliation/process_payment_reconciliation_list.js b/erpnext/accounts/doctype/process_payment_reconciliation/process_payment_reconciliation_list.js index 8012d6e03743..ed182adde1b4 100644 --- a/erpnext/accounts/doctype/process_payment_reconciliation/process_payment_reconciliation_list.js +++ b/erpnext/accounts/doctype/process_payment_reconciliation/process_payment_reconciliation_list.js @@ -1,15 +1,15 @@ -frappe.listview_settings['Process Payment Reconciliation'] = { +frappe.listview_settings["Process Payment Reconciliation"] = { add_fields: ["status"], - get_indicator: function(doc) { + get_indicator: function (doc) { let colors = { - 'Queued': 'orange', - 'Paused': 'orange', - 'Completed': 'green', - 'Partially Reconciled': 'orange', - 'Running': 'blue', - 'Failed': 'red', + Queued: "orange", + Paused: "orange", + Completed: "green", + "Partially Reconciled": "orange", + Running: "blue", + Failed: "red", }; let status = doc.status; - return [__(status), colors[status], 'status,=,'+status]; + return [__(status), colors[status], "status,=," + status]; }, }; diff --git a/erpnext/accounts/doctype/process_payment_reconciliation_log/process_payment_reconciliation_log.js b/erpnext/accounts/doctype/process_payment_reconciliation_log/process_payment_reconciliation_log.js index 2468f10bccfd..f483d0039e3c 100644 --- a/erpnext/accounts/doctype/process_payment_reconciliation_log/process_payment_reconciliation_log.js +++ b/erpnext/accounts/doctype/process_payment_reconciliation_log/process_payment_reconciliation_log.js @@ -3,15 +3,14 @@ frappe.ui.form.on("Process Payment Reconciliation Log", { refresh(frm) { - if (['Completed', 'Running', 'Paused', 'Partially Reconciled'].find(x => x == frm.doc.status)) { + if (["Completed", "Running", "Paused", "Partially Reconciled"].find((x) => x == frm.doc.status)) { let progress = 0; if (frm.doc.reconciled_entries != 0) { - progress = frm.doc.reconciled_entries / frm.doc.total_allocations * 100; - } else if(frm.doc.total_allocations == 0 && frm.doc.status == "Completed"){ + progress = (frm.doc.reconciled_entries / frm.doc.total_allocations) * 100; + } else if (frm.doc.total_allocations == 0 && frm.doc.status == "Completed") { progress = 100; } - frm.dashboard.add_progress(__('Reconciliation Progress'), progress); + frm.dashboard.add_progress(__("Reconciliation Progress"), progress); } - }, }); diff --git a/erpnext/accounts/doctype/process_payment_reconciliation_log/process_payment_reconciliation_log_list.js b/erpnext/accounts/doctype/process_payment_reconciliation_log/process_payment_reconciliation_log_list.js index 5a652048a235..19c73b249dcf 100644 --- a/erpnext/accounts/doctype/process_payment_reconciliation_log/process_payment_reconciliation_log_list.js +++ b/erpnext/accounts/doctype/process_payment_reconciliation_log/process_payment_reconciliation_log_list.js @@ -1,15 +1,15 @@ -frappe.listview_settings['Process Payment Reconciliation Log'] = { +frappe.listview_settings["Process Payment Reconciliation Log"] = { add_fields: ["status"], - get_indicator: function(doc) { + get_indicator: function (doc) { var colors = { - 'Partially Reconciled': 'orange', - 'Paused': 'orange', - 'Reconciled': 'green', - 'Failed': 'red', - 'Cancelled': 'red', - 'Running': 'blue', + "Partially Reconciled": "orange", + Paused: "orange", + Reconciled: "green", + Failed: "red", + Cancelled: "red", + Running: "blue", }; let status = doc.status; - return [__(status), colors[status], "status,=,"+status]; + return [__(status), colors[status], "status,=," + status]; }, }; diff --git a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.js b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.js index c5908b783ee5..be3579e2d640 100644 --- a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.js +++ b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.js @@ -1,153 +1,148 @@ // Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Process Statement Of Accounts', { - view_properties: function(frm) { - frappe.route_options = {doc_type: 'Customer'}; +frappe.ui.form.on("Process Statement Of Accounts", { + view_properties: function (frm) { + frappe.route_options = { doc_type: "Customer" }; frappe.set_route("Form", "Customize Form"); }, - refresh: function(frm){ - if(!frm.doc.__islocal) { - frm.add_custom_button(__('Send Emails'), function(){ + refresh: function (frm) { + if (!frm.doc.__islocal) { + frm.add_custom_button(__("Send Emails"), function () { frappe.call({ method: "erpnext.accounts.doctype.process_statement_of_accounts.process_statement_of_accounts.send_emails", args: { - "document_name": frm.doc.name, + document_name: frm.doc.name, }, - callback: function(r) { - if(r && r.message) { - frappe.show_alert({message: __('Emails Queued'), indicator: 'blue'}); + callback: function (r) { + if (r && r.message) { + frappe.show_alert({ message: __("Emails Queued"), indicator: "blue" }); + } else { + frappe.msgprint(__("No Records for these settings.")); } - else{ - frappe.msgprint(__('No Records for these settings.')) - } - } + }, }); }); - frm.add_custom_button(__('Download'), function(){ + frm.add_custom_button(__("Download"), function () { var url = frappe.urllib.get_full_url( - '/api/method/erpnext.accounts.doctype.process_statement_of_accounts.process_statement_of_accounts.download_statements?' - + 'document_name='+encodeURIComponent(frm.doc.name)) + "/api/method/erpnext.accounts.doctype.process_statement_of_accounts.process_statement_of_accounts.download_statements?" + + "document_name=" + + encodeURIComponent(frm.doc.name) + ); $.ajax({ url: url, - type: 'GET', - success: function(result) { - if(jQuery.isEmptyObject(result)){ - frappe.msgprint(__('No Records for these settings.')); - } - else{ + type: "GET", + success: function (result) { + if (jQuery.isEmptyObject(result)) { + frappe.msgprint(__("No Records for these settings.")); + } else { window.location = url; } - } + }, }); }); } }, - onload: function(frm) { - frm.set_query('currency', function(){ + onload: function (frm) { + frm.set_query("currency", function () { return { filters: { - 'enabled': 1 - } - } + enabled: 1, + }, + }; }); - frm.set_query("account", function() { + frm.set_query("account", function () { return { filters: { - 'company': frm.doc.company - } + company: frm.doc.company, + }, }; }); - if(frm.doc.__islocal){ - frm.set_value('from_date', frappe.datetime.add_months(frappe.datetime.get_today(), -1)); - frm.set_value('to_date', frappe.datetime.get_today()); + if (frm.doc.__islocal) { + frm.set_value("from_date", frappe.datetime.add_months(frappe.datetime.get_today(), -1)); + frm.set_value("to_date", frappe.datetime.get_today()); } }, - report: function(frm){ + report: function (frm) { let filters = { - 'company': frm.doc.company, - } - if(frm.doc.report == 'Accounts Receivable'){ - filters['account_type'] = 'Receivable'; + company: frm.doc.company, + }; + if (frm.doc.report == "Accounts Receivable") { + filters["account_type"] = "Receivable"; } - frm.set_query("account", function() { + frm.set_query("account", function () { return { - filters: filters + filters: filters, }; }); - }, - customer_collection: function(frm){ - frm.set_value('collection_name', ''); - if(frm.doc.customer_collection){ - frm.get_field('collection_name').set_label(frm.doc.customer_collection); + customer_collection: function (frm) { + frm.set_value("collection_name", ""); + if (frm.doc.customer_collection) { + frm.get_field("collection_name").set_label(frm.doc.customer_collection); } }, - frequency: function(frm){ - if(frm.doc.frequency != ''){ - frm.set_value('start_date', frappe.datetime.get_today()); - } - else{ - frm.set_value('start_date', ''); + frequency: function (frm) { + if (frm.doc.frequency != "") { + frm.set_value("start_date", frappe.datetime.get_today()); + } else { + frm.set_value("start_date", ""); } }, - fetch_customers: function(frm){ - if(frm.doc.collection_name){ + fetch_customers: function (frm) { + if (frm.doc.collection_name) { frappe.call({ method: "erpnext.accounts.doctype.process_statement_of_accounts.process_statement_of_accounts.fetch_customers", args: { - 'customer_collection': frm.doc.customer_collection, - 'collection_name': frm.doc.collection_name, - 'primary_mandatory': frm.doc.primary_mandatory + customer_collection: frm.doc.customer_collection, + collection_name: frm.doc.collection_name, + primary_mandatory: frm.doc.primary_mandatory, }, - callback: function(r) { - if(!r.exc) { - if(r.message.length){ - frm.clear_table('customers'); - for (const customer of r.message){ - var row = frm.add_child('customers'); + callback: function (r) { + if (!r.exc) { + if (r.message.length) { + frm.clear_table("customers"); + for (const customer of r.message) { + var row = frm.add_child("customers"); row.customer = customer.name; row.primary_email = customer.primary_email; row.billing_email = customer.billing_email; } - frm.refresh_field('customers'); - } - else{ - frappe.throw(__('No Customers found with selected options.')); + frm.refresh_field("customers"); + } else { + frappe.throw(__("No Customers found with selected options.")); } } - } + }, }); + } else { + frappe.throw("Enter " + frm.doc.customer_collection + " name."); } - else { - frappe.throw('Enter ' + frm.doc.customer_collection + ' name.'); - } - } + }, }); -frappe.ui.form.on('Process Statement Of Accounts Customer', { - customer: function(frm, cdt, cdn){ +frappe.ui.form.on("Process Statement Of Accounts Customer", { + customer: function (frm, cdt, cdn) { var row = locals[cdt][cdn]; - if (!row.customer){ + if (!row.customer) { return; } frappe.call({ - method: 'erpnext.accounts.doctype.process_statement_of_accounts.process_statement_of_accounts.get_customer_emails', + method: "erpnext.accounts.doctype.process_statement_of_accounts.process_statement_of_accounts.get_customer_emails", args: { - 'customer_name': row.customer, - 'primary_mandatory': frm.doc.primary_mandatory + customer_name: row.customer, + primary_mandatory: frm.doc.primary_mandatory, }, - callback: function(r){ - if(!r.exe){ - if(r.message.length){ - frappe.model.set_value(cdt, cdn, "primary_email", r.message[0]) - frappe.model.set_value(cdt, cdn, "billing_email", r.message[1]) - } - else { - return + callback: function (r) { + if (!r.exe) { + if (r.message.length) { + frappe.model.set_value(cdt, cdn, "primary_email", r.message[0]); + frappe.model.set_value(cdt, cdn, "billing_email", r.message[1]); + } else { + return; } } - } - }) - } + }, + }); + }, }); diff --git a/erpnext/accounts/doctype/promotional_scheme/promotional_scheme.js b/erpnext/accounts/doctype/promotional_scheme/promotional_scheme.js index e840c79cd759..7a26c07d01f1 100644 --- a/erpnext/accounts/doctype/promotional_scheme/promotional_scheme.js +++ b/erpnext/accounts/doctype/promotional_scheme/promotional_scheme.js @@ -1,51 +1,56 @@ // Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Promotional Scheme', { - refresh: function(frm) { +frappe.ui.form.on("Promotional Scheme", { + refresh: function (frm) { frm.trigger("set_options_for_applicable_for"); frm.trigger("toggle_reqd_apply_on"); }, - selling: function(frm) { + selling: function (frm) { frm.trigger("set_options_for_applicable_for"); }, - buying: function(frm) { + buying: function (frm) { frm.trigger("set_options_for_applicable_for"); }, - set_options_for_applicable_for: function(frm) { + set_options_for_applicable_for: function (frm) { var options = [""]; var applicable_for = frm.doc.applicable_for; - if(frm.doc.selling) { - options = $.merge(options, ["Customer", "Customer Group", "Territory", "Sales Partner", "Campaign"]); + if (frm.doc.selling) { + options = $.merge(options, [ + "Customer", + "Customer Group", + "Territory", + "Sales Partner", + "Campaign", + ]); } - if(frm.doc.buying) { + if (frm.doc.buying) { $.merge(options, ["Supplier", "Supplier Group"]); } set_field_options("applicable_for", options.join("\n")); - if(!in_list(options, applicable_for)) applicable_for = null; + if (!in_list(options, applicable_for)) applicable_for = null; frm.set_value("applicable_for", applicable_for); }, - apply_on: function(frm) { + apply_on: function (frm) { frm.trigger("toggle_reqd_apply_on"); }, - toggle_reqd_apply_on: function(frm) { + toggle_reqd_apply_on: function (frm) { const fields = { - 'Item Code': 'items', - 'Item Group': 'item_groups', - 'Brand': 'brands' + "Item Code": "items", + "Item Group": "item_groups", + Brand: "brands", }; for (var key in fields) { - frm.toggle_reqd(fields[key], - frm.doc.apply_on === key ? 1 : 0); + frm.toggle_reqd(fields[key], frm.doc.apply_on === key ? 1 : 0); } - } + }, }); diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice_list.js b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice_list.js index e1c37c600133..4350ba111485 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice_list.js +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice_list.js @@ -22,48 +22,35 @@ frappe.listview_settings["Purchase Invoice"] = { return [__(doc.status), "darkgrey", "status,=," + doc.status]; } - if ( - flt(doc.outstanding_amount) > 0 && - doc.docstatus == 1 && - cint(doc.on_hold) - ) { + if (flt(doc.outstanding_amount) > 0 && doc.docstatus == 1 && cint(doc.on_hold)) { if (!doc.release_date) { return [__("On Hold"), "darkgrey"]; - } else if ( - frappe.datetime.get_diff( - doc.release_date, - frappe.datetime.nowdate() - ) > 0 - ) { + } else if (frappe.datetime.get_diff(doc.release_date, frappe.datetime.nowdate()) > 0) { return [__("Temporarily on Hold"), "darkgrey"]; } } const status_colors = { - "Unpaid": "orange", - "Paid": "green", - "Return": "gray", - "Overdue": "red", + Unpaid: "orange", + Paid: "green", + Return: "gray", + Overdue: "red", "Partly Paid": "yellow", "Internal Transfer": "darkgrey", }; if (status_colors[doc.status]) { - return [ - __(doc.status), - status_colors[doc.status], - "status,=," + doc.status, - ]; + return [__(doc.status), status_colors[doc.status], "status,=," + doc.status]; } }, - onload: function(listview) { - listview.page.add_action_item(__("Purchase Receipt"), ()=>{ + onload: function (listview) { + listview.page.add_action_item(__("Purchase Receipt"), () => { erpnext.bulk_transaction_processing.create(listview, "Purchase Invoice", "Purchase Receipt"); }); - listview.page.add_action_item(__("Payment"), ()=>{ + listview.page.add_action_item(__("Payment"), () => { erpnext.bulk_transaction_processing.create(listview, "Purchase Invoice", "Payment Entry"); }); - } + }, }; diff --git a/erpnext/accounts/doctype/repost_accounting_ledger/repost_accounting_ledger.js b/erpnext/accounts/doctype/repost_accounting_ledger/repost_accounting_ledger.js index c7b7a148cfb3..c304c7f17eb8 100644 --- a/erpnext/accounts/doctype/repost_accounting_ledger/repost_accounting_ledger.js +++ b/erpnext/accounts/doctype/repost_accounting_ledger/repost_accounting_ledger.js @@ -2,47 +2,47 @@ // For license information, please see license.txt frappe.ui.form.on("Repost Accounting Ledger", { - setup: function(frm) { - frm.fields_dict['vouchers'].grid.get_field('voucher_type').get_query = function(doc) { + setup: function (frm) { + frm.fields_dict["vouchers"].grid.get_field("voucher_type").get_query = function (doc) { return { - query: "erpnext.accounts.doctype.repost_accounting_ledger.repost_accounting_ledger.get_repost_allowed_types" - } - } + query: "erpnext.accounts.doctype.repost_accounting_ledger.repost_accounting_ledger.get_repost_allowed_types", + }; + }; - frm.fields_dict['vouchers'].grid.get_field('voucher_no').get_query = function(doc) { + frm.fields_dict["vouchers"].grid.get_field("voucher_no").get_query = function (doc) { if (doc.company) { return { filters: { company: doc.company, - docstatus: 1 - } - } + docstatus: 1, + }, + }; } - } + }; }, - refresh: function(frm) { - frm.add_custom_button(__('Show Preview'), () => { + refresh: function (frm) { + frm.add_custom_button(__("Show Preview"), () => { frm.call({ - method: 'generate_preview', + method: "generate_preview", doc: frm.doc, freeze: true, - freeze_message: __('Generating Preview'), - callback: function(r) { + freeze_message: __("Generating Preview"), + callback: function (r) { if (r && r.message) { let content = r.message; let opts = { title: "Preview", subtitle: "preview", content: content, - print_settings: {orientation: "landscape"}, + print_settings: { orientation: "landscape" }, columns: [], data: [], - } + }; frappe.render_grid(opts); } - } + }, }); }); - } + }, }); diff --git a/erpnext/accounts/doctype/repost_payment_ledger/repost_payment_ledger.js b/erpnext/accounts/doctype/repost_payment_ledger/repost_payment_ledger.js index 6801408c7b3c..b9621c06eb83 100644 --- a/erpnext/accounts/doctype/repost_payment_ledger/repost_payment_ledger.js +++ b/erpnext/accounts/doctype/repost_payment_ledger/repost_payment_ledger.js @@ -1,53 +1,53 @@ // Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Repost Payment Ledger', { - setup: function(frm) { +frappe.ui.form.on("Repost Payment Ledger", { + setup: function (frm) { frm.set_query("voucher_type", () => { return { filters: { - name: ['in', ['Purchase Invoice', 'Sales Invoice', 'Payment Entry', 'Journal Entry']] - } + name: ["in", ["Purchase Invoice", "Sales Invoice", "Payment Entry", "Journal Entry"]], + }, }; }); - frm.fields_dict['repost_vouchers'].grid.get_field('voucher_type').get_query = function(doc) { + frm.fields_dict["repost_vouchers"].grid.get_field("voucher_type").get_query = function (doc) { return { filters: { - name: ['in', ['Purchase Invoice', 'Sales Invoice', 'Payment Entry', 'Journal Entry']] - } - } - } + name: ["in", ["Purchase Invoice", "Sales Invoice", "Payment Entry", "Journal Entry"]], + }, + }; + }; - frm.fields_dict['repost_vouchers'].grid.get_field('voucher_no').get_query = function(doc) { + frm.fields_dict["repost_vouchers"].grid.get_field("voucher_no").get_query = function (doc) { if (doc.company) { return { filters: { company: doc.company, - docstatus: 1 - } - } + docstatus: 1, + }, + }; } - } - + }; }, - refresh: function(frm) { - - if (frm.doc.docstatus==1 && ['Queued', 'Failed'].find(x => x == frm.doc.repost_status)) { - frm.set_intro(__("Use 'Repost in background' button to trigger background job. Job can only be triggered when document is in Queued or Failed status.")); - var btn_label = __("Repost in background") + refresh: function (frm) { + if (frm.doc.docstatus == 1 && ["Queued", "Failed"].find((x) => x == frm.doc.repost_status)) { + frm.set_intro( + __( + "Use 'Repost in background' button to trigger background job. Job can only be triggered when document is in Queued or Failed status." + ) + ); + var btn_label = __("Repost in background"); frm.add_custom_button(btn_label, () => { frappe.call({ - method: 'erpnext.accounts.doctype.repost_payment_ledger.repost_payment_ledger.execute_repost_payment_ledger', + method: "erpnext.accounts.doctype.repost_payment_ledger.repost_payment_ledger.execute_repost_payment_ledger", args: { docname: frm.doc.name, - } + }, }); - frappe.msgprint(__('Reposting in the background.')); + frappe.msgprint(__("Reposting in the background.")); }); } - - } + }, }); - diff --git a/erpnext/accounts/doctype/repost_payment_ledger/repost_payment_ledger_list.js b/erpnext/accounts/doctype/repost_payment_ledger/repost_payment_ledger_list.js index e0451845cede..76d17fc68604 100644 --- a/erpnext/accounts/doctype/repost_payment_ledger/repost_payment_ledger_list.js +++ b/erpnext/accounts/doctype/repost_payment_ledger/repost_payment_ledger_list.js @@ -1,12 +1,12 @@ frappe.listview_settings["Repost Payment Ledger"] = { add_fields: ["repost_status"], - get_indicator: function(doc) { + get_indicator: function (doc) { var colors = { - 'Queued': 'orange', - 'Completed': 'green', - 'Failed': 'red', + Queued: "orange", + Completed: "green", + Failed: "red", }; let status = doc.repost_status; - return [__(status), colors[status], 'status,=,'+status]; + return [__(status), colors[status], "status,=," + status]; }, }; diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice_list.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice_list.js index 1605b151a14f..f971f68a4546 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice_list.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice_list.js @@ -2,34 +2,42 @@ // License: GNU General Public License v3. See license.txt // render -frappe.listview_settings['Sales Invoice'] = { - add_fields: ["customer", "customer_name", "base_grand_total", "outstanding_amount", "due_date", "company", - "currency", "is_return"], - get_indicator: function(doc) { +frappe.listview_settings["Sales Invoice"] = { + add_fields: [ + "customer", + "customer_name", + "base_grand_total", + "outstanding_amount", + "due_date", + "company", + "currency", + "is_return", + ], + get_indicator: function (doc) { const status_colors = { - "Draft": "grey", - "Unpaid": "orange", - "Paid": "green", - "Return": "gray", + Draft: "grey", + Unpaid: "orange", + Paid: "green", + Return: "gray", "Credit Note Issued": "gray", "Unpaid and Discounted": "orange", "Partly Paid and Discounted": "yellow", "Overdue and Discounted": "red", - "Overdue": "red", + Overdue: "red", "Partly Paid": "yellow", - "Internal Transfer": "darkgrey" + "Internal Transfer": "darkgrey", }; - return [__(doc.status), status_colors[doc.status], "status,=,"+doc.status]; + return [__(doc.status), status_colors[doc.status], "status,=," + doc.status]; }, right_column: "grand_total", - onload: function(listview) { - listview.page.add_action_item(__("Delivery Note"), ()=>{ + onload: function (listview) { + listview.page.add_action_item(__("Delivery Note"), () => { erpnext.bulk_transaction_processing.create(listview, "Sales Invoice", "Delivery Note"); }); - listview.page.add_action_item(__("Payment"), ()=>{ + listview.page.add_action_item(__("Payment"), () => { erpnext.bulk_transaction_processing.create(listview, "Sales Invoice", "Payment Entry"); }); - } + }, }; diff --git a/erpnext/accounts/doctype/share_transfer/share_transfer.js b/erpnext/accounts/doctype/share_transfer/share_transfer.js index 6317c9c8c0d1..dd9d9628aa88 100644 --- a/erpnext/accounts/doctype/share_transfer/share_transfer.js +++ b/erpnext/accounts/doctype/share_transfer/share_transfer.js @@ -3,21 +3,19 @@ frappe.provide("erpnext.share_transfer"); -frappe.ui.form.on('Share Transfer', { - refresh: function(frm) { +frappe.ui.form.on("Share Transfer", { + refresh: function (frm) { // Don't show Parties which are a Company - let shareholders = ['from_shareholder', 'to_shareholder']; + let shareholders = ["from_shareholder", "to_shareholder"]; shareholders.forEach((shareholder) => { - frm.fields_dict[shareholder].get_query = function() { + frm.fields_dict[shareholder].get_query = function () { return { - filters: [ - ["Shareholder", "is_company", "=", 0] - ] + filters: [["Shareholder", "is_company", "=", 0]], }; }; }); if (frm.doc.docstatus == 1 && frm.doc.equity_or_liability_account && frm.doc.asset_account) { - frm.add_custom_button(__('Create Journal Entry'), function () { + frm.add_custom_button(__("Create Journal Entry"), function () { erpnext.share_transfer.make_jv(frm); }); } @@ -25,54 +23,59 @@ frappe.ui.form.on('Share Transfer', { frm.toggle_reqd("asset_account", frm.doc.transfer_type != "Transfer"); }, no_of_shares: (frm) => { - if (frm.doc.rate != undefined || frm.doc.rate != null){ + if (frm.doc.rate != undefined || frm.doc.rate != null) { erpnext.share_transfer.update_amount(frm); } }, rate: (frm) => { - if (frm.doc.no_of_shares != undefined || frm.doc.no_of_shares != null){ + if (frm.doc.no_of_shares != undefined || frm.doc.no_of_shares != null) { erpnext.share_transfer.update_amount(frm); } }, - company: async function(frm) { + company: async function (frm) { if (frm.doc.company) { - let currency = (await frappe.db.get_value("Company", frm.doc.company, "default_currency")).message.default_currency; - frm.set_query("equity_or_liability_account", function() { + let currency = (await frappe.db.get_value("Company", frm.doc.company, "default_currency")).message + .default_currency; + frm.set_query("equity_or_liability_account", function () { return { filters: { - "is_group":0, - "root_type": ["in",["Equity","Liability"]], - "company": frm.doc.company, - "account_currency": currency - } + is_group: 0, + root_type: ["in", ["Equity", "Liability"]], + company: frm.doc.company, + account_currency: currency, + }, }; }); - frm.set_query("asset_account", function() { + frm.set_query("asset_account", function () { return { filters: { - "is_group":0, - "root_type":"Asset", - "company": frm.doc.company, - "account_currency": currency - } + is_group: 0, + root_type: "Asset", + company: frm.doc.company, + account_currency: currency, + }, }; }); } }, - transfer_type: function(frm) { + transfer_type: function (frm) { frm.toggle_reqd("asset_account", frm.doc.transfer_type != "Transfer"); - } + }, }); -erpnext.share_transfer.update_amount = function(frm) { +erpnext.share_transfer.update_amount = function (frm) { frm.doc.amount = frm.doc.no_of_shares * frm.doc.rate; frm.refresh_field("amount"); }; erpnext.share_transfer.make_jv = function (frm) { - var account, payment_account, credit_applicant_type, credit_applicant, - debit_applicant_type, debit_applicant; + var account, + payment_account, + credit_applicant_type, + credit_applicant, + debit_applicant_type, + debit_applicant; if (frm.doc.transfer_type == "Transfer") { account = frm.doc.equity_or_liability_account; @@ -81,16 +84,14 @@ erpnext.share_transfer.make_jv = function (frm) { credit_applicant = frm.doc.to_shareholder; debit_applicant_type = "Shareholder"; debit_applicant = frm.doc.from_shareholder; - } - else if (frm.doc.transfer_type == "Issue") { + } else if (frm.doc.transfer_type == "Issue") { account = frm.doc.asset_account; payment_account = frm.doc.equity_or_liability_account; credit_applicant_type = "Shareholder"; credit_applicant = frm.doc.to_shareholder; debit_applicant_type = ""; debit_applicant = ""; - } - else { + } else { account = frm.doc.equity_or_liability_account; payment_account = frm.doc.asset_account; credit_applicant_type = ""; @@ -100,19 +101,19 @@ erpnext.share_transfer.make_jv = function (frm) { } frappe.call({ args: { - "company": frm.doc.company, - "account": account, - "amount": frm.doc.amount, - "payment_account": payment_account, - "credit_applicant_type": credit_applicant_type, - "credit_applicant": credit_applicant, - "debit_applicant_type": debit_applicant_type, - "debit_applicant": debit_applicant + company: frm.doc.company, + account: account, + amount: frm.doc.amount, + payment_account: payment_account, + credit_applicant_type: credit_applicant_type, + credit_applicant: credit_applicant, + debit_applicant_type: debit_applicant_type, + debit_applicant: debit_applicant, }, method: "erpnext.accounts.doctype.share_transfer.share_transfer.make_jv_entry", callback: function (r) { var doc = frappe.model.sync(r.message)[0]; frappe.set_route("Form", doc.doctype, doc.name); - } + }, }); }; diff --git a/erpnext/accounts/doctype/share_type/share_type.js b/erpnext/accounts/doctype/share_type/share_type.js index 1ae85e3a57ea..5dfb7607fed4 100644 --- a/erpnext/accounts/doctype/share_type/share_type.js +++ b/erpnext/accounts/doctype/share_type/share_type.js @@ -1,8 +1,6 @@ // Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Share Type', { - refresh: function(frm) { - - } +frappe.ui.form.on("Share Type", { + refresh: function (frm) {}, }); diff --git a/erpnext/accounts/doctype/shareholder/shareholder.js b/erpnext/accounts/doctype/shareholder/shareholder.js index c6f101e7f31d..2a31b805ab37 100644 --- a/erpnext/accounts/doctype/shareholder/shareholder.js +++ b/erpnext/accounts/doctype/shareholder/shareholder.js @@ -1,39 +1,38 @@ // Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Shareholder', { - refresh: function(frm) { - frappe.dynamic_link = { doc: frm.doc, fieldname: 'name', doctype: 'Shareholder' }; +frappe.ui.form.on("Shareholder", { + refresh: function (frm) { + frappe.dynamic_link = { doc: frm.doc, fieldname: "name", doctype: "Shareholder" }; - frm.toggle_display(['contact_html'], !frm.doc.__islocal); + frm.toggle_display(["contact_html"], !frm.doc.__islocal); if (frm.doc.__islocal) { - hide_field(['contact_html']); + hide_field(["contact_html"]); frappe.contacts.clear_address_and_contact(frm); - } - else { - if (frm.doc.is_company){ - hide_field(['company']); + } else { + if (frm.doc.is_company) { + hide_field(["company"]); } else { - unhide_field(['contact_html']); + unhide_field(["contact_html"]); frappe.contacts.render_address_and_contact(frm); } } - if (frm.doc.folio_no != undefined){ - frm.add_custom_button(__("Share Balance"), function(){ + if (frm.doc.folio_no != undefined) { + frm.add_custom_button(__("Share Balance"), function () { frappe.route_options = { - "shareholder": frm.doc.name, + shareholder: frm.doc.name, }; frappe.set_route("query-report", "Share Balance"); }); - frm.add_custom_button(__("Share Ledger"), function(){ + frm.add_custom_button(__("Share Ledger"), function () { frappe.route_options = { - "shareholder": frm.doc.name, + shareholder: frm.doc.name, }; frappe.set_route("query-report", "Share Ledger"); }); - let fields = ['title', 'folio_no', 'company']; + let fields = ["title", "folio_no", "company"]; fields.forEach((fieldname) => { frm.fields_dict[fieldname].df.read_only = 1; frm.refresh_fields(fieldname); @@ -44,11 +43,11 @@ frappe.ui.form.on('Shareholder', { }, validate: (frm) => { let contact_list = { - contacts: [] + contacts: [], }; - $('div[data-fieldname=contact_html] > .address-box').each( (index, ele) => { - contact_list.contacts.push(ele.innerText.replace(' Edit', '')); + $("div[data-fieldname=contact_html] > .address-box").each((index, ele) => { + contact_list.contacts.push(ele.innerText.replace(" Edit", "")); }); frm.doc.contact_list = JSON.stringify(contact_list); - } + }, }); diff --git a/erpnext/accounts/doctype/shipping_rule/shipping_rule.js b/erpnext/accounts/doctype/shipping_rule/shipping_rule.js index 8e4b806f02da..1ece3e6c3dd1 100644 --- a/erpnext/accounts/doctype/shipping_rule/shipping_rule.js +++ b/erpnext/accounts/doctype/shipping_rule/shipping_rule.js @@ -1,33 +1,33 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -frappe.provide('erpnext.accounts.dimensions'); +frappe.provide("erpnext.accounts.dimensions"); -frappe.ui.form.on('Shipping Rule', { - onload: function(frm) { +frappe.ui.form.on("Shipping Rule", { + onload: function (frm) { erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype); }, - company: function(frm) { + company: function (frm) { erpnext.accounts.dimensions.update_dimension(frm, frm.doctype); }, - refresh: function(frm) { - frm.set_query("account", function() { + refresh: function (frm) { + frm.set_query("account", function () { return { filters: { - company: frm.doc.company - } - } - }) + company: frm.doc.company, + }, + }; + }); - frm.trigger('toggle_reqd'); + frm.trigger("toggle_reqd"); }, - calculate_based_on: function(frm) { - frm.trigger('toggle_reqd'); + calculate_based_on: function (frm) { + frm.trigger("toggle_reqd"); + }, + toggle_reqd: function (frm) { + frm.toggle_reqd("shipping_amount", frm.doc.calculate_based_on === "Fixed"); + frm.toggle_reqd("conditions", frm.doc.calculate_based_on !== "Fixed"); }, - toggle_reqd: function(frm) { - frm.toggle_reqd("shipping_amount", frm.doc.calculate_based_on === 'Fixed'); - frm.toggle_reqd("conditions", frm.doc.calculate_based_on !== 'Fixed'); - } }); diff --git a/erpnext/accounts/doctype/subscription/subscription.js b/erpnext/accounts/doctype/subscription/subscription.js index 4b351f9d7649..60981f4b1d15 100644 --- a/erpnext/accounts/doctype/subscription/subscription.js +++ b/erpnext/accounts/doctype/subscription/subscription.js @@ -1,104 +1,99 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Subscription', { - setup: function(frm) { - frm.set_query('party_type', function() { +frappe.ui.form.on("Subscription", { + setup: function (frm) { + frm.set_query("party_type", function () { return { - filters : { - name: ['in', ['Customer', 'Supplier']] - } - } + filters: { + name: ["in", ["Customer", "Supplier"]], + }, + }; }); - frm.set_query('cost_center', function() { + frm.set_query("cost_center", function () { return { filters: { - company: frm.doc.company - } + company: frm.doc.company, + }, }; }); - frm.set_query('sales_tax_template', function () { + frm.set_query("sales_tax_template", function () { return { filters: { - company: frm.doc.company - } + company: frm.doc.company, + }, }; }); }, - refresh: function(frm) { - if(!frm.is_new()){ - if(frm.doc.status !== 'Cancelled'){ - frm.add_custom_button( - __('Cancel Subscription'), - () => frm.events.cancel_this_subscription(frm) + refresh: function (frm) { + if (!frm.is_new()) { + if (frm.doc.status !== "Cancelled") { + frm.add_custom_button(__("Cancel Subscription"), () => + frm.events.cancel_this_subscription(frm) ); - frm.add_custom_button( - __('Fetch Subscription Updates'), - () => frm.events.get_subscription_updates(frm) + frm.add_custom_button(__("Fetch Subscription Updates"), () => + frm.events.get_subscription_updates(frm) ); - } - else if(frm.doc.status === 'Cancelled'){ - frm.add_custom_button( - __('Restart Subscription'), - () => frm.events.renew_this_subscription(frm) + } else if (frm.doc.status === "Cancelled") { + frm.add_custom_button(__("Restart Subscription"), () => + frm.events.renew_this_subscription(frm) ); } } }, - cancel_this_subscription: function(frm) { + cancel_this_subscription: function (frm) { const doc = frm.doc; frappe.confirm( - __('This action will stop future billing. Are you sure you want to cancel this subscription?'), - function() { + __("This action will stop future billing. Are you sure you want to cancel this subscription?"), + function () { frappe.call({ - method: - "erpnext.accounts.doctype.subscription.subscription.cancel_subscription", - args: {name: doc.name}, - callback: function(data){ - if(!data.exc){ + method: "erpnext.accounts.doctype.subscription.subscription.cancel_subscription", + args: { name: doc.name }, + callback: function (data) { + if (!data.exc) { frm.reload_doc(); } - } + }, }); } ); }, - renew_this_subscription: function(frm) { + renew_this_subscription: function (frm) { const doc = frm.doc; frappe.confirm( - __('You will lose records of previously generated invoices. Are you sure you want to restart this subscription?'), - function() { + __( + "You will lose records of previously generated invoices. Are you sure you want to restart this subscription?" + ), + function () { frappe.call({ - method: - "erpnext.accounts.doctype.subscription.subscription.restart_subscription", - args: {name: doc.name}, - callback: function(data){ - if(!data.exc){ + method: "erpnext.accounts.doctype.subscription.subscription.restart_subscription", + args: { name: doc.name }, + callback: function (data) { + if (!data.exc) { frm.reload_doc(); } - } + }, }); } ); }, - get_subscription_updates: function(frm) { + get_subscription_updates: function (frm) { const doc = frm.doc; frappe.call({ - method: - "erpnext.accounts.doctype.subscription.subscription.get_subscription_updates", - args: {name: doc.name}, + method: "erpnext.accounts.doctype.subscription.subscription.get_subscription_updates", + args: { name: doc.name }, freeze: true, - callback: function(data){ - if(!data.exc){ + callback: function (data) { + if (!data.exc) { frm.reload_doc(); } - } + }, }); - } + }, }); diff --git a/erpnext/accounts/doctype/subscription/subscription_list.js b/erpnext/accounts/doctype/subscription/subscription_list.js index 6490ff3776e3..55430a15c5db 100644 --- a/erpnext/accounts/doctype/subscription/subscription_list.js +++ b/erpnext/accounts/doctype/subscription/subscription_list.js @@ -1,17 +1,17 @@ -frappe.listview_settings['Subscription'] = { - get_indicator: function(doc) { - if(doc.status === 'Trialling') { +frappe.listview_settings["Subscription"] = { + get_indicator: function (doc) { + if (doc.status === "Trialling") { return [__("Trialling"), "green"]; - } else if(doc.status === 'Active') { + } else if (doc.status === "Active") { return [__("Active"), "green"]; - } else if(doc.status === 'Completed') { - return [__("Completed"), "green"]; - } else if(doc.status === 'Past Due Date') { + } else if (doc.status === "Completed") { + return [__("Completed"), "green"]; + } else if (doc.status === "Past Due Date") { return [__("Past Due Date"), "orange"]; - } else if(doc.status === 'Unpaid') { + } else if (doc.status === "Unpaid") { return [__("Unpaid"), "red"]; - } else if(doc.status === 'Cancelled') { + } else if (doc.status === "Cancelled") { return [__("Cancelled"), "gray"]; } - } + }, }; diff --git a/erpnext/accounts/doctype/subscription_plan/subscription_plan.js b/erpnext/accounts/doctype/subscription_plan/subscription_plan.js index 00727f103f98..125dc7dd9ae9 100644 --- a/erpnext/accounts/doctype/subscription_plan/subscription_plan.js +++ b/erpnext/accounts/doctype/subscription_plan/subscription_plan.js @@ -1,10 +1,10 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Subscription Plan', { - price_determination: function(frm) { - frm.toggle_reqd("cost", frm.doc.price_determination === 'Fixed rate'); - frm.toggle_reqd("price_list", frm.doc.price_determination === 'Based on price list'); +frappe.ui.form.on("Subscription Plan", { + price_determination: function (frm) { + frm.toggle_reqd("cost", frm.doc.price_determination === "Fixed rate"); + frm.toggle_reqd("price_list", frm.doc.price_determination === "Based on price list"); }, subscription_plan: function (frm) { diff --git a/erpnext/accounts/doctype/tax_category/tax_category.js b/erpnext/accounts/doctype/tax_category/tax_category.js index 4b63edbde2d2..fe60e037b166 100644 --- a/erpnext/accounts/doctype/tax_category/tax_category.js +++ b/erpnext/accounts/doctype/tax_category/tax_category.js @@ -1,8 +1,6 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Tax Category', { - refresh: function(frm) { - - } +frappe.ui.form.on("Tax Category", { + refresh: function (frm) {}, }); diff --git a/erpnext/accounts/doctype/tax_rule/tax_rule.js b/erpnext/accounts/doctype/tax_rule/tax_rule.js index bc497163e8b0..b8c68e8d81d5 100644 --- a/erpnext/accounts/doctype/tax_rule/tax_rule.js +++ b/erpnext/accounts/doctype/tax_rule/tax_rule.js @@ -1,40 +1,40 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -frappe.ui.form.on("Tax Rule", "customer", function(frm) { - if(frm.doc.customer) { +frappe.ui.form.on("Tax Rule", "customer", function (frm) { + if (frm.doc.customer) { frappe.call({ - method:"erpnext.accounts.doctype.tax_rule.tax_rule.get_party_details", + method: "erpnext.accounts.doctype.tax_rule.tax_rule.get_party_details", args: { - "party": frm.doc.customer, - "party_type": "customer" + party: frm.doc.customer, + party_type: "customer", }, - callback: function(r) { - if(!r.exc) { - $.each(r.message, function(k, v) { + callback: function (r) { + if (!r.exc) { + $.each(r.message, function (k, v) { frm.set_value(k, v); }); } - } + }, }); } }); -frappe.ui.form.on("Tax Rule", "supplier", function(frm) { - if(frm.doc.supplier) { +frappe.ui.form.on("Tax Rule", "supplier", function (frm) { + if (frm.doc.supplier) { frappe.call({ - method:"erpnext.accounts.doctype.tax_rule.tax_rule.get_party_details", + method: "erpnext.accounts.doctype.tax_rule.tax_rule.get_party_details", args: { - "party": frm.doc.supplier, - "party_type": "supplier" + party: frm.doc.supplier, + party_type: "supplier", }, - callback: function(r) { - if(!r.exc) { - $.each(r.message, function(k, v) { + callback: function (r) { + if (!r.exc) { + $.each(r.message, function (k, v) { frm.set_value(k, v); }); } - } + }, }); } }); diff --git a/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.js b/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.js index 7b4797494655..4f4f32c47474 100644 --- a/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.js +++ b/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.js @@ -1,18 +1,18 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Tax Withholding Category', { - setup: function(frm) { - frm.set_query("account", "accounts", function(doc, cdt, cdn) { +frappe.ui.form.on("Tax Withholding Category", { + setup: function (frm) { + frm.set_query("account", "accounts", function (doc, cdt, cdn) { var child = locals[cdt][cdn]; if (child.company) { return { filters: { - 'company': child.company, - 'root_type': ['in', ['Asset', 'Liability']] - } + company: child.company, + root_type: ["in", ["Asset", "Liability"]], + }, }; } }); - } + }, }); diff --git a/erpnext/accounts/doctype/unreconcile_payment/unreconcile_payment.js b/erpnext/accounts/doctype/unreconcile_payment/unreconcile_payment.js index 70cefb13b572..63ae30d9d201 100644 --- a/erpnext/accounts/doctype/unreconcile_payment/unreconcile_payment.js +++ b/erpnext/accounts/doctype/unreconcile_payment/unreconcile_payment.js @@ -3,39 +3,36 @@ frappe.ui.form.on("Unreconcile Payment", { refresh(frm) { - frm.set_query("voucher_type", function() { + frm.set_query("voucher_type", function () { return { filters: { - name: ["in", ["Payment Entry", "Journal Entry"]] - } - } + name: ["in", ["Payment Entry", "Journal Entry"]], + }, + }; }); - - frm.set_query("voucher_no", function(doc) { + frm.set_query("voucher_no", function (doc) { return { filters: { company: doc.company, - docstatus: 1 - } - } + docstatus: 1, + }, + }; }); - }, - get_allocations: function(frm) { + get_allocations: function (frm) { frm.clear_table("allocations"); frappe.call({ method: "get_allocations_from_payment", doc: frm.doc, - callback: function(r) { + callback: function (r) { if (r.message) { - r.message.forEach(x => { - frm.add_child("allocations", x) - }) + r.message.forEach((x) => { + frm.add_child("allocations", x); + }); frm.refresh_fields(); } - } - }) - - } + }, + }); + }, }); diff --git a/erpnext/accounts/report/account_balance/account_balance.js b/erpnext/accounts/report/account_balance/account_balance.js index bb66951cdcda..52775739b8fc 100644 --- a/erpnext/accounts/report/account_balance/account_balance.js +++ b/erpnext/accounts/report/account_balance/account_balance.js @@ -3,31 +3,31 @@ /* eslint-disable */ frappe.query_reports["Account Balance"] = { - "filters": [ + filters: [ { - fieldname:"company", + fieldname: "company", label: __("Company"), fieldtype: "Link", options: "Company", - default: frappe.defaults.get_user_default("Company") + default: frappe.defaults.get_user_default("Company"), }, { - fieldname:"report_date", + fieldname: "report_date", label: __("Date"), fieldtype: "Date", default: frappe.datetime.get_today(), - reqd: 1 + reqd: 1, }, { fieldname: "root_type", label: __("Root Type"), fieldtype: "Select", options: [ - { "value": "Asset", "label": __("Asset") }, - { "value": "Liability", "label": __("Liability") }, - { "value": "Income", "label": __("Income") }, - { "value": "Expense", "label": __("Expense") }, - { "value": "Equity", "label": __("Equity") } + { value: "Asset", label: __("Asset") }, + { value: "Liability", label: __("Liability") }, + { value: "Income", label: __("Income") }, + { value: "Expense", label: __("Expense") }, + { value: "Equity", label: __("Equity") }, ], }, { @@ -35,30 +35,32 @@ frappe.query_reports["Account Balance"] = { label: __("Account Type"), fieldtype: "Select", options: [ - { "value": "Accumulated Depreciation", "label": __("Accumulated Depreciation") }, - { "value": "Asset Received But Not Billed", "label": __("Asset Received But Not Billed") }, - { "value": "Bank", "label": __("Bank") }, - { "value": "Cash", "label": __("Cash") }, - { "value": "Chargeble", "label": __("Chargeble") }, - { "value": "Capital Work in Progress", "label": __("Capital Work in Progress") }, - { "value": "Cost of Goods Sold", "label": __("Cost of Goods Sold") }, - { "value": "Depreciation", "label": __("Depreciation") }, - { "value": "Equity", "label": __("Equity") }, - { "value": "Expense Account", "label": __("Expense Account") }, - { "value": "Expenses Included In Asset Valuation", "label": __("Expenses Included In Asset Valuation") }, - { "value": "Expenses Included In Valuation", "label": __("Expenses Included In Valuation") }, - { "value": "Fixed Asset", "label": __("Fixed Asset") }, - { "value": "Income Account", "label": __("Income Account") }, - { "value": "Payable", "label": __("Payable") }, - { "value": "Receivable", "label": __("Receivable") }, - { "value": "Round Off", "label": __("Round Off") }, - { "value": "Stock", "label": __("Stock") }, - { "value": "Stock Adjustment", "label": __("Stock Adjustment") }, - { "value": "Stock Received But Not Billed", "label": __("Stock Received But Not Billed") }, - { "value": "Tax", "label": __("Tax") }, - { "value": "Temporary", "label": __("Temporary") }, + { value: "Accumulated Depreciation", label: __("Accumulated Depreciation") }, + { value: "Asset Received But Not Billed", label: __("Asset Received But Not Billed") }, + { value: "Bank", label: __("Bank") }, + { value: "Cash", label: __("Cash") }, + { value: "Chargeble", label: __("Chargeble") }, + { value: "Capital Work in Progress", label: __("Capital Work in Progress") }, + { value: "Cost of Goods Sold", label: __("Cost of Goods Sold") }, + { value: "Depreciation", label: __("Depreciation") }, + { value: "Equity", label: __("Equity") }, + { value: "Expense Account", label: __("Expense Account") }, + { + value: "Expenses Included In Asset Valuation", + label: __("Expenses Included In Asset Valuation"), + }, + { value: "Expenses Included In Valuation", label: __("Expenses Included In Valuation") }, + { value: "Fixed Asset", label: __("Fixed Asset") }, + { value: "Income Account", label: __("Income Account") }, + { value: "Payable", label: __("Payable") }, + { value: "Receivable", label: __("Receivable") }, + { value: "Round Off", label: __("Round Off") }, + { value: "Stock", label: __("Stock") }, + { value: "Stock Adjustment", label: __("Stock Adjustment") }, + { value: "Stock Received But Not Billed", label: __("Stock Received But Not Billed") }, + { value: "Tax", label: __("Tax") }, + { value: "Temporary", label: __("Temporary") }, ], }, - - ] -} + ], +}; diff --git a/erpnext/accounts/report/accounts_payable/accounts_payable.js b/erpnext/accounts/report/accounts_payable/accounts_payable.js index dc2e8a8518ba..61a3a96d5fe6 100644 --- a/erpnext/accounts/report/accounts_payable/accounts_payable.js +++ b/erpnext/accounts/report/accounts_payable/accounts_payable.js @@ -2,193 +2,194 @@ // License: GNU General Public License v3. See license.txt frappe.query_reports["Accounts Payable"] = { - "filters": [ + filters: [ { - "fieldname": "company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "reqd": 1, - "default": frappe.defaults.get_user_default("Company") + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + reqd: 1, + default: frappe.defaults.get_user_default("Company"), }, { - "fieldname": "report_date", - "label": __("Posting Date"), - "fieldtype": "Date", - "default": frappe.datetime.get_today() + fieldname: "report_date", + label: __("Posting Date"), + fieldtype: "Date", + default: frappe.datetime.get_today(), }, { - "fieldname": "finance_book", - "label": __("Finance Book"), - "fieldtype": "Link", - "options": "Finance Book" + fieldname: "finance_book", + label: __("Finance Book"), + fieldtype: "Link", + options: "Finance Book", }, { - "fieldname": "cost_center", - "label": __("Cost Center"), - "fieldtype": "Link", - "options": "Cost Center", + fieldname: "cost_center", + label: __("Cost Center"), + fieldtype: "Link", + options: "Cost Center", get_query: () => { - var company = frappe.query_report.get_filter_value('company'); + var company = frappe.query_report.get_filter_value("company"); return { filters: { - 'company': company - } - } - } + company: company, + }, + }; + }, }, { - "fieldname": "party_account", - "label": __("Payable Account"), - "fieldtype": "Link", - "options": "Account", + fieldname: "party_account", + label: __("Payable Account"), + fieldtype: "Link", + options: "Account", get_query: () => { - var company = frappe.query_report.get_filter_value('company'); + var company = frappe.query_report.get_filter_value("company"); return { filters: { - 'company': company, - 'account_type': 'Payable', - 'is_group': 0 - } + company: company, + account_type: "Payable", + is_group: 0, + }, }; - } + }, }, { - "fieldname": "ageing_based_on", - "label": __("Ageing Based On"), - "fieldtype": "Select", - "options": 'Posting Date\nDue Date\nSupplier Invoice Date', - "default": "Due Date" + fieldname: "ageing_based_on", + label: __("Ageing Based On"), + fieldtype: "Select", + options: "Posting Date\nDue Date\nSupplier Invoice Date", + default: "Due Date", }, { - "fieldname": "range1", - "label": __("Ageing Range 1"), - "fieldtype": "Int", - "default": "30", - "reqd": 1 + fieldname: "range1", + label: __("Ageing Range 1"), + fieldtype: "Int", + default: "30", + reqd: 1, }, { - "fieldname": "range2", - "label": __("Ageing Range 2"), - "fieldtype": "Int", - "default": "60", - "reqd": 1 + fieldname: "range2", + label: __("Ageing Range 2"), + fieldtype: "Int", + default: "60", + reqd: 1, }, { - "fieldname": "range3", - "label": __("Ageing Range 3"), - "fieldtype": "Int", - "default": "90", - "reqd": 1 + fieldname: "range3", + label: __("Ageing Range 3"), + fieldtype: "Int", + default: "90", + reqd: 1, }, { - "fieldname": "range4", - "label": __("Ageing Range 4"), - "fieldtype": "Int", - "default": "120", - "reqd": 1 + fieldname: "range4", + label: __("Ageing Range 4"), + fieldtype: "Int", + default: "120", + reqd: 1, }, { - "fieldname": "payment_terms_template", - "label": __("Payment Terms Template"), - "fieldtype": "Link", - "options": "Payment Terms Template" + fieldname: "payment_terms_template", + label: __("Payment Terms Template"), + fieldtype: "Link", + options: "Payment Terms Template", }, { - "fieldname":"party_type", - "label": __("Party Type"), - "fieldtype": "Autocomplete", + fieldname: "party_type", + label: __("Party Type"), + fieldtype: "Autocomplete", options: get_party_type_options(), - on_change: function() { - frappe.query_report.set_filter_value('party', ""); - frappe.query_report.toggle_filter_display('supplier_group', frappe.query_report.get_filter_value('party_type') !== "Supplier"); - } + on_change: function () { + frappe.query_report.set_filter_value("party", ""); + frappe.query_report.toggle_filter_display( + "supplier_group", + frappe.query_report.get_filter_value("party_type") !== "Supplier" + ); + }, }, { - "fieldname":"party", - "label": __("Party"), - "fieldtype": "MultiSelectList", - get_data: function(txt) { + fieldname: "party", + label: __("Party"), + fieldtype: "MultiSelectList", + get_data: function (txt) { if (!frappe.query_report.filters) return; - let party_type = frappe.query_report.get_filter_value('party_type'); + let party_type = frappe.query_report.get_filter_value("party_type"); if (!party_type) return; return frappe.db.get_link_options(party_type, txt); }, }, { - "fieldname": "supplier_group", - "label": __("Supplier Group"), - "fieldtype": "Link", - "options": "Supplier Group", - "hidden": 1 + fieldname: "supplier_group", + label: __("Supplier Group"), + fieldtype: "Link", + options: "Supplier Group", + hidden: 1, }, { - "fieldname": "group_by_party", - "label": __("Group By Supplier"), - "fieldtype": "Check" + fieldname: "group_by_party", + label: __("Group By Supplier"), + fieldtype: "Check", }, { - "fieldname": "based_on_payment_terms", - "label": __("Based On Payment Terms"), - "fieldtype": "Check", + fieldname: "based_on_payment_terms", + label: __("Based On Payment Terms"), + fieldtype: "Check", }, { - "fieldname": "show_remarks", - "label": __("Show Remarks"), - "fieldtype": "Check", + fieldname: "show_remarks", + label: __("Show Remarks"), + fieldtype: "Check", }, { - "fieldname": "show_future_payments", - "label": __("Show Future Payments"), - "fieldtype": "Check", + fieldname: "show_future_payments", + label: __("Show Future Payments"), + fieldtype: "Check", }, { - "fieldname": "for_revaluation_journals", - "label": __("Revaluation Journals"), - "fieldtype": "Check", + fieldname: "for_revaluation_journals", + label: __("Revaluation Journals"), + fieldtype: "Check", }, { - "fieldname": "in_party_currency", - "label": __("In Party Currency"), - "fieldtype": "Check", + fieldname: "in_party_currency", + label: __("In Party Currency"), + fieldtype: "Check", }, { - "fieldname": "ignore_accounts", - "label": __("Group by Voucher"), - "fieldtype": "Check", + fieldname: "ignore_accounts", + label: __("Group by Voucher"), + fieldtype: "Check", }, - ], - "formatter": function(value, row, column, data, default_formatter) { + formatter: function (value, row, column, data, default_formatter) { value = default_formatter(value, row, column, data); if (data && data.bold) { value = value.bold(); - } return value; }, - onload: function(report) { - report.page.add_inner_button(__("Accounts Payable Summary"), function() { + onload: function (report) { + report.page.add_inner_button(__("Accounts Payable Summary"), function () { var filters = report.get_values(); - frappe.set_route('query-report', 'Accounts Payable Summary', {company: filters.company}); + frappe.set_route("query-report", "Accounts Payable Summary", { company: filters.company }); }); - } -} + }, +}; -erpnext.utils.add_dimensions('Accounts Payable', 9); +erpnext.utils.add_dimensions("Accounts Payable", 9); function get_party_type_options() { let options = []; - frappe.db.get_list( - "Party Type", {filters:{"account_type": "Payable"}, fields:['name']} - ).then((res) => { - res.forEach((party_type) => { - options.push(party_type.name); + frappe.db + .get_list("Party Type", { filters: { account_type: "Payable" }, fields: ["name"] }) + .then((res) => { + res.forEach((party_type) => { + options.push(party_type.name); + }); }); - }); return options; } diff --git a/erpnext/accounts/report/accounts_payable_summary/accounts_payable_summary.js b/erpnext/accounts/report/accounts_payable_summary/accounts_payable_summary.js index 0f206b1cf421..92ea9e8f598f 100644 --- a/erpnext/accounts/report/accounts_payable_summary/accounts_payable_summary.js +++ b/erpnext/accounts/report/accounts_payable_summary/accounts_payable_summary.js @@ -2,140 +2,143 @@ // License: GNU General Public License v3. See license.txt frappe.query_reports["Accounts Payable Summary"] = { - "filters": [ + filters: [ { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_user_default("Company") + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), }, { - "fieldname":"report_date", - "label": __("Posting Date"), - "fieldtype": "Date", - "default": frappe.datetime.get_today() + fieldname: "report_date", + label: __("Posting Date"), + fieldtype: "Date", + default: frappe.datetime.get_today(), }, { - "fieldname":"ageing_based_on", - "label": __("Ageing Based On"), - "fieldtype": "Select", - "options": 'Posting Date\nDue Date', - "default": "Due Date" + fieldname: "ageing_based_on", + label: __("Ageing Based On"), + fieldtype: "Select", + options: "Posting Date\nDue Date", + default: "Due Date", }, { - "fieldname":"range1", - "label": __("Ageing Range 1"), - "fieldtype": "Int", - "default": "30", - "reqd": 1 + fieldname: "range1", + label: __("Ageing Range 1"), + fieldtype: "Int", + default: "30", + reqd: 1, }, { - "fieldname":"range2", - "label": __("Ageing Range 2"), - "fieldtype": "Int", - "default": "60", - "reqd": 1 + fieldname: "range2", + label: __("Ageing Range 2"), + fieldtype: "Int", + default: "60", + reqd: 1, }, { - "fieldname":"range3", - "label": __("Ageing Range 3"), - "fieldtype": "Int", - "default": "90", - "reqd": 1 + fieldname: "range3", + label: __("Ageing Range 3"), + fieldtype: "Int", + default: "90", + reqd: 1, }, { - "fieldname":"range4", - "label": __("Ageing Range 4"), - "fieldtype": "Int", - "default": "120", - "reqd": 1 + fieldname: "range4", + label: __("Ageing Range 4"), + fieldtype: "Int", + default: "120", + reqd: 1, }, { - "fieldname":"finance_book", - "label": __("Finance Book"), - "fieldtype": "Link", - "options": "Finance Book" + fieldname: "finance_book", + label: __("Finance Book"), + fieldtype: "Link", + options: "Finance Book", }, { - "fieldname":"cost_center", - "label": __("Cost Center"), - "fieldtype": "Link", - "options": "Cost Center", + fieldname: "cost_center", + label: __("Cost Center"), + fieldtype: "Link", + options: "Cost Center", get_query: () => { - var company = frappe.query_report.get_filter_value('company'); + var company = frappe.query_report.get_filter_value("company"); return { filters: { - 'company': company - } - } - } + company: company, + }, + }; + }, }, { - "fieldname":"party_type", - "label": __("Party Type"), - "fieldtype": "Autocomplete", + fieldname: "party_type", + label: __("Party Type"), + fieldtype: "Autocomplete", options: get_party_type_options(), - on_change: function() { - frappe.query_report.set_filter_value('party', ""); - frappe.query_report.toggle_filter_display('supplier_group', frappe.query_report.get_filter_value('party_type') !== "Supplier"); - } + on_change: function () { + frappe.query_report.set_filter_value("party", ""); + frappe.query_report.toggle_filter_display( + "supplier_group", + frappe.query_report.get_filter_value("party_type") !== "Supplier" + ); + }, }, { - "fieldname":"party", - "label": __("Party"), - "fieldtype": "MultiSelectList", - get_data: function(txt) { + fieldname: "party", + label: __("Party"), + fieldtype: "MultiSelectList", + get_data: function (txt) { if (!frappe.query_report.filters) return; - let party_type = frappe.query_report.get_filter_value('party_type'); + let party_type = frappe.query_report.get_filter_value("party_type"); if (!party_type) return; return frappe.db.get_link_options(party_type, txt); }, }, { - "fieldname":"payment_terms_template", - "label": __("Payment Terms Template"), - "fieldtype": "Link", - "options": "Payment Terms Template" + fieldname: "payment_terms_template", + label: __("Payment Terms Template"), + fieldtype: "Link", + options: "Payment Terms Template", }, { - "fieldname":"supplier_group", - "label": __("Supplier Group"), - "fieldtype": "Link", - "options": "Supplier Group" + fieldname: "supplier_group", + label: __("Supplier Group"), + fieldtype: "Link", + options: "Supplier Group", }, { - "fieldname":"based_on_payment_terms", - "label": __("Based On Payment Terms"), - "fieldtype": "Check", + fieldname: "based_on_payment_terms", + label: __("Based On Payment Terms"), + fieldtype: "Check", }, { - "fieldname": "for_revaluation_journals", - "label": __("Revaluation Journals"), - "fieldtype": "Check", - } + fieldname: "for_revaluation_journals", + label: __("Revaluation Journals"), + fieldtype: "Check", + }, ], - onload: function(report) { - report.page.add_inner_button(__("Accounts Payable"), function() { + onload: function (report) { + report.page.add_inner_button(__("Accounts Payable"), function () { var filters = report.get_values(); - frappe.set_route('query-report', 'Accounts Payable', {company: filters.company}); + frappe.set_route("query-report", "Accounts Payable", { company: filters.company }); }); - } -} + }, +}; -erpnext.utils.add_dimensions('Accounts Payable Summary', 9); +erpnext.utils.add_dimensions("Accounts Payable Summary", 9); function get_party_type_options() { let options = []; - frappe.db.get_list( - "Party Type", {filters:{"account_type": "Payable"}, fields:['name']} - ).then((res) => { - res.forEach((party_type) => { - options.push(party_type.name); + frappe.db + .get_list("Party Type", { filters: { account_type: "Payable" }, fields: ["name"] }) + .then((res) => { + res.forEach((party_type) => { + options.push(party_type.name); + }); }); - }); return options; -} \ No newline at end of file +} diff --git a/erpnext/accounts/report/accounts_receivable/accounts_receivable.js b/erpnext/accounts/report/accounts_receivable/accounts_receivable.js index 28aa7bf9ecf7..7e4563ee85e0 100644 --- a/erpnext/accounts/report/accounts_receivable/accounts_receivable.js +++ b/erpnext/accounts/report/accounts_receivable/accounts_receivable.js @@ -4,224 +4,224 @@ frappe.provide("erpnext.utils"); frappe.query_reports["Accounts Receivable"] = { - "filters": [ + filters: [ { - "fieldname": "company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "reqd": 1, - "default": frappe.defaults.get_user_default("Company") + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + reqd: 1, + default: frappe.defaults.get_user_default("Company"), }, { - "fieldname": "report_date", - "label": __("Posting Date"), - "fieldtype": "Date", - "default": frappe.datetime.get_today() + fieldname: "report_date", + label: __("Posting Date"), + fieldtype: "Date", + default: frappe.datetime.get_today(), }, { - "fieldname": "finance_book", - "label": __("Finance Book"), - "fieldtype": "Link", - "options": "Finance Book" + fieldname: "finance_book", + label: __("Finance Book"), + fieldtype: "Link", + options: "Finance Book", }, { - "fieldname": "cost_center", - "label": __("Cost Center"), - "fieldtype": "Link", - "options": "Cost Center", + fieldname: "cost_center", + label: __("Cost Center"), + fieldtype: "Link", + options: "Cost Center", get_query: () => { - var company = frappe.query_report.get_filter_value('company'); + var company = frappe.query_report.get_filter_value("company"); return { filters: { - 'company': company - } + company: company, + }, }; - } + }, }, { - "fieldname":"party_type", - "label": __("Party Type"), - "fieldtype": "Autocomplete", + fieldname: "party_type", + label: __("Party Type"), + fieldtype: "Autocomplete", options: get_party_type_options(), - on_change: function() { - frappe.query_report.set_filter_value('party', ""); - frappe.query_report.toggle_filter_display('customer_group', frappe.query_report.get_filter_value('party_type') !== "Customer"); - } + on_change: function () { + frappe.query_report.set_filter_value("party", ""); + frappe.query_report.toggle_filter_display( + "customer_group", + frappe.query_report.get_filter_value("party_type") !== "Customer" + ); + }, }, { - "fieldname":"party", - "label": __("Party"), - "fieldtype": "MultiSelectList", - get_data: function(txt) { + fieldname: "party", + label: __("Party"), + fieldtype: "MultiSelectList", + get_data: function (txt) { if (!frappe.query_report.filters) return; - let party_type = frappe.query_report.get_filter_value('party_type'); + let party_type = frappe.query_report.get_filter_value("party_type"); if (!party_type) return; return frappe.db.get_link_options(party_type, txt); }, }, { - "fieldname": "party_account", - "label": __("Receivable Account"), - "fieldtype": "Link", - "options": "Account", + fieldname: "party_account", + label: __("Receivable Account"), + fieldtype: "Link", + options: "Account", get_query: () => { - var company = frappe.query_report.get_filter_value('company'); + var company = frappe.query_report.get_filter_value("company"); return { filters: { - 'company': company, - 'account_type': 'Receivable', - 'is_group': 0 - } + company: company, + account_type: "Receivable", + is_group: 0, + }, }; - } + }, }, { - "fieldname": "ageing_based_on", - "label": __("Ageing Based On"), - "fieldtype": "Select", - "options": 'Posting Date\nDue Date', - "default": "Due Date" + fieldname: "ageing_based_on", + label: __("Ageing Based On"), + fieldtype: "Select", + options: "Posting Date\nDue Date", + default: "Due Date", }, { - "fieldname": "range1", - "label": __("Ageing Range 1"), - "fieldtype": "Int", - "default": "30", - "reqd": 1 + fieldname: "range1", + label: __("Ageing Range 1"), + fieldtype: "Int", + default: "30", + reqd: 1, }, { - "fieldname": "range2", - "label": __("Ageing Range 2"), - "fieldtype": "Int", - "default": "60", - "reqd": 1 + fieldname: "range2", + label: __("Ageing Range 2"), + fieldtype: "Int", + default: "60", + reqd: 1, }, { - "fieldname": "range3", - "label": __("Ageing Range 3"), - "fieldtype": "Int", - "default": "90", - "reqd": 1 + fieldname: "range3", + label: __("Ageing Range 3"), + fieldtype: "Int", + default: "90", + reqd: 1, }, { - "fieldname": "range4", - "label": __("Ageing Range 4"), - "fieldtype": "Int", - "default": "120", - "reqd": 1 + fieldname: "range4", + label: __("Ageing Range 4"), + fieldtype: "Int", + default: "120", + reqd: 1, }, { - "fieldname":"customer_group", - "label": __("Customer Group"), - "fieldtype": "MultiSelectList", - "options": "Customer Group", - get_data: function(txt) { - return frappe.db.get_link_options('Customer Group', txt); - } + fieldname: "customer_group", + label: __("Customer Group"), + fieldtype: "MultiSelectList", + options: "Customer Group", + get_data: function (txt) { + return frappe.db.get_link_options("Customer Group", txt); + }, }, { - "fieldname": "payment_terms_template", - "label": __("Payment Terms Template"), - "fieldtype": "Link", - "options": "Payment Terms Template" + fieldname: "payment_terms_template", + label: __("Payment Terms Template"), + fieldtype: "Link", + options: "Payment Terms Template", }, { - "fieldname": "sales_partner", - "label": __("Sales Partner"), - "fieldtype": "Link", - "options": "Sales Partner" + fieldname: "sales_partner", + label: __("Sales Partner"), + fieldtype: "Link", + options: "Sales Partner", }, { - "fieldname": "sales_person", - "label": __("Sales Person"), - "fieldtype": "Link", - "options": "Sales Person" + fieldname: "sales_person", + label: __("Sales Person"), + fieldtype: "Link", + options: "Sales Person", }, { - "fieldname": "territory", - "label": __("Territory"), - "fieldtype": "Link", - "options": "Territory" + fieldname: "territory", + label: __("Territory"), + fieldtype: "Link", + options: "Territory", }, { - "fieldname": "group_by_party", - "label": __("Group By Customer"), - "fieldtype": "Check" + fieldname: "group_by_party", + label: __("Group By Customer"), + fieldtype: "Check", }, { - "fieldname": "based_on_payment_terms", - "label": __("Based On Payment Terms"), - "fieldtype": "Check", + fieldname: "based_on_payment_terms", + label: __("Based On Payment Terms"), + fieldtype: "Check", }, { - "fieldname": "show_future_payments", - "label": __("Show Future Payments"), - "fieldtype": "Check", + fieldname: "show_future_payments", + label: __("Show Future Payments"), + fieldtype: "Check", }, { - "fieldname": "show_delivery_notes", - "label": __("Show Linked Delivery Notes"), - "fieldtype": "Check", + fieldname: "show_delivery_notes", + label: __("Show Linked Delivery Notes"), + fieldtype: "Check", }, { - "fieldname": "show_sales_person", - "label": __("Show Sales Person"), - "fieldtype": "Check", + fieldname: "show_sales_person", + label: __("Show Sales Person"), + fieldtype: "Check", }, { - "fieldname": "show_remarks", - "label": __("Show Remarks"), - "fieldtype": "Check", + fieldname: "show_remarks", + label: __("Show Remarks"), + fieldtype: "Check", }, { - "fieldname": "for_revaluation_journals", - "label": __("Revaluation Journals"), - "fieldtype": "Check", + fieldname: "for_revaluation_journals", + label: __("Revaluation Journals"), + fieldtype: "Check", }, { - "fieldname": "in_party_currency", - "label": __("In Party Currency"), - "fieldtype": "Check", + fieldname: "in_party_currency", + label: __("In Party Currency"), + fieldtype: "Check", }, { - "fieldname": "ignore_accounts", - "label": __("Group by Voucher"), - "fieldtype": "Check", - } - + fieldname: "ignore_accounts", + label: __("Group by Voucher"), + fieldtype: "Check", + }, ], - "formatter": function(value, row, column, data, default_formatter) { + formatter: function (value, row, column, data, default_formatter) { value = default_formatter(value, row, column, data); if (data && data.bold) { value = value.bold(); - } return value; }, - onload: function(report) { - report.page.add_inner_button(__("Accounts Receivable Summary"), function() { + onload: function (report) { + report.page.add_inner_button(__("Accounts Receivable Summary"), function () { var filters = report.get_values(); - frappe.set_route('query-report', 'Accounts Receivable Summary', {company: filters.company}); + frappe.set_route("query-report", "Accounts Receivable Summary", { company: filters.company }); }); - } -} - -erpnext.utils.add_dimensions('Accounts Receivable', 9); + }, +}; +erpnext.utils.add_dimensions("Accounts Receivable", 9); function get_party_type_options() { let options = []; - frappe.db.get_list( - "Party Type", {filters:{"account_type": "Receivable"}, fields:['name']} - ).then((res) => { - res.forEach((party_type) => { - options.push(party_type.name); + frappe.db + .get_list("Party Type", { filters: { account_type: "Receivable" }, fields: ["name"] }) + .then((res) => { + res.forEach((party_type) => { + options.push(party_type.name); + }); }); - }); return options; } diff --git a/erpnext/accounts/report/accounts_receivable_summary/accounts_receivable_summary.js b/erpnext/accounts/report/accounts_receivable_summary/accounts_receivable_summary.js index 2f6d2582b338..964abc23747d 100644 --- a/erpnext/accounts/report/accounts_receivable_summary/accounts_receivable_summary.js +++ b/erpnext/accounts/report/accounts_receivable_summary/accounts_receivable_summary.js @@ -2,168 +2,171 @@ // License: GNU General Public License v3. See license.txt frappe.query_reports["Accounts Receivable Summary"] = { - "filters": [ + filters: [ { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_user_default("Company") + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), }, { - "fieldname":"report_date", - "label": __("Posting Date"), - "fieldtype": "Date", - "default": frappe.datetime.get_today() + fieldname: "report_date", + label: __("Posting Date"), + fieldtype: "Date", + default: frappe.datetime.get_today(), }, { - "fieldname":"ageing_based_on", - "label": __("Ageing Based On"), - "fieldtype": "Select", - "options": 'Posting Date\nDue Date', - "default": "Due Date" + fieldname: "ageing_based_on", + label: __("Ageing Based On"), + fieldtype: "Select", + options: "Posting Date\nDue Date", + default: "Due Date", }, { - "fieldname":"range1", - "label": __("Ageing Range 1"), - "fieldtype": "Int", - "default": "30", - "reqd": 1 + fieldname: "range1", + label: __("Ageing Range 1"), + fieldtype: "Int", + default: "30", + reqd: 1, }, { - "fieldname":"range2", - "label": __("Ageing Range 2"), - "fieldtype": "Int", - "default": "60", - "reqd": 1 + fieldname: "range2", + label: __("Ageing Range 2"), + fieldtype: "Int", + default: "60", + reqd: 1, }, { - "fieldname":"range3", - "label": __("Ageing Range 3"), - "fieldtype": "Int", - "default": "90", - "reqd": 1 + fieldname: "range3", + label: __("Ageing Range 3"), + fieldtype: "Int", + default: "90", + reqd: 1, }, { - "fieldname":"range4", - "label": __("Ageing Range 4"), - "fieldtype": "Int", - "default": "120", - "reqd": 1 + fieldname: "range4", + label: __("Ageing Range 4"), + fieldtype: "Int", + default: "120", + reqd: 1, }, { - "fieldname":"finance_book", - "label": __("Finance Book"), - "fieldtype": "Link", - "options": "Finance Book" + fieldname: "finance_book", + label: __("Finance Book"), + fieldtype: "Link", + options: "Finance Book", }, { - "fieldname":"cost_center", - "label": __("Cost Center"), - "fieldtype": "Link", - "options": "Cost Center", + fieldname: "cost_center", + label: __("Cost Center"), + fieldtype: "Link", + options: "Cost Center", get_query: () => { - var company = frappe.query_report.get_filter_value('company'); + var company = frappe.query_report.get_filter_value("company"); return { filters: { - 'company': company - } - } - } + company: company, + }, + }; + }, }, { - "fieldname":"party_type", - "label": __("Party Type"), - "fieldtype": "Autocomplete", + fieldname: "party_type", + label: __("Party Type"), + fieldtype: "Autocomplete", options: get_party_type_options(), - on_change: function() { - frappe.query_report.set_filter_value('party', ""); - frappe.query_report.toggle_filter_display('customer_group', frappe.query_report.get_filter_value('party_type') !== "Customer"); - } + on_change: function () { + frappe.query_report.set_filter_value("party", ""); + frappe.query_report.toggle_filter_display( + "customer_group", + frappe.query_report.get_filter_value("party_type") !== "Customer" + ); + }, }, { - "fieldname":"party", - "label": __("Party"), - "fieldtype": "MultiSelectList", - get_data: function(txt) { + fieldname: "party", + label: __("Party"), + fieldtype: "MultiSelectList", + get_data: function (txt) { if (!frappe.query_report.filters) return; - let party_type = frappe.query_report.get_filter_value('party_type'); + let party_type = frappe.query_report.get_filter_value("party_type"); if (!party_type) return; return frappe.db.get_link_options(party_type, txt); }, }, { - "fieldname":"customer_group", - "label": __("Customer Group"), - "fieldtype": "Link", - "options": "Customer Group" + fieldname: "customer_group", + label: __("Customer Group"), + fieldtype: "Link", + options: "Customer Group", }, { - "fieldname":"payment_terms_template", - "label": __("Payment Terms Template"), - "fieldtype": "Link", - "options": "Payment Terms Template" + fieldname: "payment_terms_template", + label: __("Payment Terms Template"), + fieldtype: "Link", + options: "Payment Terms Template", }, { - "fieldname":"territory", - "label": __("Territory"), - "fieldtype": "Link", - "options": "Territory" + fieldname: "territory", + label: __("Territory"), + fieldtype: "Link", + options: "Territory", }, { - "fieldname":"sales_partner", - "label": __("Sales Partner"), - "fieldtype": "Link", - "options": "Sales Partner" + fieldname: "sales_partner", + label: __("Sales Partner"), + fieldtype: "Link", + options: "Sales Partner", }, { - "fieldname":"sales_person", - "label": __("Sales Person"), - "fieldtype": "Link", - "options": "Sales Person" + fieldname: "sales_person", + label: __("Sales Person"), + fieldtype: "Link", + options: "Sales Person", }, { - "fieldname":"based_on_payment_terms", - "label": __("Based On Payment Terms"), - "fieldtype": "Check", + fieldname: "based_on_payment_terms", + label: __("Based On Payment Terms"), + fieldtype: "Check", }, { - "fieldname":"show_future_payments", - "label": __("Show Future Payments"), - "fieldtype": "Check", + fieldname: "show_future_payments", + label: __("Show Future Payments"), + fieldtype: "Check", }, { - "fieldname":"show_gl_balance", - "label": __("Show GL Balance"), - "fieldtype": "Check", + fieldname: "show_gl_balance", + label: __("Show GL Balance"), + fieldtype: "Check", }, { - "fieldname": "for_revaluation_journals", - "label": __("Revaluation Journals"), - "fieldtype": "Check", - } + fieldname: "for_revaluation_journals", + label: __("Revaluation Journals"), + fieldtype: "Check", + }, ], - onload: function(report) { - report.page.add_inner_button(__("Accounts Receivable"), function() { + onload: function (report) { + report.page.add_inner_button(__("Accounts Receivable"), function () { var filters = report.get_values(); - frappe.set_route('query-report', 'Accounts Receivable', { company: filters.company }); + frappe.set_route("query-report", "Accounts Receivable", { company: filters.company }); }); - } -} + }, +}; -erpnext.utils.add_dimensions('Accounts Receivable Summary', 9); +erpnext.utils.add_dimensions("Accounts Receivable Summary", 9); function get_party_type_options() { let options = []; - frappe.db.get_list( - "Party Type", {filters:{"account_type": "Receivable"}, fields:['name']} - ).then((res) => { - res.forEach((party_type) => { - options.push(party_type.name); + frappe.db + .get_list("Party Type", { filters: { account_type: "Receivable" }, fields: ["name"] }) + .then((res) => { + res.forEach((party_type) => { + options.push(party_type.name); + }); }); - }); return options; -} \ No newline at end of file +} diff --git a/erpnext/accounts/report/asset_depreciation_ledger/asset_depreciation_ledger.js b/erpnext/accounts/report/asset_depreciation_ledger/asset_depreciation_ledger.js index 12b94347e00f..db49ccb79a8d 100644 --- a/erpnext/accounts/report/asset_depreciation_ledger/asset_depreciation_ledger.js +++ b/erpnext/accounts/report/asset_depreciation_ledger/asset_depreciation_ledger.js @@ -2,58 +2,58 @@ // For license information, please see license.txt frappe.query_reports["Asset Depreciation Ledger"] = { - "filters": [ + filters: [ { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_user_default("Company"), - "reqd": 1 + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), + reqd: 1, }, { - "fieldname":"from_date", - "label": __("From Date"), - "fieldtype": "Date", - "default": frappe.datetime.add_months(frappe.datetime.get_today(), -1), - "reqd": 1 + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + default: frappe.datetime.add_months(frappe.datetime.get_today(), -1), + reqd: 1, }, { - "fieldname":"to_date", - "label": __("To Date"), - "fieldtype": "Date", - "default": frappe.datetime.get_today(), - "reqd": 1 + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + default: frappe.datetime.get_today(), + reqd: 1, }, { - "fieldname":"asset", - "label": __("Asset"), - "fieldtype": "Link", - "options": "Asset" + fieldname: "asset", + label: __("Asset"), + fieldtype: "Link", + options: "Asset", }, { - "fieldname":"asset_category", - "label": __("Asset Category"), - "fieldtype": "Link", - "options": "Asset Category" + fieldname: "asset_category", + label: __("Asset Category"), + fieldtype: "Link", + options: "Asset Category", }, { - "fieldname":"cost_center", - "label": __("Cost Center"), - "fieldtype": "Link", - "options": "Cost Center" + fieldname: "cost_center", + label: __("Cost Center"), + fieldtype: "Link", + options: "Cost Center", }, { - "fieldname":"finance_book", - "label": __("Finance Book"), - "fieldtype": "Link", - "options": "Finance Book" + fieldname: "finance_book", + label: __("Finance Book"), + fieldtype: "Link", + options: "Finance Book", }, { - "fieldname": "include_default_book_assets", - "label": __("Include Default FB Assets"), - "fieldtype": "Check", - "default": 1 + fieldname: "include_default_book_assets", + label: __("Include Default FB Assets"), + fieldtype: "Check", + default: 1, }, - ] -} + ], +}; diff --git a/erpnext/accounts/report/asset_depreciations_and_balances/asset_depreciations_and_balances.js b/erpnext/accounts/report/asset_depreciations_and_balances/asset_depreciations_and_balances.js index 1da35cd95bf8..215d431e786a 100644 --- a/erpnext/accounts/report/asset_depreciations_and_balances/asset_depreciations_and_balances.js +++ b/erpnext/accounts/report/asset_depreciations_and_balances/asset_depreciations_and_balances.js @@ -2,34 +2,34 @@ // For license information, please see license.txt frappe.query_reports["Asset Depreciations and Balances"] = { - "filters": [ + filters: [ { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_user_default("Company"), - "reqd": 1 + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), + reqd: 1, }, { - "fieldname":"from_date", - "label": __("From Date"), - "fieldtype": "Date", - "default": frappe.defaults.get_user_default("year_start_date"), - "reqd": 1 + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + default: frappe.defaults.get_user_default("year_start_date"), + reqd: 1, }, { - "fieldname":"to_date", - "label": __("To Date"), - "fieldtype": "Date", - "default": frappe.defaults.get_user_default("year_end_date"), - "reqd": 1 + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + default: frappe.defaults.get_user_default("year_end_date"), + reqd: 1, }, { - "fieldname":"asset_category", - "label": __("Asset Category"), - "fieldtype": "Link", - "options": "Asset Category" - } - ] -} + fieldname: "asset_category", + label: __("Asset Category"), + fieldtype: "Link", + options: "Asset Category", + }, + ], +}; diff --git a/erpnext/accounts/report/balance_sheet/balance_sheet.js b/erpnext/accounts/report/balance_sheet/balance_sheet.js index 57de73e72d06..605dff8b6087 100644 --- a/erpnext/accounts/report/balance_sheet/balance_sheet.js +++ b/erpnext/accounts/report/balance_sheet/balance_sheet.js @@ -1,35 +1,33 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -frappe.require("assets/erpnext/js/financial_statements.js", function() { +frappe.require("assets/erpnext/js/financial_statements.js", function () { frappe.query_reports["Balance Sheet"] = $.extend({}, erpnext.financial_statements); - erpnext.utils.add_dimensions('Balance Sheet', 10); + erpnext.utils.add_dimensions("Balance Sheet", 10); - frappe.query_reports["Balance Sheet"]["filters"].push( - { - "fieldname": "selected_view", - "label": __("Select View"), - "fieldtype": "Select", - "options": [ - { "value": "Report", "label": __("Report View") }, - { "value": "Growth", "label": __("Growth View") } - ], - "default": "Report", - "reqd": 1 - }, - ); frappe.query_reports["Balance Sheet"]["filters"].push({ - "fieldname": "accumulated_values", - "label": __("Accumulated Values"), - "fieldtype": "Check", - "default": 1 + fieldname: "selected_view", + label: __("Select View"), + fieldtype: "Select", + options: [ + { value: "Report", label: __("Report View") }, + { value: "Growth", label: __("Growth View") }, + ], + default: "Report", + reqd: 1, + }); + frappe.query_reports["Balance Sheet"]["filters"].push({ + fieldname: "accumulated_values", + label: __("Accumulated Values"), + fieldtype: "Check", + default: 1, }); frappe.query_reports["Balance Sheet"]["filters"].push({ - "fieldname": "include_default_book_entries", - "label": __("Include Default FB Entries"), - "fieldtype": "Check", - "default": 1 + fieldname: "include_default_book_entries", + label: __("Include Default FB Entries"), + fieldtype: "Check", + default: 1, }); }); diff --git a/erpnext/accounts/report/bank_clearance_summary/bank_clearance_summary.js b/erpnext/accounts/report/bank_clearance_summary/bank_clearance_summary.js index f0b6c6b20ac6..c15d43012dbe 100644 --- a/erpnext/accounts/report/bank_clearance_summary/bank_clearance_summary.js +++ b/erpnext/accounts/report/bank_clearance_summary/bank_clearance_summary.js @@ -2,37 +2,38 @@ // License: GNU General Public License v3. See license.txt frappe.query_reports["Bank Clearance Summary"] = { - "filters": [ + filters: [ { - "fieldname":"from_date", - "label": __("From Date"), - "fieldtype": "Date", - "default": frappe.defaults.get_user_default("year_start_date"), - "width": "80" + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + default: frappe.defaults.get_user_default("year_start_date"), + width: "80", }, { - "fieldname":"to_date", - "label": __("To Date"), - "fieldtype": "Date", - "default": frappe.datetime.get_today() + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + default: frappe.datetime.get_today(), }, { - "fieldname":"account", - "label": __("Bank Account"), - "fieldtype": "Link", - "options": "Account", - "reqd": 1, - "default": frappe.defaults.get_user_default("Company")? - locals[":Company"][frappe.defaults.get_user_default("Company")]["default_bank_account"]: "", - "get_query": function() { + fieldname: "account", + label: __("Bank Account"), + fieldtype: "Link", + options: "Account", + reqd: 1, + default: frappe.defaults.get_user_default("Company") + ? locals[":Company"][frappe.defaults.get_user_default("Company")]["default_bank_account"] + : "", + get_query: function () { return { - "query": "erpnext.controllers.queries.get_account_list", - "filters": [ - ['Account', 'account_type', 'in', 'Bank, Cash'], - ['Account', 'is_group', '=', 0], - ] - } - } + query: "erpnext.controllers.queries.get_account_list", + filters: [ + ["Account", "account_type", "in", "Bank, Cash"], + ["Account", "is_group", "=", 0], + ], + }; + }, }, - ] -} + ], +}; diff --git a/erpnext/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.js b/erpnext/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.js index 9bb6a14c6778..efcfa7a5ee59 100644 --- a/erpnext/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.js +++ b/erpnext/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.js @@ -2,47 +2,48 @@ // License: GNU General Public License v3. See license.txt frappe.query_reports["Bank Reconciliation Statement"] = { - "filters": [ + filters: [ { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "reqd": 1, - "default": frappe.defaults.get_user_default("Company") + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + reqd: 1, + default: frappe.defaults.get_user_default("Company"), }, { - "fieldname":"account", - "label": __("Bank Account"), - "fieldtype": "Link", - "options": "Account", - "default": frappe.defaults.get_user_default("Company")? - locals[":Company"][frappe.defaults.get_user_default("Company")]["default_bank_account"]: "", - "reqd": 1, - "get_query": function() { - var company = frappe.query_report.get_filter_value('company') + fieldname: "account", + label: __("Bank Account"), + fieldtype: "Link", + options: "Account", + default: frappe.defaults.get_user_default("Company") + ? locals[":Company"][frappe.defaults.get_user_default("Company")]["default_bank_account"] + : "", + reqd: 1, + get_query: function () { + var company = frappe.query_report.get_filter_value("company"); return { - "query": "erpnext.controllers.queries.get_account_list", - "filters": [ - ['Account', 'account_type', 'in', 'Bank, Cash'], - ['Account', 'is_group', '=', 0], - ['Account', 'disabled', '=', 0], - ['Account', 'company', '=', company], - ] - } - } + query: "erpnext.controllers.queries.get_account_list", + filters: [ + ["Account", "account_type", "in", "Bank, Cash"], + ["Account", "is_group", "=", 0], + ["Account", "disabled", "=", 0], + ["Account", "company", "=", company], + ], + }; + }, }, { - "fieldname":"report_date", - "label": __("Date"), - "fieldtype": "Date", - "default": frappe.datetime.get_today(), - "reqd": 1 + fieldname: "report_date", + label: __("Date"), + fieldtype: "Date", + default: frappe.datetime.get_today(), + reqd: 1, }, { - "fieldname":"include_pos_transactions", - "label": __("Include POS Transactions"), - "fieldtype": "Check" + fieldname: "include_pos_transactions", + label: __("Include POS Transactions"), + fieldtype: "Check", }, - ] -} + ], +}; diff --git a/erpnext/accounts/report/billed_items_to_be_received/billed_items_to_be_received.js b/erpnext/accounts/report/billed_items_to_be_received/billed_items_to_be_received.js index e1fccb6e720e..65c8e8222271 100644 --- a/erpnext/accounts/report/billed_items_to_be_received/billed_items_to_be_received.js +++ b/erpnext/accounts/report/billed_items_to_be_received/billed_items_to_be_received.js @@ -2,28 +2,28 @@ // For license information, please see license.txt /* eslint-disable */ -frappe.query_reports['Billed Items To Be Received'] = { - 'filters': [ +frappe.query_reports["Billed Items To Be Received"] = { + filters: [ { - 'label': __('Company'), - 'fieldname': 'company', - 'fieldtype': 'Link', - 'options': 'Company', - 'reqd': 1, - 'default': frappe.defaults.get_default('Company') + label: __("Company"), + fieldname: "company", + fieldtype: "Link", + options: "Company", + reqd: 1, + default: frappe.defaults.get_default("Company"), }, { - 'label': __('As on Date'), - 'fieldname': 'posting_date', - 'fieldtype': 'Date', - 'reqd': 1, - 'default': get_today() + label: __("As on Date"), + fieldname: "posting_date", + fieldtype: "Date", + reqd: 1, + default: get_today(), }, { - 'label': __('Purchase Invoice'), - 'fieldname': 'purchase_invoice', - 'fieldtype': 'Link', - 'options': 'Purchase Invoice' - } - ] + label: __("Purchase Invoice"), + fieldname: "purchase_invoice", + fieldtype: "Link", + options: "Purchase Invoice", + }, + ], }; diff --git a/erpnext/accounts/report/budget_variance_report/budget_variance_report.js b/erpnext/accounts/report/budget_variance_report/budget_variance_report.js index c9ddde9b5fbe..156ae8f2f2ae 100644 --- a/erpnext/accounts/report/budget_variance_report/budget_variance_report.js +++ b/erpnext/accounts/report/budget_variance_report/budget_variance_report.js @@ -2,37 +2,35 @@ // License: GNU General Public License v3. See license.txt frappe.query_reports["Budget Variance Report"] = { - "filters": get_filters(), - "formatter": function (value, row, column, data, default_formatter) { + filters: get_filters(), + formatter: function (value, row, column, data, default_formatter) { value = default_formatter(value, row, column, data); if (column.fieldname.includes(__("variance"))) { - if (data[column.fieldname] < 0) { value = "" + value + ""; - } - else if (data[column.fieldname] > 0) { + } else if (data[column.fieldname] > 0) { value = "" + value + ""; } } return value; - } -} + }, +}; function get_filters() { function get_dimensions() { let result = []; frappe.call({ method: "erpnext.accounts.doctype.accounting_dimension.accounting_dimension.get_dimensions", args: { - 'with_cost_center_and_project': true + with_cost_center_and_project: true, }, async: false, - callback: function(r) { - if(!r.exc) { - result = r.message[0].map(elem => elem.document_type); + callback: function (r) { + if (!r.exc) { + result = r.message[0].map((elem) => elem.document_type); } - } + }, }); return result; } @@ -46,7 +44,7 @@ function get_filters() { fieldtype: "Link", options: "Fiscal Year", default: frappe.sys_defaults.fiscal_year, - reqd: 1 + reqd: 1, }, { fieldname: "to_fiscal_year", @@ -54,20 +52,20 @@ function get_filters() { fieldtype: "Link", options: "Fiscal Year", default: frappe.sys_defaults.fiscal_year, - reqd: 1 + reqd: 1, }, { fieldname: "period", label: __("Period"), fieldtype: "Select", options: [ - { "value": "Monthly", "label": __("Monthly") }, - { "value": "Quarterly", "label": __("Quarterly") }, - { "value": "Half-Yearly", "label": __("Half-Yearly") }, - { "value": "Yearly", "label": __("Yearly") } + { value: "Monthly", label: __("Monthly") }, + { value: "Quarterly", label: __("Quarterly") }, + { value: "Half-Yearly", label: __("Half-Yearly") }, + { value: "Yearly", label: __("Yearly") }, ], default: "Yearly", - reqd: 1 + reqd: 1, }, { fieldname: "company", @@ -75,7 +73,7 @@ function get_filters() { fieldtype: "Link", options: "Company", default: frappe.defaults.get_user_default("Company"), - reqd: 1 + reqd: 1, }, { fieldname: "budget_against", @@ -84,32 +82,31 @@ function get_filters() { options: budget_against_options, default: "Cost Center", reqd: 1, - on_change: function() { + on_change: function () { frappe.query_report.set_filter_value("budget_against_filter", []); frappe.query_report.refresh(); - } + }, }, { - fieldname:"budget_against_filter", - label: __('Dimension Filter'), + fieldname: "budget_against_filter", + label: __("Dimension Filter"), fieldtype: "MultiSelectList", - get_data: function(txt) { + get_data: function (txt) { if (!frappe.query_report.filters) return; - let budget_against = frappe.query_report.get_filter_value('budget_against'); + let budget_against = frappe.query_report.get_filter_value("budget_against"); if (!budget_against) return; return frappe.db.get_link_options(budget_against, txt); - } + }, }, { - fieldname:"show_cumulative", + fieldname: "show_cumulative", label: __("Show Cumulative Amount"), fieldtype: "Check", default: 0, }, - ] + ]; return filters; } - diff --git a/erpnext/accounts/report/cash_flow/cash_flow.js b/erpnext/accounts/report/cash_flow/cash_flow.js index b9c62b528619..c3560c8d3f53 100644 --- a/erpnext/accounts/report/cash_flow/cash_flow.js +++ b/erpnext/accounts/report/cash_flow/cash_flow.js @@ -1,11 +1,10 @@ // Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.require("assets/erpnext/js/financial_statements.js", function() { - frappe.query_reports["Cash Flow"] = $.extend({}, - erpnext.financial_statements); +frappe.require("assets/erpnext/js/financial_statements.js", function () { + frappe.query_reports["Cash Flow"] = $.extend({}, erpnext.financial_statements); - erpnext.utils.add_dimensions('Cash Flow', 10); + erpnext.utils.add_dimensions("Cash Flow", 10); // The last item in the array is the definition for Presentation Currency // filter. It won't be used in cash flow for now so we pop it. Please take @@ -13,12 +12,10 @@ frappe.require("assets/erpnext/js/financial_statements.js", function() { frappe.query_reports["Cash Flow"]["filters"].splice(8, 1); - frappe.query_reports["Cash Flow"]["filters"].push( - { - "fieldname": "include_default_book_entries", - "label": __("Include Default FB Entries"), - "fieldtype": "Check", - "default": 1 - } - ); + frappe.query_reports["Cash Flow"]["filters"].push({ + fieldname: "include_default_book_entries", + label: __("Include Default FB Entries"), + fieldtype: "Check", + default: 1, + }); }); diff --git a/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.js b/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.js index cb1083b06c1b..f700cb7759d6 100644 --- a/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.js +++ b/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.js @@ -2,125 +2,153 @@ // For license information, please see license.txt /* eslint-disable */ -frappe.require("assets/erpnext/js/financial_statements.js", function() { +frappe.require("assets/erpnext/js/financial_statements.js", function () { frappe.query_reports["Consolidated Financial Statement"] = { - "filters": [ + filters: [ { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_user_default("Company"), - "reqd": 1 + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), + reqd: 1, }, { - "fieldname":"filter_based_on", - "label": __("Filter Based On"), - "fieldtype": "Select", - "options": ["Fiscal Year", "Date Range"], - "default": ["Fiscal Year"], - "reqd": 1, - on_change: function() { - let filter_based_on = frappe.query_report.get_filter_value('filter_based_on'); - frappe.query_report.toggle_filter_display('from_fiscal_year', filter_based_on === 'Date Range'); - frappe.query_report.toggle_filter_display('to_fiscal_year', filter_based_on === 'Date Range'); - frappe.query_report.toggle_filter_display('period_start_date', filter_based_on === 'Fiscal Year'); - frappe.query_report.toggle_filter_display('period_end_date', filter_based_on === 'Fiscal Year'); + fieldname: "filter_based_on", + label: __("Filter Based On"), + fieldtype: "Select", + options: ["Fiscal Year", "Date Range"], + default: ["Fiscal Year"], + reqd: 1, + on_change: function () { + let filter_based_on = frappe.query_report.get_filter_value("filter_based_on"); + frappe.query_report.toggle_filter_display( + "from_fiscal_year", + filter_based_on === "Date Range" + ); + frappe.query_report.toggle_filter_display( + "to_fiscal_year", + filter_based_on === "Date Range" + ); + frappe.query_report.toggle_filter_display( + "period_start_date", + filter_based_on === "Fiscal Year" + ); + frappe.query_report.toggle_filter_display( + "period_end_date", + filter_based_on === "Fiscal Year" + ); frappe.query_report.refresh(); - } + }, }, { - "fieldname":"period_start_date", - "label": __("Start Date"), - "fieldtype": "Date", - "hidden": 1, - "reqd": 1 + fieldname: "period_start_date", + label: __("Start Date"), + fieldtype: "Date", + hidden: 1, + reqd: 1, }, { - "fieldname":"period_end_date", - "label": __("End Date"), - "fieldtype": "Date", - "hidden": 1, - "reqd": 1 + fieldname: "period_end_date", + label: __("End Date"), + fieldtype: "Date", + hidden: 1, + reqd: 1, }, { - "fieldname":"from_fiscal_year", - "label": __("Start Year"), - "fieldtype": "Link", - "options": "Fiscal Year", - "default": erpnext.utils.get_fiscal_year(frappe.datetime.get_today()), - "reqd": 1, + fieldname: "from_fiscal_year", + label: __("Start Year"), + fieldtype: "Link", + options: "Fiscal Year", + default: erpnext.utils.get_fiscal_year(frappe.datetime.get_today()), + reqd: 1, on_change: () => { - frappe.model.with_doc("Fiscal Year", frappe.query_report.get_filter_value('from_fiscal_year'), function(r) { - let year_start_date = frappe.model.get_value("Fiscal Year", frappe.query_report.get_filter_value('from_fiscal_year'), "year_start_date"); - frappe.query_report.set_filter_value({ - period_start_date: year_start_date - }); - }); - } + frappe.model.with_doc( + "Fiscal Year", + frappe.query_report.get_filter_value("from_fiscal_year"), + function (r) { + let year_start_date = frappe.model.get_value( + "Fiscal Year", + frappe.query_report.get_filter_value("from_fiscal_year"), + "year_start_date" + ); + frappe.query_report.set_filter_value({ + period_start_date: year_start_date, + }); + } + ); + }, }, { - "fieldname":"to_fiscal_year", - "label": __("End Year"), - "fieldtype": "Link", - "options": "Fiscal Year", - "default": erpnext.utils.get_fiscal_year(frappe.datetime.get_today()), - "reqd": 1, + fieldname: "to_fiscal_year", + label: __("End Year"), + fieldtype: "Link", + options: "Fiscal Year", + default: erpnext.utils.get_fiscal_year(frappe.datetime.get_today()), + reqd: 1, on_change: () => { - frappe.model.with_doc("Fiscal Year", frappe.query_report.get_filter_value('to_fiscal_year'), function(r) { - let year_end_date = frappe.model.get_value("Fiscal Year", frappe.query_report.get_filter_value('to_fiscal_year'), "year_end_date"); - frappe.query_report.set_filter_value({ - period_end_date: year_end_date - }); - }); - } + frappe.model.with_doc( + "Fiscal Year", + frappe.query_report.get_filter_value("to_fiscal_year"), + function (r) { + let year_end_date = frappe.model.get_value( + "Fiscal Year", + frappe.query_report.get_filter_value("to_fiscal_year"), + "year_end_date" + ); + frappe.query_report.set_filter_value({ + period_end_date: year_end_date, + }); + } + ); + }, }, { - "fieldname":"finance_book", - "label": __("Finance Book"), - "fieldtype": "Link", - "options": "Finance Book" + fieldname: "finance_book", + label: __("Finance Book"), + fieldtype: "Link", + options: "Finance Book", }, { - "fieldname":"report", - "label": __("Report"), - "fieldtype": "Select", - "options": ["Profit and Loss Statement", "Balance Sheet", "Cash Flow"], - "default": "Balance Sheet", - "reqd": 1 + fieldname: "report", + label: __("Report"), + fieldtype: "Select", + options: ["Profit and Loss Statement", "Balance Sheet", "Cash Flow"], + default: "Balance Sheet", + reqd: 1, }, { - "fieldname": "presentation_currency", - "label": __("Currency"), - "fieldtype": "Select", - "options": erpnext.get_presentation_currency_list(), - "default": frappe.defaults.get_user_default("Currency") + fieldname: "presentation_currency", + label: __("Currency"), + fieldtype: "Select", + options: erpnext.get_presentation_currency_list(), + default: frappe.defaults.get_user_default("Currency"), }, { - "fieldname":"accumulated_in_group_company", - "label": __("Accumulated Values in Group Company"), - "fieldtype": "Check", - "default": 0 + fieldname: "accumulated_in_group_company", + label: __("Accumulated Values in Group Company"), + fieldtype: "Check", + default: 0, }, { - "fieldname": "include_default_book_entries", - "label": __("Include Default FB Entries"), - "fieldtype": "Check", - "default": 1 + fieldname: "include_default_book_entries", + label: __("Include Default FB Entries"), + fieldtype: "Check", + default: 1, }, { - "fieldname": "show_zero_values", - "label": __("Show zero values"), - "fieldtype": "Check" - } + fieldname: "show_zero_values", + label: __("Show zero values"), + fieldtype: "Check", + }, ], - "formatter": function(value, row, column, data, default_formatter) { - if (data && column.fieldname=="account") { + formatter: function (value, row, column, data, default_formatter) { + if (data && column.fieldname == "account") { value = data.account_name || value; column.link_onclick = - "erpnext.financial_statements.open_general_ledger(" + JSON.stringify(data) + ")"; + "erpnext.financial_statements.open_general_ledger(" + JSON.stringify(data) + ")"; column.is_tree = true; } @@ -138,16 +166,16 @@ frappe.require("assets/erpnext/js/financial_statements.js", function() { } return value; }, - onload: function() { + onload: function () { let fiscal_year = erpnext.utils.get_fiscal_year(frappe.datetime.get_today()); - frappe.model.with_doc("Fiscal Year", fiscal_year, function(r) { + frappe.model.with_doc("Fiscal Year", fiscal_year, function (r) { var fy = frappe.model.get_doc("Fiscal Year", fiscal_year); frappe.query_report.set_filter_value({ period_start_date: fy.year_start_date, - period_end_date: fy.year_end_date + period_end_date: fy.year_end_date, }); }); - } - } + }, + }; }); diff --git a/erpnext/accounts/report/customer_ledger_summary/customer_ledger_summary.js b/erpnext/accounts/report/customer_ledger_summary/customer_ledger_summary.js index a1236316638a..dec2ebd25204 100644 --- a/erpnext/accounts/report/customer_ledger_summary/customer_ledger_summary.js +++ b/erpnext/accounts/report/customer_ledger_summary/customer_ledger_summary.js @@ -3,95 +3,95 @@ /* eslint-disable */ frappe.query_reports["Customer Ledger Summary"] = { - "filters": [ + filters: [ { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_user_default("Company") + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), }, { - "fieldname":"from_date", - "label": __("From Date"), - "fieldtype": "Date", - "default": frappe.datetime.add_months(frappe.datetime.get_today(), -1), - "reqd": 1, - "width": "60px" + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + default: frappe.datetime.add_months(frappe.datetime.get_today(), -1), + reqd: 1, + width: "60px", }, { - "fieldname":"to_date", - "label": __("To Date"), - "fieldtype": "Date", - "default": frappe.datetime.get_today(), - "reqd": 1, - "width": "60px" + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + default: frappe.datetime.get_today(), + reqd: 1, + width: "60px", }, { - "fieldname":"finance_book", - "label": __("Finance Book"), - "fieldtype": "Link", - "options": "Finance Book" + fieldname: "finance_book", + label: __("Finance Book"), + fieldtype: "Link", + options: "Finance Book", }, { - "fieldname":"party", - "label": __("Customer"), - "fieldtype": "Link", - "options": "Customer", + fieldname: "party", + label: __("Customer"), + fieldtype: "Link", + options: "Customer", on_change: () => { - var party = frappe.query_report.get_filter_value('party'); + var party = frappe.query_report.get_filter_value("party"); if (party) { - frappe.db.get_value('Customer', party, ["tax_id", "customer_name"], function(value) { - frappe.query_report.set_filter_value('tax_id', value["tax_id"]); - frappe.query_report.set_filter_value('customer_name', value["customer_name"]); + frappe.db.get_value("Customer", party, ["tax_id", "customer_name"], function (value) { + frappe.query_report.set_filter_value("tax_id", value["tax_id"]); + frappe.query_report.set_filter_value("customer_name", value["customer_name"]); }); } else { - frappe.query_report.set_filter_value('tax_id', ""); - frappe.query_report.set_filter_value('customer_name', ""); + frappe.query_report.set_filter_value("tax_id", ""); + frappe.query_report.set_filter_value("customer_name", ""); } - } + }, }, { - "fieldname":"customer_group", - "label": __("Customer Group"), - "fieldtype": "Link", - "options": "Customer Group" + fieldname: "customer_group", + label: __("Customer Group"), + fieldtype: "Link", + options: "Customer Group", }, { - "fieldname":"payment_terms_template", - "label": __("Payment Terms Template"), - "fieldtype": "Link", - "options": "Payment Terms Template" + fieldname: "payment_terms_template", + label: __("Payment Terms Template"), + fieldtype: "Link", + options: "Payment Terms Template", }, { - "fieldname":"territory", - "label": __("Territory"), - "fieldtype": "Link", - "options": "Territory" + fieldname: "territory", + label: __("Territory"), + fieldtype: "Link", + options: "Territory", }, { - "fieldname":"sales_partner", - "label": __("Sales Partner"), - "fieldtype": "Link", - "options": "Sales Partner" + fieldname: "sales_partner", + label: __("Sales Partner"), + fieldtype: "Link", + options: "Sales Partner", }, { - "fieldname":"sales_person", - "label": __("Sales Person"), - "fieldtype": "Link", - "options": "Sales Person" + fieldname: "sales_person", + label: __("Sales Person"), + fieldtype: "Link", + options: "Sales Person", }, { - "fieldname":"tax_id", - "label": __("Tax Id"), - "fieldtype": "Data", - "hidden": 1 + fieldname: "tax_id", + label: __("Tax Id"), + fieldtype: "Data", + hidden: 1, }, { - "fieldname":"customer_name", - "label": __("Customer Name"), - "fieldtype": "Data", - "hidden": 1 - } - ] + fieldname: "customer_name", + label: __("Customer Name"), + fieldtype: "Data", + hidden: 1, + }, + ], }; diff --git a/erpnext/accounts/report/deferred_revenue_and_expense/deferred_revenue_and_expense.js b/erpnext/accounts/report/deferred_revenue_and_expense/deferred_revenue_and_expense.js index 96e0c844ca58..63f1062fd330 100644 --- a/erpnext/accounts/report/deferred_revenue_and_expense/deferred_revenue_and_expense.js +++ b/erpnext/accounts/report/deferred_revenue_and_expense/deferred_revenue_and_expense.js @@ -5,110 +5,118 @@ function get_filters() { let filters = [ { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_user_default("Company"), - "reqd": 1 + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), + reqd: 1, }, { - "fieldname":"filter_based_on", - "label": __("Filter Based On"), - "fieldtype": "Select", - "options": ["Fiscal Year", "Date Range"], - "default": ["Fiscal Year"], - "reqd": 1, - on_change: function() { - let filter_based_on = frappe.query_report.get_filter_value('filter_based_on'); - frappe.query_report.toggle_filter_display('from_fiscal_year', filter_based_on === 'Date Range'); - frappe.query_report.toggle_filter_display('to_fiscal_year', filter_based_on === 'Date Range'); - frappe.query_report.toggle_filter_display('period_start_date', filter_based_on === 'Fiscal Year'); - frappe.query_report.toggle_filter_display('period_end_date', filter_based_on === 'Fiscal Year'); + fieldname: "filter_based_on", + label: __("Filter Based On"), + fieldtype: "Select", + options: ["Fiscal Year", "Date Range"], + default: ["Fiscal Year"], + reqd: 1, + on_change: function () { + let filter_based_on = frappe.query_report.get_filter_value("filter_based_on"); + frappe.query_report.toggle_filter_display( + "from_fiscal_year", + filter_based_on === "Date Range" + ); + frappe.query_report.toggle_filter_display("to_fiscal_year", filter_based_on === "Date Range"); + frappe.query_report.toggle_filter_display( + "period_start_date", + filter_based_on === "Fiscal Year" + ); + frappe.query_report.toggle_filter_display( + "period_end_date", + filter_based_on === "Fiscal Year" + ); frappe.query_report.refresh(); - } + }, }, { - "fieldname":"period_start_date", - "label": __("Start Date"), - "fieldtype": "Date", - "hidden": 1, - "reqd": 1 + fieldname: "period_start_date", + label: __("Start Date"), + fieldtype: "Date", + hidden: 1, + reqd: 1, }, { - "fieldname":"period_end_date", - "label": __("End Date"), - "fieldtype": "Date", - "hidden": 1, - "reqd": 1 + fieldname: "period_end_date", + label: __("End Date"), + fieldtype: "Date", + hidden: 1, + reqd: 1, }, { - "fieldname":"from_fiscal_year", - "label": __("Start Year"), - "fieldtype": "Link", - "options": "Fiscal Year", - "default": erpnext.utils.get_fiscal_year(frappe.datetime.get_today()), - "reqd": 1 + fieldname: "from_fiscal_year", + label: __("Start Year"), + fieldtype: "Link", + options: "Fiscal Year", + default: erpnext.utils.get_fiscal_year(frappe.datetime.get_today()), + reqd: 1, }, { - "fieldname":"to_fiscal_year", - "label": __("End Year"), - "fieldtype": "Link", - "options": "Fiscal Year", - "default": erpnext.utils.get_fiscal_year(frappe.datetime.get_today()), - "reqd": 1 + fieldname: "to_fiscal_year", + label: __("End Year"), + fieldtype: "Link", + options: "Fiscal Year", + default: erpnext.utils.get_fiscal_year(frappe.datetime.get_today()), + reqd: 1, }, { - "fieldname": "periodicity", - "label": __("Periodicity"), - "fieldtype": "Select", - "options": [ - { "value": "Monthly", "label": __("Monthly") }, - { "value": "Quarterly", "label": __("Quarterly") }, - { "value": "Half-Yearly", "label": __("Half-Yearly") }, - { "value": "Yearly", "label": __("Yearly") } + fieldname: "periodicity", + label: __("Periodicity"), + fieldtype: "Select", + options: [ + { value: "Monthly", label: __("Monthly") }, + { value: "Quarterly", label: __("Quarterly") }, + { value: "Half-Yearly", label: __("Half-Yearly") }, + { value: "Yearly", label: __("Yearly") }, ], - "default": "Monthly", - "reqd": 1 + default: "Monthly", + reqd: 1, }, { - "fieldname": "type", - "label": __("Invoice Type"), - "fieldtype": "Select", - "options": [ - { "value": "Revenue", "label": __("Revenue") }, - { "value": "Expense", "label": __("Expense") } + fieldname: "type", + label: __("Invoice Type"), + fieldtype: "Select", + options: [ + { value: "Revenue", label: __("Revenue") }, + { value: "Expense", label: __("Expense") }, ], - "default": "Revenue", - "reqd": 1 + default: "Revenue", + reqd: 1, }, { - "fieldname" : "with_upcoming_postings", - "label": __("Show with upcoming revenue/expense"), - "fieldtype": "Check", - "default": 1 - } - ] + fieldname: "with_upcoming_postings", + label: __("Show with upcoming revenue/expense"), + fieldtype: "Check", + default: 1, + }, + ]; return filters; } frappe.query_reports["Deferred Revenue and Expense"] = { - "filters": get_filters(), - "formatter": function(value, row, column, data, default_formatter){ + filters: get_filters(), + formatter: function (value, row, column, data, default_formatter) { return default_formatter(value, row, column, data); }, - onload: function(report){ + onload: function (report) { let fiscal_year = erpnext.utils.get_fiscal_year(frappe.datetime.get_today()); - frappe.model.with_doc("Fiscal Year", fiscal_year, function(r) { + frappe.model.with_doc("Fiscal Year", fiscal_year, function (r) { var fy = frappe.model.get_doc("Fiscal Year", fiscal_year); frappe.query_report.set_filter_value({ period_start_date: fy.year_start_date, - period_end_date: fy.year_end_date + period_end_date: fy.year_end_date, }); }); - } + }, }; - diff --git a/erpnext/accounts/report/delivered_items_to_be_billed/delivered_items_to_be_billed.js b/erpnext/accounts/report/delivered_items_to_be_billed/delivered_items_to_be_billed.js index 1454b2c73c87..f6051d7e04fa 100644 --- a/erpnext/accounts/report/delivered_items_to_be_billed/delivered_items_to_be_billed.js +++ b/erpnext/accounts/report/delivered_items_to_be_billed/delivered_items_to_be_billed.js @@ -2,7 +2,5 @@ // For license information, please see license.txt frappe.query_reports["Delivered Items To Be Billed"] = { - "filters": [ - - ] -} + filters: [], +}; diff --git a/erpnext/accounts/report/dimension_wise_accounts_balance_report/dimension_wise_accounts_balance_report.js b/erpnext/accounts/report/dimension_wise_accounts_balance_report/dimension_wise_accounts_balance_report.js index 9d416db4fdd8..27c0c660f018 100644 --- a/erpnext/accounts/report/dimension_wise_accounts_balance_report/dimension_wise_accounts_balance_report.js +++ b/erpnext/accounts/report/dimension_wise_accounts_balance_report/dimension_wise_accounts_balance_report.js @@ -2,83 +2,81 @@ // For license information, please see license.txt /* eslint-disable */ -frappe.require("assets/erpnext/js/financial_statements.js", function() { +frappe.require("assets/erpnext/js/financial_statements.js", function () { frappe.query_reports["Dimension-wise Accounts Balance Report"] = { - "filters": [ + filters: [ { - "fieldname": "company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_user_default("Company"), - "reqd": 1 + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), + reqd: 1, }, { - "fieldname": "fiscal_year", - "label": __("Fiscal Year"), - "fieldtype": "Link", - "options": "Fiscal Year", - "default": erpnext.utils.get_fiscal_year(frappe.datetime.get_today()), - "reqd": 1, - "on_change": function(query_report) { + fieldname: "fiscal_year", + label: __("Fiscal Year"), + fieldtype: "Link", + options: "Fiscal Year", + default: erpnext.utils.get_fiscal_year(frappe.datetime.get_today()), + reqd: 1, + on_change: function (query_report) { var fiscal_year = query_report.get_values().fiscal_year; if (!fiscal_year) { return; } - frappe.model.with_doc("Fiscal Year", fiscal_year, function(r) { + frappe.model.with_doc("Fiscal Year", fiscal_year, function (r) { var fy = frappe.model.get_doc("Fiscal Year", fiscal_year); frappe.query_report.set_filter_value({ from_date: fy.year_start_date, - to_date: fy.year_end_date + to_date: fy.year_end_date, }); }); - } + }, }, { - "fieldname": "from_date", - "label": __("From Date"), - "fieldtype": "Date", - "default": frappe.defaults.get_user_default("year_start_date"), - "reqd": 1 + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + default: frappe.defaults.get_user_default("year_start_date"), + reqd: 1, }, { - "fieldname": "to_date", - "label": __("To Date"), - "fieldtype": "Date", - "default": frappe.defaults.get_user_default("year_end_date"), - "reqd": 1 + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + default: frappe.defaults.get_user_default("year_end_date"), + reqd: 1, }, { - "fieldname": "finance_book", - "label": __("Finance Book"), - "fieldtype": "Link", - "options": "Finance Book", + fieldname: "finance_book", + label: __("Finance Book"), + fieldtype: "Link", + options: "Finance Book", }, { - "fieldname": "dimension", - "label": __("Select Dimension"), - "fieldtype": "Select", - "default": "Cost Center", - "options": get_accounting_dimension_options(), - "reqd": 1, + fieldname: "dimension", + label: __("Select Dimension"), + fieldtype: "Select", + default: "Cost Center", + options: get_accounting_dimension_options(), + reqd: 1, }, ], - "formatter": erpnext.financial_statements.formatter, - "tree": true, - "name_field": "account", - "parent_field": "parent_account", - "initial_depth": 3 - } - + formatter: erpnext.financial_statements.formatter, + tree: true, + name_field: "account", + parent_field: "parent_account", + initial_depth: 3, + }; }); function get_accounting_dimension_options() { - let options =["Cost Center", "Project"]; - frappe.db.get_list('Accounting Dimension', - {fields:['document_type']}).then((res) => { - res.forEach((dimension) => { - options.push(dimension.document_type); - }); + let options = ["Cost Center", "Project"]; + frappe.db.get_list("Accounting Dimension", { fields: ["document_type"] }).then((res) => { + res.forEach((dimension) => { + options.push(dimension.document_type); }); - return options + }); + return options; } diff --git a/erpnext/accounts/report/general_and_payment_ledger_comparison/general_and_payment_ledger_comparison.js b/erpnext/accounts/report/general_and_payment_ledger_comparison/general_and_payment_ledger_comparison.js index 7e6b0537e875..4eadf342be85 100644 --- a/erpnext/accounts/report/general_and_payment_ledger_comparison/general_and_payment_ledger_comparison.js +++ b/erpnext/accounts/report/general_and_payment_ledger_comparison/general_and_payment_ledger_comparison.js @@ -4,49 +4,49 @@ function get_filters() { let filters = [ { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_user_default("Company"), - "reqd": 1 + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), + reqd: 1, }, { - "fieldname":"period_start_date", - "label": __("Start Date"), - "fieldtype": "Date", - "reqd": 1, - "default": frappe.datetime.add_months(frappe.datetime.get_today(), -1) + fieldname: "period_start_date", + label: __("Start Date"), + fieldtype: "Date", + reqd: 1, + default: frappe.datetime.add_months(frappe.datetime.get_today(), -1), }, { - "fieldname":"period_end_date", - "label": __("End Date"), - "fieldtype": "Date", - "reqd": 1, - "default": frappe.datetime.get_today() + fieldname: "period_end_date", + label: __("End Date"), + fieldtype: "Date", + reqd: 1, + default: frappe.datetime.get_today(), }, { - "fieldname":"account", - "label": __("Account"), - "fieldtype": "MultiSelectList", - "options": "Account", - get_data: function(txt) { - return frappe.db.get_link_options('Account', txt, { + fieldname: "account", + label: __("Account"), + fieldtype: "MultiSelectList", + options: "Account", + get_data: function (txt) { + return frappe.db.get_link_options("Account", txt, { company: frappe.query_report.get_filter_value("company"), - account_type: ['in', ["Receivable", "Payable"]] + account_type: ["in", ["Receivable", "Payable"]], }); - } + }, }, { - "fieldname":"voucher_no", - "label": __("Voucher No"), - "fieldtype": "Data", - "width": 100, + fieldname: "voucher_no", + label: __("Voucher No"), + fieldtype: "Data", + width: 100, }, - ] + ]; return filters; } frappe.query_reports["General and Payment Ledger Comparison"] = { - "filters": get_filters() + filters: get_filters(), }; diff --git a/erpnext/accounts/report/general_ledger/general_ledger.js b/erpnext/accounts/report/general_ledger/general_ledger.js index 2b5abcb72409..3d0a2b78e5eb 100644 --- a/erpnext/accounts/report/general_ledger/general_ledger.js +++ b/erpnext/accounts/report/general_ledger/general_ledger.js @@ -2,114 +2,114 @@ // License: GNU General Public License v3. See license.txt frappe.query_reports["General Ledger"] = { - "filters": [ + filters: [ { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_user_default("Company"), - "reqd": 1 + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), + reqd: 1, }, { - "fieldname":"finance_book", - "label": __("Finance Book"), - "fieldtype": "Link", - "options": "Finance Book" + fieldname: "finance_book", + label: __("Finance Book"), + fieldtype: "Link", + options: "Finance Book", }, { - "fieldname":"from_date", - "label": __("From Date"), - "fieldtype": "Date", - "default": frappe.datetime.add_months(frappe.datetime.get_today(), -1), - "reqd": 1, - "width": "60px" + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + default: frappe.datetime.add_months(frappe.datetime.get_today(), -1), + reqd: 1, + width: "60px", }, { - "fieldname":"to_date", - "label": __("To Date"), - "fieldtype": "Date", - "default": frappe.datetime.get_today(), - "reqd": 1, - "width": "60px" + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + default: frappe.datetime.get_today(), + reqd: 1, + width: "60px", }, { - "fieldname":"account", - "label": __("Account"), - "fieldtype": "MultiSelectList", - "options": "Account", - get_data: function(txt) { - return frappe.db.get_link_options('Account', txt, { - company: frappe.query_report.get_filter_value("company") + fieldname: "account", + label: __("Account"), + fieldtype: "MultiSelectList", + options: "Account", + get_data: function (txt) { + return frappe.db.get_link_options("Account", txt, { + company: frappe.query_report.get_filter_value("company"), }); - } + }, }, { - "fieldname":"voucher_no", - "label": __("Voucher No"), - "fieldtype": "Data", - on_change: function() { - frappe.query_report.set_filter_value('group_by', "Group by Voucher (Consolidated)"); - } + fieldname: "voucher_no", + label: __("Voucher No"), + fieldtype: "Data", + on_change: function () { + frappe.query_report.set_filter_value("group_by", "Group by Voucher (Consolidated)"); + }, }, { - "fieldtype": "Break", + fieldtype: "Break", }, { - "fieldname":"party_type", - "label": __("Party Type"), - "fieldtype": "Autocomplete", + fieldname: "party_type", + label: __("Party Type"), + fieldtype: "Autocomplete", options: Object.keys(frappe.boot.party_account_types), - on_change: function() { - frappe.query_report.set_filter_value('party', ""); - } + on_change: function () { + frappe.query_report.set_filter_value("party", ""); + }, }, { - "fieldname":"party", - "label": __("Party"), - "fieldtype": "MultiSelectList", - get_data: function(txt) { + fieldname: "party", + label: __("Party"), + fieldtype: "MultiSelectList", + get_data: function (txt) { if (!frappe.query_report.filters) return; - let party_type = frappe.query_report.get_filter_value('party_type'); + let party_type = frappe.query_report.get_filter_value("party_type"); if (!party_type) return; return frappe.db.get_link_options(party_type, txt); }, - on_change: function() { - var party_type = frappe.query_report.get_filter_value('party_type'); - var parties = frappe.query_report.get_filter_value('party'); + on_change: function () { + var party_type = frappe.query_report.get_filter_value("party_type"); + var parties = frappe.query_report.get_filter_value("party"); - if(!party_type || parties.length === 0 || parties.length > 1) { - frappe.query_report.set_filter_value('party_name', ""); - frappe.query_report.set_filter_value('tax_id', ""); + if (!party_type || parties.length === 0 || parties.length > 1) { + frappe.query_report.set_filter_value("party_name", ""); + frappe.query_report.set_filter_value("tax_id", ""); return; } else { var party = parties[0]; var fieldname = erpnext.utils.get_party_name(party_type) || "name"; - frappe.db.get_value(party_type, party, fieldname, function(value) { - frappe.query_report.set_filter_value('party_name', value[fieldname]); + frappe.db.get_value(party_type, party, fieldname, function (value) { + frappe.query_report.set_filter_value("party_name", value[fieldname]); }); if (party_type === "Customer" || party_type === "Supplier") { - frappe.db.get_value(party_type, party, "tax_id", function(value) { - frappe.query_report.set_filter_value('tax_id', value["tax_id"]); + frappe.db.get_value(party_type, party, "tax_id", function (value) { + frappe.query_report.set_filter_value("tax_id", value["tax_id"]); }); } } - } + }, }, { - "fieldname":"party_name", - "label": __("Party Name"), - "fieldtype": "Data", - "hidden": 1 + fieldname: "party_name", + label: __("Party Name"), + fieldtype: "Data", + hidden: 1, }, { - "fieldname":"group_by", - "label": __("Group by"), - "fieldtype": "Select", - "options": [ + fieldname: "group_by", + label: __("Group by"), + fieldtype: "Select", + options: [ "", { label: __("Group by Voucher"), @@ -128,80 +128,78 @@ frappe.query_reports["General Ledger"] = { value: "Group by Party", }, ], - "default": "Group by Voucher (Consolidated)" + default: "Group by Voucher (Consolidated)", }, { - "fieldname":"tax_id", - "label": __("Tax Id"), - "fieldtype": "Data", - "hidden": 1 + fieldname: "tax_id", + label: __("Tax Id"), + fieldtype: "Data", + hidden: 1, }, { - "fieldname": "presentation_currency", - "label": __("Currency"), - "fieldtype": "Select", - "options": erpnext.get_presentation_currency_list() + fieldname: "presentation_currency", + label: __("Currency"), + fieldtype: "Select", + options: erpnext.get_presentation_currency_list(), }, { - "fieldname":"cost_center", - "label": __("Cost Center"), - "fieldtype": "MultiSelectList", - get_data: function(txt) { - return frappe.db.get_link_options('Cost Center', txt, { - company: frappe.query_report.get_filter_value("company") + fieldname: "cost_center", + label: __("Cost Center"), + fieldtype: "MultiSelectList", + get_data: function (txt) { + return frappe.db.get_link_options("Cost Center", txt, { + company: frappe.query_report.get_filter_value("company"), }); - } + }, }, { - "fieldname":"project", - "label": __("Project"), - "fieldtype": "MultiSelectList", - get_data: function(txt) { - return frappe.db.get_link_options('Project', txt, { - company: frappe.query_report.get_filter_value("company") + fieldname: "project", + label: __("Project"), + fieldtype: "MultiSelectList", + get_data: function (txt) { + return frappe.db.get_link_options("Project", txt, { + company: frappe.query_report.get_filter_value("company"), }); - } + }, }, { - "fieldname": "include_dimensions", - "label": __("Consider Accounting Dimensions"), - "fieldtype": "Check", - "default": 1 + fieldname: "include_dimensions", + label: __("Consider Accounting Dimensions"), + fieldtype: "Check", + default: 1, }, { - "fieldname": "show_opening_entries", - "label": __("Show Opening Entries"), - "fieldtype": "Check" + fieldname: "show_opening_entries", + label: __("Show Opening Entries"), + fieldtype: "Check", }, { - "fieldname": "include_default_book_entries", - "label": __("Include Default FB Entries"), - "fieldtype": "Check", - "default": 1 + fieldname: "include_default_book_entries", + label: __("Include Default FB Entries"), + fieldtype: "Check", + default: 1, }, { - "fieldname": "show_cancelled_entries", - "label": __("Show Cancelled Entries"), - "fieldtype": "Check" + fieldname: "show_cancelled_entries", + label: __("Show Cancelled Entries"), + fieldtype: "Check", }, { - "fieldname": "show_net_values_in_party_account", - "label": __("Show Net Values in Party Account"), - "fieldtype": "Check" + fieldname: "show_net_values_in_party_account", + label: __("Show Net Values in Party Account"), + fieldtype: "Check", }, { - "fieldname": "show_remarks", - "label": __("Show Remarks"), - "fieldtype": "Check" + fieldname: "show_remarks", + label: __("Show Remarks"), + fieldtype: "Check", }, { - "fieldname": "ignore_err", - "label": __("Ignore Exchange Rate Revaluation Journals"), - "fieldtype": "Check" - } - - - ] -} + fieldname: "ignore_err", + label: __("Ignore Exchange Rate Revaluation Journals"), + fieldtype: "Check", + }, + ], +}; -erpnext.utils.add_dimensions('General Ledger', 15) +erpnext.utils.add_dimensions("General Ledger", 15); diff --git a/erpnext/accounts/report/gross_and_net_profit_report/gross_and_net_profit_report.js b/erpnext/accounts/report/gross_and_net_profit_report/gross_and_net_profit_report.js index 92cf36ebc528..3610d1721ea3 100644 --- a/erpnext/accounts/report/gross_and_net_profit_report/gross_and_net_profit_report.js +++ b/erpnext/accounts/report/gross_and_net_profit_report/gross_and_net_profit_report.js @@ -3,19 +3,14 @@ /* eslint-disable */ frappe.query_reports["Gross and Net Profit Report"] = { - "filters": [ + filters: [], +}; +frappe.require("assets/erpnext/js/financial_statements.js", function () { + frappe.query_reports["Gross and Net Profit Report"] = $.extend({}, erpnext.financial_statements); - ] -} -frappe.require("assets/erpnext/js/financial_statements.js", function() { - frappe.query_reports["Gross and Net Profit Report"] = $.extend({}, - erpnext.financial_statements); - - frappe.query_reports["Gross and Net Profit Report"]["filters"].push( - { - "fieldname": "accumulated_values", - "label": __("Accumulated Values"), - "fieldtype": "Check" - } - ); + frappe.query_reports["Gross and Net Profit Report"]["filters"].push({ + fieldname: "accumulated_values", + label: __("Accumulated Values"), + fieldtype: "Check", + }); }); diff --git a/erpnext/accounts/report/gross_profit/gross_profit.js b/erpnext/accounts/report/gross_profit/gross_profit.js index cf4ccef24333..890befe85963 100644 --- a/erpnext/accounts/report/gross_profit/gross_profit.js +++ b/erpnext/accounts/report/gross_profit/gross_profit.js @@ -2,60 +2,61 @@ // License: GNU General Public License v3. See license.txt frappe.query_reports["Gross Profit"] = { - "filters": [ + filters: [ { - "fieldname": "company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_user_default("Company"), - "reqd": 1 + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), + reqd: 1, }, { - "fieldname": "from_date", - "label": __("From Date"), - "fieldtype": "Date", - "default": frappe.defaults.get_user_default("year_start_date"), - "reqd": 1 + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + default: frappe.defaults.get_user_default("year_start_date"), + reqd: 1, }, { - "fieldname": "to_date", - "label": __("To Date"), - "fieldtype": "Date", - "default": frappe.defaults.get_user_default("year_end_date"), - "reqd": 1 + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + default: frappe.defaults.get_user_default("year_end_date"), + reqd: 1, }, { - "fieldname": "sales_invoice", - "label": __("Sales Invoice"), - "fieldtype": "Link", - "options": "Sales Invoice" + fieldname: "sales_invoice", + label: __("Sales Invoice"), + fieldtype: "Link", + options: "Sales Invoice", }, { - "fieldname": "group_by", - "label": __("Group By"), - "fieldtype": "Select", - "options": "Invoice\nItem Code\nItem Group\nBrand\nWarehouse\nCustomer\nCustomer Group\nTerritory\nSales Person\nProject\nMonthly\nPayment Term", - "default": "Invoice" + fieldname: "group_by", + label: __("Group By"), + fieldtype: "Select", + options: + "Invoice\nItem Code\nItem Group\nBrand\nWarehouse\nCustomer\nCustomer Group\nTerritory\nSales Person\nProject\nMonthly\nPayment Term", + default: "Invoice", }, { - "fieldname": "item_group", - "label": __("Item Group"), - "fieldtype": "Link", - "options": "Item Group" + fieldname: "item_group", + label: __("Item Group"), + fieldtype: "Link", + options: "Item Group", }, { - "fieldname": "sales_person", - "label": __("Sales Person"), - "fieldtype": "Link", - "options": "Sales Person" + fieldname: "sales_person", + label: __("Sales Person"), + fieldtype: "Link", + options: "Sales Person", }, ], - "tree": true, - "name_field": "parent", - "parent_field": "parent_invoice", - "initial_depth": 3, - "formatter": function(value, row, column, data, default_formatter) { + tree: true, + name_field: "parent", + parent_field: "parent_invoice", + initial_depth: 3, + formatter: function (value, row, column, data, default_formatter) { if (column.fieldname == "sales_invoice" && column.options == "Item" && data && data.indent == 0) { column._options = "Sales Invoice"; } else { @@ -71,4 +72,4 @@ frappe.query_reports["Gross Profit"] = { return value; }, -} +}; diff --git a/erpnext/accounts/report/inactive_sales_items/inactive_sales_items.js b/erpnext/accounts/report/inactive_sales_items/inactive_sales_items.js index 7908c07a0ade..6aa1943c453c 100644 --- a/erpnext/accounts/report/inactive_sales_items/inactive_sales_items.js +++ b/erpnext/accounts/report/inactive_sales_items/inactive_sales_items.js @@ -3,7 +3,7 @@ /* eslint-disable */ frappe.query_reports["Inactive Sales Items"] = { - "filters": [ + filters: [ { fieldname: "territory", label: __("Territory"), @@ -15,27 +15,27 @@ frappe.query_reports["Inactive Sales Items"] = { fieldname: "item", label: __("Item"), fieldtype: "Link", - options: "Item" + options: "Item", }, { fieldname: "item_group", label: __("Item Group"), fieldtype: "Link", - options: "Item Group" + options: "Item Group", }, { fieldname: "based_on", label: __("Based On"), fieldtype: "Select", options: "Sales Order\nSales Invoice", - default: "Sales Order" + default: "Sales Order", }, { fieldname: "days", label: __("Days Since Last order"), fieldtype: "Select", options: [30, 60, 90], - default: 30 + default: 30, }, - ] + ], }; diff --git a/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.js b/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.js index b709ab9b57d2..19ce9ffc6073 100644 --- a/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.js +++ b/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.js @@ -2,59 +2,58 @@ // License: GNU General Public License v3. See license.txt frappe.query_reports["Item-wise Purchase Register"] = { - "filters": [ + filters: [ { - "fieldname":"from_date", - "label": __("From Date"), - "fieldtype": "Date", - "default": frappe.datetime.add_months(frappe.datetime.get_today(), -1), - "reqd": 1, + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + default: frappe.datetime.add_months(frappe.datetime.get_today(), -1), + reqd: 1, }, { - "fieldname":"to_date", - "label": __("To Date"), - "fieldtype": "Date", - "default": frappe.datetime.get_today(), - "reqd": 1, + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + default: frappe.datetime.get_today(), + reqd: 1, }, { - "fieldname": "item_code", - "label": __("Item"), - "fieldtype": "Link", - "options": "Item", + fieldname: "item_code", + label: __("Item"), + fieldtype: "Link", + options: "Item", }, { - "fieldname":"supplier", - "label": __("Supplier"), - "fieldtype": "Link", - "options": "Supplier" + fieldname: "supplier", + label: __("Supplier"), + fieldtype: "Link", + options: "Supplier", }, { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_user_default("Company") + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), }, { - "fieldname":"mode_of_payment", - "label": __("Mode of Payment"), - "fieldtype": "Link", - "options": "Mode of Payment" + fieldname: "mode_of_payment", + label: __("Mode of Payment"), + fieldtype: "Link", + options: "Mode of Payment", }, { - "label": __("Group By"), - "fieldname": "group_by", - "fieldtype": "Select", - "options": ["Supplier", "Item Group", "Item", "Invoice"] - } + label: __("Group By"), + fieldname: "group_by", + fieldtype: "Select", + options: ["Supplier", "Item Group", "Item", "Invoice"], + }, ], - "formatter": function(value, row, column, data, default_formatter) { + formatter: function (value, row, column, data, default_formatter) { value = default_formatter(value, row, column, data); if (data && data.bold) { value = value.bold(); - } return value; - } -} + }, +}; diff --git a/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.js b/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.js index 39fb3ca5ee39..7ed2ebd89abf 100644 --- a/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.js +++ b/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.js @@ -2,71 +2,70 @@ // License: GNU General Public License v3. See license.txt frappe.query_reports["Item-wise Sales Register"] = { - "filters": [ + filters: [ { - "fieldname":"from_date", - "label": __("From Date"), - "fieldtype": "Date", - "default": frappe.datetime.add_months(frappe.datetime.get_today(), -1), - "reqd": 1, + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + default: frappe.datetime.add_months(frappe.datetime.get_today(), -1), + reqd: 1, }, { - "fieldname":"to_date", - "label": __("To Date"), - "fieldtype": "Date", - "default": frappe.datetime.get_today(), - "reqd": 1, + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + default: frappe.datetime.get_today(), + reqd: 1, }, { - "fieldname": "customer", - "label": __("Customer"), - "fieldtype": "Link", - "options": "Customer" + fieldname: "customer", + label: __("Customer"), + fieldtype: "Link", + options: "Customer", }, { - "fieldname": "company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_user_default("Company") + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), }, { - "fieldname": "mode_of_payment", - "label": __("Mode of Payment"), - "fieldtype": "Link", - "options": "Mode of Payment" + fieldname: "mode_of_payment", + label: __("Mode of Payment"), + fieldtype: "Link", + options: "Mode of Payment", }, { - "fieldname": "warehouse", - "label": __("Warehouse"), - "fieldtype": "Link", - "options": "Warehouse" + fieldname: "warehouse", + label: __("Warehouse"), + fieldtype: "Link", + options: "Warehouse", }, { - "fieldname": "brand", - "label": __("Brand"), - "fieldtype": "Link", - "options": "Brand" + fieldname: "brand", + label: __("Brand"), + fieldtype: "Link", + options: "Brand", }, { - "fieldname": "item_group", - "label": __("Item Group"), - "fieldtype": "Link", - "options": "Item Group" + fieldname: "item_group", + label: __("Item Group"), + fieldtype: "Link", + options: "Item Group", }, { - "label": __("Group By"), - "fieldname": "group_by", - "fieldtype": "Select", - "options": ["Customer Group", "Customer", "Item Group", "Item", "Territory", "Invoice"] - } + label: __("Group By"), + fieldname: "group_by", + fieldtype: "Select", + options: ["Customer Group", "Customer", "Item Group", "Item", "Territory", "Invoice"], + }, ], - "formatter": function(value, row, column, data, default_formatter) { + formatter: function (value, row, column, data, default_formatter) { value = default_formatter(value, row, column, data); if (data && data.bold) { value = value.bold(); - } return value; - } -} + }, +}; diff --git a/erpnext/accounts/report/payment_ledger/payment_ledger.js b/erpnext/accounts/report/payment_ledger/payment_ledger.js index a5a4108f1df9..e0ea7522b124 100644 --- a/erpnext/accounts/report/payment_ledger/payment_ledger.js +++ b/erpnext/accounts/report/payment_ledger/payment_ledger.js @@ -5,92 +5,89 @@ function get_filters() { let filters = [ { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_user_default("Company"), - "reqd": 1 + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), + reqd: 1, }, { - "fieldname":"period_start_date", - "label": __("Start Date"), - "fieldtype": "Date", - "reqd": 1, - "default": frappe.datetime.add_months(frappe.datetime.get_today(), -1) + fieldname: "period_start_date", + label: __("Start Date"), + fieldtype: "Date", + reqd: 1, + default: frappe.datetime.add_months(frappe.datetime.get_today(), -1), }, { - "fieldname":"period_end_date", - "label": __("End Date"), - "fieldtype": "Date", - "reqd": 1, - "default": frappe.datetime.get_today() + fieldname: "period_end_date", + label: __("End Date"), + fieldtype: "Date", + reqd: 1, + default: frappe.datetime.get_today(), }, { - "fieldname":"account", - "label": __("Account"), - "fieldtype": "MultiSelectList", - "options": "Account", - get_data: function(txt) { - return frappe.db.get_link_options('Account', txt, { - company: frappe.query_report.get_filter_value("company") + fieldname: "account", + label: __("Account"), + fieldtype: "MultiSelectList", + options: "Account", + get_data: function (txt) { + return frappe.db.get_link_options("Account", txt, { + company: frappe.query_report.get_filter_value("company"), }); - } + }, }, { - "fieldname":"party_type", - "label": __("Party Type"), - "fieldtype": "Link", - "options": "Party Type", - "default": "", - on_change: function() { - frappe.query_report.set_filter_value('party', ""); - } + fieldname: "party_type", + label: __("Party Type"), + fieldtype: "Link", + options: "Party Type", + default: "", + on_change: function () { + frappe.query_report.set_filter_value("party", ""); + }, }, { - "fieldname":"party", - "label": __("Party"), - "fieldtype": "MultiSelectList", - get_data: function(txt) { + fieldname: "party", + label: __("Party"), + fieldtype: "MultiSelectList", + get_data: function (txt) { if (!frappe.query_report.filters) return; - let party_type = frappe.query_report.get_filter_value('party_type'); + let party_type = frappe.query_report.get_filter_value("party_type"); if (!party_type) return; return frappe.db.get_link_options(party_type, txt); }, }, { - "fieldname":"voucher_no", - "label": __("Voucher No"), - "fieldtype": "Data", - "width": 100, + fieldname: "voucher_no", + label: __("Voucher No"), + fieldtype: "Data", + width: 100, }, { - "fieldname":"against_voucher_no", - "label": __("Against Voucher No"), - "fieldtype": "Data", - "width": 100, + fieldname: "against_voucher_no", + label: __("Against Voucher No"), + fieldtype: "Data", + width: 100, }, { - "fieldname":"include_account_currency", - "label": __("Include Account Currency"), - "fieldtype": "Check", - "width": 100, + fieldname: "include_account_currency", + label: __("Include Account Currency"), + fieldtype: "Check", + width: 100, }, { - "fieldname":"group_party", - "label": __("Group by Party"), - "fieldtype": "Check", - "width": 100, + fieldname: "group_party", + label: __("Group by Party"), + fieldtype: "Check", + width: 100, }, - - - - ] + ]; return filters; } frappe.query_reports["Payment Ledger"] = { - "filters": get_filters() + filters: get_filters(), }; diff --git a/erpnext/accounts/report/payment_period_based_on_invoice_date/payment_period_based_on_invoice_date.js b/erpnext/accounts/report/payment_period_based_on_invoice_date/payment_period_based_on_invoice_date.js index 2343eaa8461e..8625c57d46bf 100644 --- a/erpnext/accounts/report/payment_period_based_on_invoice_date/payment_period_based_on_invoice_date.js +++ b/erpnext/accounts/report/payment_period_based_on_invoice_date/payment_period_based_on_invoice_date.js @@ -2,14 +2,14 @@ // License: GNU General Public License v3. See license.txt frappe.query_reports["Payment Period Based On Invoice Date"] = { - "filters": [ + filters: [ { - fieldname:"company", + fieldname: "company", label: __("Company"), fieldtype: "Link", options: "Company", reqd: 1, - default: frappe.defaults.get_user_default("Company") + default: frappe.defaults.get_user_default("Company"), }, { fieldname: "from_date", @@ -18,41 +18,41 @@ frappe.query_reports["Payment Period Based On Invoice Date"] = { default: frappe.defaults.get_user_default("year_start_date"), }, { - fieldname:"to_date", + fieldname: "to_date", label: __("To Date"), fieldtype: "Date", - default: frappe.datetime.get_today() + default: frappe.datetime.get_today(), }, { - fieldname:"payment_type", + fieldname: "payment_type", label: __("Payment Type"), fieldtype: "Select", options: __("Incoming") + "\n" + __("Outgoing"), - default: __("Incoming") + default: __("Incoming"), }, { - "fieldname":"party_type", - "label": __("Party Type"), - "fieldtype": "Link", - "options": "DocType", - "get_query": function() { + fieldname: "party_type", + label: __("Party Type"), + fieldtype: "Link", + options: "DocType", + get_query: function () { return { - filters: {"name": ["in", ["Customer", "Supplier"]]} - } - } + filters: { name: ["in", ["Customer", "Supplier"]] }, + }; + }, }, { - "fieldname":"party", - "label": __("Party"), - "fieldtype": "Dynamic Link", - "get_options": function() { - var party_type = frappe.query_report.get_filter_value('party_type'); - var party = frappe.query_report.get_filter_value('party'); - if(party && !party_type) { + fieldname: "party", + label: __("Party"), + fieldtype: "Dynamic Link", + get_options: function () { + var party_type = frappe.query_report.get_filter_value("party_type"); + var party = frappe.query_report.get_filter_value("party"); + if (party && !party_type) { frappe.throw(__("Please select Party Type first")); } return party_type; - } + }, }, - ] -} + ], +}; diff --git a/erpnext/accounts/report/pos_register/pos_register.js b/erpnext/accounts/report/pos_register/pos_register.js index b8d48d92de0f..1200d3e79f22 100644 --- a/erpnext/accounts/report/pos_register/pos_register.js +++ b/erpnext/accounts/report/pos_register/pos_register.js @@ -3,74 +3,73 @@ /* eslint-disable */ frappe.query_reports["POS Register"] = { - "filters": [ + filters: [ { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_user_default("Company"), - "reqd": 1 + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), + reqd: 1, }, { - "fieldname":"from_date", - "label": __("From Date"), - "fieldtype": "Date", - "default": frappe.datetime.add_months(frappe.datetime.get_today(), -1), - "reqd": 1, - "width": "60px" + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + default: frappe.datetime.add_months(frappe.datetime.get_today(), -1), + reqd: 1, + width: "60px", }, { - "fieldname":"to_date", - "label": __("To Date"), - "fieldtype": "Date", - "default": frappe.datetime.get_today(), - "reqd": 1, - "width": "60px" + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + default: frappe.datetime.get_today(), + reqd: 1, + width: "60px", }, { - "fieldname":"pos_profile", - "label": __("POS Profile"), - "fieldtype": "Link", - "options": "POS Profile" + fieldname: "pos_profile", + label: __("POS Profile"), + fieldtype: "Link", + options: "POS Profile", }, { - "fieldname":"cashier", - "label": __("Cashier"), - "fieldtype": "Link", - "options": "User" + fieldname: "cashier", + label: __("Cashier"), + fieldtype: "Link", + options: "User", }, { - "fieldname":"customer", - "label": __("Customer"), - "fieldtype": "Link", - "options": "Customer" + fieldname: "customer", + label: __("Customer"), + fieldtype: "Link", + options: "Customer", }, { - "fieldname":"mode_of_payment", - "label": __("Payment Method"), - "fieldtype": "Link", - "options": "Mode of Payment" + fieldname: "mode_of_payment", + label: __("Payment Method"), + fieldtype: "Link", + options: "Mode of Payment", }, { - "fieldname":"group_by", - "label": __("Group by"), - "fieldtype": "Select", - "options": ["", "POS Profile", "Cashier", "Payment Method", "Customer"], - "default": "POS Profile" + fieldname: "group_by", + label: __("Group by"), + fieldtype: "Select", + options: ["", "POS Profile", "Cashier", "Payment Method", "Customer"], + default: "POS Profile", }, { - "fieldname":"is_return", - "label": __("Is Return"), - "fieldtype": "Check" + fieldname: "is_return", + label: __("Is Return"), + fieldtype: "Check", }, ], - "formatter": function(value, row, column, data, default_formatter) { + formatter: function (value, row, column, data, default_formatter) { value = default_formatter(value, row, column, data); if (data && data.bold) { value = value.bold(); - } return value; - } + }, }; diff --git a/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.js b/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.js index 4e5cd312734e..c89a86c37b60 100644 --- a/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.js +++ b/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.js @@ -1,34 +1,28 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt +frappe.require("assets/erpnext/js/financial_statements.js", function () { + frappe.query_reports["Profit and Loss Statement"] = $.extend({}, erpnext.financial_statements); -frappe.require("assets/erpnext/js/financial_statements.js", function() { - frappe.query_reports["Profit and Loss Statement"] = $.extend({}, - erpnext.financial_statements); + erpnext.utils.add_dimensions("Profit and Loss Statement", 10); - erpnext.utils.add_dimensions('Profit and Loss Statement', 10); + frappe.query_reports["Profit and Loss Statement"]["filters"].push({ + fieldname: "selected_view", + label: __("Select View"), + fieldtype: "Select", + options: [ + { value: "Report", label: __("Report View") }, + { value: "Growth", label: __("Growth View") }, + { value: "Margin", label: __("Margin View") }, + ], + default: "Report", + reqd: 1, + }); - frappe.query_reports["Profit and Loss Statement"]["filters"].push( - { - "fieldname": "selected_view", - "label": __("Select View"), - "fieldtype": "Select", - "options": [ - { "value": "Report", "label": __("Report View") }, - { "value": "Growth", "label": __("Growth View") }, - { "value": "Margin", "label": __("Margin View") }, - ], - "default": "Report", - "reqd": 1 - }, - ); - - frappe.query_reports["Profit and Loss Statement"]["filters"].push( - { - "fieldname": "include_default_book_entries", - "label": __("Include Default Book Entries"), - "fieldtype": "Check", - "default": 1 - } - ); + frappe.query_reports["Profit and Loss Statement"]["filters"].push({ + fieldname: "include_default_book_entries", + label: __("Include Default Book Entries"), + fieldtype: "Check", + default: 1, + }); }); diff --git a/erpnext/accounts/report/profitability_analysis/profitability_analysis.js b/erpnext/accounts/report/profitability_analysis/profitability_analysis.js index 1ac52fe5206d..dcecf7bb47fc 100644 --- a/erpnext/accounts/report/profitability_analysis/profitability_analysis.js +++ b/erpnext/accounts/report/profitability_analysis/profitability_analysis.js @@ -1,90 +1,92 @@ // Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.require("assets/erpnext/js/financial_statements.js", function() { +frappe.require("assets/erpnext/js/financial_statements.js", function () { frappe.query_reports["Profitability Analysis"] = { - "filters": [ + filters: [ { - "fieldname": "company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_user_default("Company"), - "reqd": 1 + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), + reqd: 1, }, { - "fieldname": "based_on", - "label": __("Based On"), - "fieldtype": "Select", - "options": ["Cost Center", "Project", "Accounting Dimension"], - "default": "Cost Center", - "reqd": 1, - "on_change": function(query_report){ + fieldname: "based_on", + label: __("Based On"), + fieldtype: "Select", + options: ["Cost Center", "Project", "Accounting Dimension"], + default: "Cost Center", + reqd: 1, + on_change: function (query_report) { let based_on = query_report.get_values().based_on; - if(based_on!='Accounting Dimension'){ + if (based_on != "Accounting Dimension") { frappe.query_report.set_filter_value({ - accounting_dimension: '' + accounting_dimension: "", }); } - } + }, }, { - "fieldname": "accounting_dimension", - "label": __("Accounting Dimension"), - "fieldtype": "Link", - "options": "Accounting Dimension", + fieldname: "accounting_dimension", + label: __("Accounting Dimension"), + fieldtype: "Link", + options: "Accounting Dimension", }, { - "fieldname": "fiscal_year", - "label": __("Fiscal Year"), - "fieldtype": "Link", - "options": "Fiscal Year", - "default": erpnext.utils.get_fiscal_year(frappe.datetime.get_today()), - "reqd": 1, - "on_change": function(query_report) { + fieldname: "fiscal_year", + label: __("Fiscal Year"), + fieldtype: "Link", + options: "Fiscal Year", + default: erpnext.utils.get_fiscal_year(frappe.datetime.get_today()), + reqd: 1, + on_change: function (query_report) { var fiscal_year = query_report.get_values().fiscal_year; if (!fiscal_year) { return; } - frappe.model.with_doc("Fiscal Year", fiscal_year, function(r) { + frappe.model.with_doc("Fiscal Year", fiscal_year, function (r) { var fy = frappe.model.get_doc("Fiscal Year", fiscal_year); frappe.query_report.set_filter_value({ from_date: fy.year_start_date, - to_date: fy.year_end_date + to_date: fy.year_end_date, }); }); - } + }, }, { - "fieldname": "from_date", - "label": __("From Date"), - "fieldtype": "Date", - "default": frappe.defaults.get_user_default("year_start_date"), + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + default: frappe.defaults.get_user_default("year_start_date"), }, { - "fieldname": "to_date", - "label": __("To Date"), - "fieldtype": "Date", - "default": frappe.defaults.get_user_default("year_end_date"), + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + default: frappe.defaults.get_user_default("year_end_date"), }, { - "fieldname": "show_zero_values", - "label": __("Show zero values"), - "fieldtype": "Check" - } + fieldname: "show_zero_values", + label: __("Show zero values"), + fieldtype: "Check", + }, ], - "formatter": function(value, row, column, data, default_formatter) { - if (column.fieldname=="account") { + formatter: function (value, row, column, data, default_formatter) { + if (column.fieldname == "account") { value = data.account_name; column.link_onclick = - "frappe.query_reports['Profitability Analysis'].open_profit_and_loss_statement(" + JSON.stringify(data) + ")"; + "frappe.query_reports['Profitability Analysis'].open_profit_and_loss_statement(" + + JSON.stringify(data) + + ")"; column.is_tree = true; } value = default_formatter(value, row, column, data); - if (!data.parent_account && data.based_on != 'project') { + if (!data.parent_account && data.based_on != "project") { value = $(`${value}`); var $value = $(value).css("font-weight", "bold"); if (data.warn_if_negative && data[column.fieldname] < 0) { @@ -96,27 +98,26 @@ frappe.require("assets/erpnext/js/financial_statements.js", function() { return value; }, - "open_profit_and_loss_statement": function(data) { + open_profit_and_loss_statement: function (data) { if (!data.account) return; frappe.route_options = { - "company": frappe.query_report.get_filter_value('company'), - "from_fiscal_year": data.fiscal_year, - "to_fiscal_year": data.fiscal_year + company: frappe.query_report.get_filter_value("company"), + from_fiscal_year: data.fiscal_year, + to_fiscal_year: data.fiscal_year, }; - if(data.based_on == 'Cost Center'){ - frappe.route_options["cost_center"] = data.account + if (data.based_on == "Cost Center") { + frappe.route_options["cost_center"] = data.account; } else { - frappe.route_options["project"] = data.account + frappe.route_options["project"] = data.account; } frappe.set_route("query-report", "Profit and Loss Statement"); }, - "tree": true, - "name_field": "account", - "parent_field": "parent_account", - "initial_depth": 3 - } - + tree: true, + name_field: "account", + parent_field: "parent_account", + initial_depth: 3, + }; }); diff --git a/erpnext/accounts/report/purchase_invoice_trends/purchase_invoice_trends.js b/erpnext/accounts/report/purchase_invoice_trends/purchase_invoice_trends.js index feab96f26521..e3f90f299827 100644 --- a/erpnext/accounts/report/purchase_invoice_trends/purchase_invoice_trends.js +++ b/erpnext/accounts/report/purchase_invoice_trends/purchase_invoice_trends.js @@ -1,8 +1,8 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -frappe.require("assets/erpnext/js/purchase_trends_filters.js", function() { +frappe.require("assets/erpnext/js/purchase_trends_filters.js", function () { frappe.query_reports["Purchase Invoice Trends"] = { - filters: erpnext.get_purchase_trends_filters() - } + filters: erpnext.get_purchase_trends_filters(), + }; }); diff --git a/erpnext/accounts/report/purchase_register/purchase_register.js b/erpnext/accounts/report/purchase_register/purchase_register.js index 57cb703baeaa..6366f3685525 100644 --- a/erpnext/accounts/report/purchase_register/purchase_register.js +++ b/erpnext/accounts/report/purchase_register/purchase_register.js @@ -2,64 +2,64 @@ // License: GNU General Public License v3. See license.txt frappe.query_reports["Purchase Register"] = { - "filters": [ + filters: [ { - "fieldname":"from_date", - "label": __("From Date"), - "fieldtype": "Date", - "default": frappe.datetime.add_months(frappe.datetime.get_today(), -1), - "width": "80" + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + default: frappe.datetime.add_months(frappe.datetime.get_today(), -1), + width: "80", }, { - "fieldname":"to_date", - "label": __("To Date"), - "fieldtype": "Date", - "default": frappe.datetime.get_today() + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + default: frappe.datetime.get_today(), }, { - "fieldname":"supplier", - "label": __("Supplier"), - "fieldtype": "Link", - "options": "Supplier" + fieldname: "supplier", + label: __("Supplier"), + fieldtype: "Link", + options: "Supplier", }, { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_user_default("Company") + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), }, { - "fieldname":"mode_of_payment", - "label": __("Mode of Payment"), - "fieldtype": "Link", - "options": "Mode of Payment" + fieldname: "mode_of_payment", + label: __("Mode of Payment"), + fieldtype: "Link", + options: "Mode of Payment", }, { - "fieldname":"cost_center", - "label": __("Cost Center"), - "fieldtype": "Link", - "options": "Cost Center" + fieldname: "cost_center", + label: __("Cost Center"), + fieldtype: "Link", + options: "Cost Center", }, { - "fieldname":"warehouse", - "label": __("Warehouse"), - "fieldtype": "Link", - "options": "Warehouse" + fieldname: "warehouse", + label: __("Warehouse"), + fieldtype: "Link", + options: "Warehouse", }, { - "fieldname":"item_group", - "label": __("Item Group"), - "fieldtype": "Link", - "options": "Item Group" + fieldname: "item_group", + label: __("Item Group"), + fieldtype: "Link", + options: "Item Group", }, { - "fieldname": "include_payments", - "label": __("Show Ledger View"), - "fieldtype": "Check", - "default": 0 - } - ] -} + fieldname: "include_payments", + label: __("Show Ledger View"), + fieldtype: "Check", + default: 0, + }, + ], +}; -erpnext.utils.add_dimensions('Purchase Register', 7); +erpnext.utils.add_dimensions("Purchase Register", 7); diff --git a/erpnext/accounts/report/received_items_to_be_billed/received_items_to_be_billed.js b/erpnext/accounts/report/received_items_to_be_billed/received_items_to_be_billed.js index 0ee3f5771719..ad97f270dd39 100644 --- a/erpnext/accounts/report/received_items_to_be_billed/received_items_to_be_billed.js +++ b/erpnext/accounts/report/received_items_to_be_billed/received_items_to_be_billed.js @@ -2,7 +2,5 @@ // For license information, please see license.txt frappe.query_reports["Received Items To Be Billed"] = { - "filters": [ - - ] -} + filters: [], +}; diff --git a/erpnext/accounts/report/sales_invoice_trends/sales_invoice_trends.js b/erpnext/accounts/report/sales_invoice_trends/sales_invoice_trends.js index e3d43a7de1e7..292d827b1634 100644 --- a/erpnext/accounts/report/sales_invoice_trends/sales_invoice_trends.js +++ b/erpnext/accounts/report/sales_invoice_trends/sales_invoice_trends.js @@ -1,8 +1,8 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -frappe.require("assets/erpnext/js/sales_trends_filters.js", function() { +frappe.require("assets/erpnext/js/sales_trends_filters.js", function () { frappe.query_reports["Sales Invoice Trends"] = { - filters: erpnext.get_sales_trends_filters() - } + filters: erpnext.get_sales_trends_filters(), + }; }); diff --git a/erpnext/accounts/report/sales_payment_summary/sales_payment_summary.js b/erpnext/accounts/report/sales_payment_summary/sales_payment_summary.js index 44e20e83c50c..0ec24ab0a2a9 100644 --- a/erpnext/accounts/report/sales_payment_summary/sales_payment_summary.js +++ b/erpnext/accounts/report/sales_payment_summary/sales_payment_summary.js @@ -1,45 +1,45 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt frappe.query_reports["Sales Payment Summary"] = { - "filters": [ + filters: [ { - "fieldname":"from_date", - "label": __("From Date"), - "fieldtype": "Date", - "default": frappe.datetime.get_today(), - "reqd": 1, - "width": "80" + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + default: frappe.datetime.get_today(), + reqd: 1, + width: "80", }, { - "fieldname":"to_date", - "label": __("To Date"), - "fieldtype": "Date", - "reqd": 1, - "default": frappe.datetime.get_today() + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + reqd: 1, + default: frappe.datetime.get_today(), }, { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_user_default("Company") + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), }, { - "fieldname":"owner", - "label": __("Owner"), - "fieldtype": "Link", - "options": "User", - "defaults": user + fieldname: "owner", + label: __("Owner"), + fieldtype: "Link", + options: "User", + defaults: user, }, { - "fieldname":"is_pos", - "label": __("Show only POS"), - "fieldtype": "Check" + fieldname: "is_pos", + label: __("Show only POS"), + fieldtype: "Check", }, { - "fieldname":"payment_detail", - "label": __("Show Payment Details"), - "fieldtype": "Check" + fieldname: "payment_detail", + label: __("Show Payment Details"), + fieldtype: "Check", }, - ] + ], }; diff --git a/erpnext/accounts/report/sales_register/sales_register.js b/erpnext/accounts/report/sales_register/sales_register.js index 1a41172a970d..b7f82e2367b0 100644 --- a/erpnext/accounts/report/sales_register/sales_register.js +++ b/erpnext/accounts/report/sales_register/sales_register.js @@ -2,76 +2,76 @@ // License: GNU General Public License v3. See license.txt frappe.query_reports["Sales Register"] = { - "filters": [ + filters: [ { - "fieldname":"from_date", - "label": __("From Date"), - "fieldtype": "Date", - "default": frappe.datetime.add_months(frappe.datetime.get_today(), -1), - "width": "80" + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + default: frappe.datetime.add_months(frappe.datetime.get_today(), -1), + width: "80", }, { - "fieldname":"to_date", - "label": __("To Date"), - "fieldtype": "Date", - "default": frappe.datetime.get_today() + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + default: frappe.datetime.get_today(), }, { - "fieldname":"customer", - "label": __("Customer"), - "fieldtype": "Link", - "options": "Customer" + fieldname: "customer", + label: __("Customer"), + fieldtype: "Link", + options: "Customer", }, { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_user_default("Company") + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), }, { - "fieldname":"mode_of_payment", - "label": __("Mode of Payment"), - "fieldtype": "Link", - "options": "Mode of Payment" + fieldname: "mode_of_payment", + label: __("Mode of Payment"), + fieldtype: "Link", + options: "Mode of Payment", }, { - "fieldname":"owner", - "label": __("Owner"), - "fieldtype": "Link", - "options": "User" + fieldname: "owner", + label: __("Owner"), + fieldtype: "Link", + options: "User", }, { - "fieldname":"cost_center", - "label": __("Cost Center"), - "fieldtype": "Link", - "options": "Cost Center" + fieldname: "cost_center", + label: __("Cost Center"), + fieldtype: "Link", + options: "Cost Center", }, { - "fieldname":"warehouse", - "label": __("Warehouse"), - "fieldtype": "Link", - "options": "Warehouse" + fieldname: "warehouse", + label: __("Warehouse"), + fieldtype: "Link", + options: "Warehouse", }, { - "fieldname":"brand", - "label": __("Brand"), - "fieldtype": "Link", - "options": "Brand" + fieldname: "brand", + label: __("Brand"), + fieldtype: "Link", + options: "Brand", }, { - "fieldname":"item_group", - "label": __("Item Group"), - "fieldtype": "Link", - "options": "Item Group" + fieldname: "item_group", + label: __("Item Group"), + fieldtype: "Link", + options: "Item Group", }, { - "fieldname": "include_payments", - "label": __("Show Ledger View"), - "fieldtype": "Check", - "default": 0 - } - ] -} + fieldname: "include_payments", + label: __("Show Ledger View"), + fieldtype: "Check", + default: 0, + }, + ], +}; -erpnext.utils.add_dimensions('Sales Register', 7); +erpnext.utils.add_dimensions("Sales Register", 7); diff --git a/erpnext/accounts/report/share_balance/share_balance.js b/erpnext/accounts/report/share_balance/share_balance.js index 6db5bdd299e1..bcfc2e43f179 100644 --- a/erpnext/accounts/report/share_balance/share_balance.js +++ b/erpnext/accounts/report/share_balance/share_balance.js @@ -4,19 +4,19 @@ /* eslint-disable */ frappe.query_reports["Share Balance"] = { - "filters": [ + filters: [ { - "fieldname":"date", - "label": __("Date"), - "fieldtype": "Date", - "default": frappe.datetime.get_today(), - "reqd": 1 + fieldname: "date", + label: __("Date"), + fieldtype: "Date", + default: frappe.datetime.get_today(), + reqd: 1, }, { - "fieldname":"shareholder", - "label": __("Shareholder"), - "fieldtype": "Link", - "options": "Shareholder" - } - ] -} + fieldname: "shareholder", + label: __("Shareholder"), + fieldtype: "Link", + options: "Shareholder", + }, + ], +}; diff --git a/erpnext/accounts/report/share_ledger/share_ledger.js b/erpnext/accounts/report/share_ledger/share_ledger.js index 6d1c44a6d016..e5e6289a8d36 100644 --- a/erpnext/accounts/report/share_ledger/share_ledger.js +++ b/erpnext/accounts/report/share_ledger/share_ledger.js @@ -4,19 +4,19 @@ /* eslint-disable */ frappe.query_reports["Share Ledger"] = { - "filters": [ + filters: [ { - "fieldname":"date", - "label": __("Date"), - "fieldtype": "Date", - "default": frappe.datetime.get_today(), - "reqd": 1 + fieldname: "date", + label: __("Date"), + fieldtype: "Date", + default: frappe.datetime.get_today(), + reqd: 1, }, { - "fieldname":"shareholder", - "label": __("Shareholder"), - "fieldtype": "Link", - "options": "Shareholder" - } - ] + fieldname: "shareholder", + label: __("Shareholder"), + fieldtype: "Link", + options: "Shareholder", + }, + ], }; diff --git a/erpnext/accounts/report/supplier_ledger_summary/supplier_ledger_summary.js b/erpnext/accounts/report/supplier_ledger_summary/supplier_ledger_summary.js index 5dc4c3d1c159..1244a1b01684 100644 --- a/erpnext/accounts/report/supplier_ledger_summary/supplier_ledger_summary.js +++ b/erpnext/accounts/report/supplier_ledger_summary/supplier_ledger_summary.js @@ -3,77 +3,77 @@ /* eslint-disable */ frappe.query_reports["Supplier Ledger Summary"] = { - "filters": [ + filters: [ { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_user_default("Company") + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), }, { - "fieldname":"from_date", - "label": __("From Date"), - "fieldtype": "Date", - "default": frappe.datetime.add_months(frappe.datetime.get_today(), -1), - "reqd": 1, - "width": "60px" + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + default: frappe.datetime.add_months(frappe.datetime.get_today(), -1), + reqd: 1, + width: "60px", }, { - "fieldname":"to_date", - "label": __("To Date"), - "fieldtype": "Date", - "default": frappe.datetime.get_today(), - "reqd": 1, - "width": "60px" + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + default: frappe.datetime.get_today(), + reqd: 1, + width: "60px", }, { - "fieldname":"finance_book", - "label": __("Finance Book"), - "fieldtype": "Link", - "options": "Finance Book" + fieldname: "finance_book", + label: __("Finance Book"), + fieldtype: "Link", + options: "Finance Book", }, { - "fieldname":"party", - "label": __("Supplier"), - "fieldtype": "Link", - "options": "Supplier", + fieldname: "party", + label: __("Supplier"), + fieldtype: "Link", + options: "Supplier", on_change: () => { - var party = frappe.query_report.get_filter_value('party'); + var party = frappe.query_report.get_filter_value("party"); if (party) { - frappe.db.get_value('Supplier', party, ["tax_id", "supplier_name"], function(value) { - frappe.query_report.set_filter_value('tax_id', value["tax_id"]); - frappe.query_report.set_filter_value('supplier_name', value["supplier_name"]); + frappe.db.get_value("Supplier", party, ["tax_id", "supplier_name"], function (value) { + frappe.query_report.set_filter_value("tax_id", value["tax_id"]); + frappe.query_report.set_filter_value("supplier_name", value["supplier_name"]); }); } else { - frappe.query_report.set_filter_value('tax_id', ""); - frappe.query_report.set_filter_value('supplier_name', ""); + frappe.query_report.set_filter_value("tax_id", ""); + frappe.query_report.set_filter_value("supplier_name", ""); } - } + }, }, { - "fieldname":"supplier_group", - "label": __("Supplier Group"), - "fieldtype": "Link", - "options": "Supplier Group" + fieldname: "supplier_group", + label: __("Supplier Group"), + fieldtype: "Link", + options: "Supplier Group", }, { - "fieldname":"payment_terms_template", - "label": __("Payment Terms Template"), - "fieldtype": "Link", - "options": "Payment Terms Template" + fieldname: "payment_terms_template", + label: __("Payment Terms Template"), + fieldtype: "Link", + options: "Payment Terms Template", }, { - "fieldname":"tax_id", - "label": __("Tax Id"), - "fieldtype": "Data", - "hidden": 1 + fieldname: "tax_id", + label: __("Tax Id"), + fieldtype: "Data", + hidden: 1, }, { - "fieldname":"supplier_name", - "label": __("Supplier Name"), - "fieldtype": "Data", - "hidden": 1 - } - ] + fieldname: "supplier_name", + label: __("Supplier Name"), + fieldtype: "Data", + hidden: 1, + }, + ], }; diff --git a/erpnext/accounts/report/tax_detail/tax_detail.js b/erpnext/accounts/report/tax_detail/tax_detail.js index ed6fac4e605d..d0e0970daa05 100644 --- a/erpnext/accounts/report/tax_detail/tax_detail.js +++ b/erpnext/accounts/report/tax_detail/tax_detail.js @@ -3,7 +3,7 @@ // Contributed by Case Solved and sponsored by Nulight Studios /* eslint-disable */ -frappe.provide('frappe.query_reports'); +frappe.provide("frappe.query_reports"); frappe.query_reports["Tax Detail"] = { filters: [ @@ -13,7 +13,7 @@ frappe.query_reports["Tax Detail"] = { fieldtype: "Link", options: "Company", default: frappe.defaults.get_user_default("company"), - reqd: 1 + reqd: 1, }, { fieldname: "from_date", @@ -21,7 +21,7 @@ frappe.query_reports["Tax Detail"] = { fieldtype: "Date", default: frappe.datetime.month_start(frappe.datetime.get_today()), reqd: 1, - width: "60px" + width: "60px", }, { fieldname: "to_date", @@ -29,7 +29,7 @@ frappe.query_reports["Tax Detail"] = { fieldtype: "Date", default: frappe.datetime.month_end(frappe.datetime.get_today()), reqd: 1, - width: "60px" + width: "60px", }, { fieldname: "report_name", @@ -37,7 +37,7 @@ frappe.query_reports["Tax Detail"] = { fieldtype: "Read Only", default: frappe.query_report.report_name, hidden: 1, - reqd: 1 + reqd: 1, }, { fieldname: "mode", @@ -45,23 +45,25 @@ frappe.query_reports["Tax Detail"] = { fieldtype: "Read Only", default: "edit", hidden: 1, - reqd: 1 - } + reqd: 1, + }, ], onload: function onload(report) { // Remove Add Column and Save from menu report.page.add_inner_button(__("New Report"), () => new_report(), __("Custom Report")); report.page.add_inner_button(__("Load Report"), () => load_report(), __("Custom Report")); hide_filters(report); - } + }, }; function hide_filters(report) { - report.page.page_form[0].querySelectorAll('.form-group.frappe-control').forEach(function setHidden(field) { - if (field.dataset.fieldtype == "Read Only") { - field.classList.add("hidden"); - } - }); + report.page.page_form[0] + .querySelectorAll(".form-group.frappe-control") + .forEach(function setHidden(field) { + if (field.dataset.fieldtype == "Read Only") { + field.classList.add("hidden"); + } + }); } erpnext.TaxDetail = class TaxDetail { @@ -74,20 +76,20 @@ erpnext.TaxDetail = class TaxDetail { this.qr = frappe.query_report; this.super = { refresh_report: this.qr.refresh_report, - show_footer_message: this.qr.show_footer_message - } + show_footer_message: this.qr.show_footer_message, + }; this.qr.refresh_report = () => this.refresh_report(); this.qr.show_footer_message = () => this.show_footer_message(); } show_footer_message() { // The last thing to run after datatable_render in refresh() this.super.show_footer_message.apply(this.qr); - if (this.qr.report_name !== 'Tax Detail') { + if (this.qr.report_name !== "Tax Detail") { this.show_help(); if (this.loading) { - this.set_section(''); + this.set_section(""); } else { - this.reload_component(''); + this.reload_component(""); } } this.loading = false; @@ -98,16 +100,18 @@ erpnext.TaxDetail = class TaxDetail { // already run within frappe.run_serially this.loading = true; this.super.refresh_report.apply(this.qr); - if (this.qr.report_name !== 'Tax Detail') { - frappe.call({ - method: 'erpnext.accounts.report.tax_detail.tax_detail.get_custom_reports', - args: {name: this.qr.report_name} - }).then((r) => { - const data = JSON.parse(r.message[this.qr.report_name]['json']); - this.create_controls(); - this.sections = data.sections || {}; - this.controls['show_detail'].set_input(data.show_detail); - }); + if (this.qr.report_name !== "Tax Detail") { + frappe + .call({ + method: "erpnext.accounts.report.tax_detail.tax_detail.get_custom_reports", + args: { name: this.qr.report_name }, + }) + .then((r) => { + const data = JSON.parse(r.message[this.qr.report_name]["json"]); + this.create_controls(); + this.sections = data.sections || {}; + this.controls["show_detail"].set_input(data.show_detail); + }); } } load_report() { @@ -118,14 +122,14 @@ erpnext.TaxDetail = class TaxDetail { get_menu_items() { // Replace Save action let new_items = []; - const save = __('Save'); + const save = __("Save"); for (let item of this.qr.menu_items) { if (item.label === save) { new_items.push({ label: save, action: () => this.save_report(), - standard: false + standard: false, }); } else { new_items.push(item); @@ -135,27 +139,29 @@ erpnext.TaxDetail = class TaxDetail { } save_report() { this.check_datatable(); - if (this.qr.report_name !== 'Tax Detail') { - frappe.call({ - method:'erpnext.accounts.report.tax_detail.tax_detail.save_custom_report', - args: { - reference_report: 'Tax Detail', - report_name: this.qr.report_name, - data: { - columns: this.qr.get_visible_columns(), - sections: this.sections, - show_detail: this.controls['show_detail'].get_input_value() - } - }, - freeze: true - }).then((r) => { - this.set_section(''); - }); + if (this.qr.report_name !== "Tax Detail") { + frappe + .call({ + method: "erpnext.accounts.report.tax_detail.tax_detail.save_custom_report", + args: { + reference_report: "Tax Detail", + report_name: this.qr.report_name, + data: { + columns: this.qr.get_visible_columns(), + sections: this.sections, + show_detail: this.controls["show_detail"].get_input_value(), + }, + }, + freeze: true, + }) + .then((r) => { + this.set_section(""); + }); } } check_datatable() { if (!this.qr.datatable) { - frappe.throw(__('Please change the date range to load data first')); + frappe.throw(__("Please change the date range to load data first")); } } set_section(name) { @@ -164,60 +170,62 @@ erpnext.TaxDetail = class TaxDetail { this.sections[name] = {}; } let options = Object.keys(this.sections); - options.unshift(''); - this.controls['section_name'].$wrapper.find("select").empty().add_options(options); - const org_mode = this.qr.get_filter_value('mode'); + options.unshift(""); + this.controls["section_name"].$wrapper.find("select").empty().add_options(options); + const org_mode = this.qr.get_filter_value("mode"); let refresh = false; if (name) { - this.controls['section_name'].set_input(name); - this.qr.set_filter_value('mode', 'edit'); - if (org_mode === 'run') { + this.controls["section_name"].set_input(name); + this.qr.set_filter_value("mode", "edit"); + if (org_mode === "run") { refresh = true; } } else { - this.controls['section_name'].set_input(''); - this.qr.set_filter_value('mode', 'run'); - if (org_mode === 'edit') { + this.controls["section_name"].set_input(""); + this.qr.set_filter_value("mode", "run"); + if (org_mode === "edit") { refresh = true; } } if (refresh) { this.qr.refresh(); } - this.reload_component(''); + this.reload_component(""); } reload_component(component_name) { - const section_name = this.controls['section_name'].get_input_value(); + const section_name = this.controls["section_name"].get_input_value(); if (section_name) { const section = this.sections[section_name]; const component_names = Object.keys(section); - component_names.unshift(''); - this.controls['component'].$wrapper.find("select").empty().add_options(component_names); - this.controls['component'].set_input(component_name); + component_names.unshift(""); + this.controls["component"].$wrapper.find("select").empty().add_options(component_names); + this.controls["component"].set_input(component_name); if (component_name) { - this.controls['component_type'].set_input(section[component_name].type); + this.controls["component_type"].set_input(section[component_name].type); } } else { - this.controls['component'].$wrapper.find("select").empty(); - this.controls['component'].set_input(''); + this.controls["component"].$wrapper.find("select").empty(); + this.controls["component"].set_input(""); } this.set_table_filters(); } set_table_filters() { let filters = {}; - const section_name = this.controls['section_name'].get_input_value(); - const component_name = this.controls['component'].get_input_value(); + const section_name = this.controls["section_name"].get_input_value(); + const component_name = this.controls["component"].get_input_value(); if (section_name && component_name) { const component_type = this.sections[section_name][component_name].type; - if (component_type === 'filter') { - filters = this.sections[section_name][component_name]['filters']; + if (component_type === "filter") { + filters = this.sections[section_name][component_name]["filters"]; } } this.setAppliedFilters(filters); } setAppliedFilters(filters) { if (this.qr.datatable) { - Array.from(this.qr.datatable.header.querySelectorAll('.dt-filter')).map(function setFilters(input) { + Array.from(this.qr.datatable.header.querySelectorAll(".dt-filter")).map(function setFilters( + input + ) { let idx = input.dataset.colIndex; if (filters[idx]) { input.value = filters[idx]; @@ -229,82 +237,89 @@ erpnext.TaxDetail = class TaxDetail { } } delete(name, type) { - if (type === 'section') { + if (type === "section") { delete this.sections[name]; - const new_section = Object.keys(this.sections)[0] || ''; + const new_section = Object.keys(this.sections)[0] || ""; this.set_section(new_section); } - if (type === 'component') { - const cur_section = this.controls['section_name'].get_input_value(); + if (type === "component") { + const cur_section = this.controls["section_name"].get_input_value(); delete this.sections[cur_section][name]; - this.reload_component(''); + this.reload_component(""); } } create_controls() { let controls = {}; // SELECT in data.js - controls['section_name'] = this.qr.page.add_field({ - label: __('Section'), - fieldtype: 'Select', - fieldname: 'section_name', + controls["section_name"] = this.qr.page.add_field({ + label: __("Section"), + fieldtype: "Select", + fieldname: "section_name", change: (e) => { - this.set_section(this.controls['section_name'].get_input_value()); - } + this.set_section(this.controls["section_name"].get_input_value()); + }, }); // BUTTON in button.js - controls['new_section'] = this.qr.page.add_field({ - label: __('New Section'), - fieldtype: 'Button', - fieldname: 'new_section', + controls["new_section"] = this.qr.page.add_field({ + label: __("New Section"), + fieldtype: "Button", + fieldname: "new_section", click: () => { - frappe.prompt({ - label: __('Section Name'), - fieldname: 'name', - fieldtype: 'Data' - }, (values) => { - this.set_section(values.name); - }); - } + frappe.prompt( + { + label: __("Section Name"), + fieldname: "name", + fieldtype: "Data", + }, + (values) => { + this.set_section(values.name); + } + ); + }, }); - controls['delete_section'] = this.qr.page.add_field({ - label: __('Delete Section'), - fieldtype: 'Button', - fieldname: 'delete_section', + controls["delete_section"] = this.qr.page.add_field({ + label: __("Delete Section"), + fieldtype: "Button", + fieldname: "delete_section", click: () => { - let cur_section = this.controls['section_name'].get_input_value(); + let cur_section = this.controls["section_name"].get_input_value(); if (cur_section) { - frappe.confirm(__('Are you sure you want to delete section') + ' ' + cur_section + '?', - () => {this.delete(cur_section, 'section')}); + frappe.confirm( + __("Are you sure you want to delete section") + " " + cur_section + "?", + () => { + this.delete(cur_section, "section"); + } + ); } - } + }, }); - controls['component'] = this.qr.page.add_field({ - label: __('Component'), - fieldtype: 'Select', - fieldname: 'component', + controls["component"] = this.qr.page.add_field({ + label: __("Component"), + fieldtype: "Select", + fieldname: "component", change: (e) => { - this.reload_component(this.controls['component'].get_input_value()); - } + this.reload_component(this.controls["component"].get_input_value()); + }, }); - controls['component_type'] = this.qr.page.add_field({ - label: __('Component Type'), - fieldtype: 'Select', - fieldname: 'component_type', - default: 'filter', + controls["component_type"] = this.qr.page.add_field({ + label: __("Component Type"), + fieldtype: "Select", + fieldname: "component_type", + default: "filter", options: [ - {label: __('Filtered Row Subtotal'), value: 'filter'}, - {label: __('Section Subtotal'), value: 'section'} - ] + { label: __("Filtered Row Subtotal"), value: "filter" }, + { label: __("Section Subtotal"), value: "section" }, + ], }); - controls['add_component'] = this.qr.page.add_field({ - label: __('Add Component'), - fieldtype: 'Button', - fieldname: 'add_component', + controls["add_component"] = this.qr.page.add_field({ + label: __("Add Component"), + fieldtype: "Button", + fieldname: "add_component", click: () => { this.check_datatable(); - let section_name = this.controls['section_name'].get_input_value(); + let section_name = this.controls["section_name"].get_input_value(); if (section_name) { - const component_type = this.controls['component_type'].get_input_value(); + const component_type = this.controls["component_type"].get_input_value(); let idx = 0; const names = Object.keys(this.sections[section_name]); if (names.length > 0) { @@ -312,118 +327,135 @@ erpnext.TaxDetail = class TaxDetail { idx = Math.max(...idxs) + 1; } const filters = this.qr.datatable.columnmanager.getAppliedFilters(); - if (component_type === 'filter') { - const name = 'Filter' + idx.toString(); + if (component_type === "filter") { + const name = "Filter" + idx.toString(); let data = { type: component_type, - filters: filters - } + filters: filters, + }; this.sections[section_name][name] = data; this.reload_component(name); - } else if (component_type === 'section') { + } else if (component_type === "section") { if (filters && Object.keys(filters).length !== 0) { frappe.show_alert({ - message: __('Column filters ignored'), - indicator: 'yellow' + message: __("Column filters ignored"), + indicator: "yellow", }); } let data = { - type: component_type - } - frappe.prompt({ - label: __('Section'), - fieldname: 'section', - fieldtype: 'Select', - options: Object.keys(this.sections) - }, (values) => { - this.sections[section_name][values.section] = data; - this.reload_component(values.section); - }); + type: component_type, + }; + frappe.prompt( + { + label: __("Section"), + fieldname: "section", + fieldtype: "Select", + options: Object.keys(this.sections), + }, + (values) => { + this.sections[section_name][values.section] = data; + this.reload_component(values.section); + } + ); } else { - frappe.throw(__('Please select the Component Type first')); + frappe.throw(__("Please select the Component Type first")); } } else { - frappe.throw(__('Please select the Section first')); + frappe.throw(__("Please select the Section first")); } - } + }, }); - controls['delete_component'] = this.qr.page.add_field({ - label: __('Delete Component'), - fieldtype: 'Button', - fieldname: 'delete_component', + controls["delete_component"] = this.qr.page.add_field({ + label: __("Delete Component"), + fieldtype: "Button", + fieldname: "delete_component", click: () => { - const component = this.controls['component'].get_input_value(); + const component = this.controls["component"].get_input_value(); if (component) { - frappe.confirm(__('Are you sure you want to delete component') + ' ' + component + '?', - () => {this.delete(component, 'component')}); + frappe.confirm( + __("Are you sure you want to delete component") + " " + component + "?", + () => { + this.delete(component, "component"); + } + ); } - } + }, }); - controls['save'] = this.qr.page.add_field({ - label: __('Save & Run'), - fieldtype: 'Button', - fieldname: 'save', + controls["save"] = this.qr.page.add_field({ + label: __("Save & Run"), + fieldtype: "Button", + fieldname: "save", click: () => { this.save_report(); - } + }, }); - controls['show_detail'] = this.qr.page.add_field({ - label: __('Show Detail'), - fieldtype: 'Check', - fieldname: 'show_detail', - default: 1 + controls["show_detail"] = this.qr.page.add_field({ + label: __("Show Detail"), + fieldtype: "Check", + fieldname: "show_detail", + default: 1, }); this.controls = controls; } show_help() { - const help = __('Your custom report is built from General Ledger Entries within the date range. You can add multiple sections to the report using the New Section button. Each component added to a section adds a subset of the data into the specified section. Beware of duplicated data rows. The Filtered Row component type saves the datatable column filters to specify the added data. The Section component type refers to the data in a previously defined section, but it cannot refer to its parent section. The Amount column is summed to give the section subtotal. Use the Show Detail box to see the data rows included in each section in the final report. Once finished, hit Save & Run. Report contributed by'); - this.qr.$report_footer.append('
      ' + __('Help') + `: ${help} Case Solved
      `); + const help = __( + "Your custom report is built from General Ledger Entries within the date range. You can add multiple sections to the report using the New Section button. Each component added to a section adds a subset of the data into the specified section. Beware of duplicated data rows. The Filtered Row component type saves the datatable column filters to specify the added data. The Section component type refers to the data in a previously defined section, but it cannot refer to its parent section. The Amount column is summed to give the section subtotal. Use the Show Detail box to see the data rows included in each section in the final report. Once finished, hit Save & Run. Report contributed by" + ); + this.qr.$report_footer.append( + '
      ' + + __("Help") + + `: ${help} Case Solved
      ` + ); } -} +}; if (!window.taxdetail) { window.taxdetail = new erpnext.TaxDetail(); } function get_reports(cb) { - frappe.call({ - method: 'erpnext.accounts.report.tax_detail.tax_detail.get_custom_reports', - freeze: true - }).then((r) => { - cb(r.message); - }) + frappe + .call({ + method: "erpnext.accounts.report.tax_detail.tax_detail.get_custom_reports", + freeze: true, + }) + .then((r) => { + cb(r.message); + }); } function new_report() { const dialog = new frappe.ui.Dialog({ - title: __('New Report'), + title: __("New Report"), fields: [ { - fieldname: 'report_name', - label: __('Report Name'), - fieldtype: 'Data', - default: 'VAT Return' - } + fieldname: "report_name", + label: __("Report Name"), + fieldtype: "Data", + default: "VAT Return", + }, ], - primary_action_label: __('Create'), + primary_action_label: __("Create"), primary_action: function new_report_pa(values) { - frappe.call({ - method:'erpnext.accounts.report.tax_detail.tax_detail.save_custom_report', - args: { - reference_report: 'Tax Detail', - report_name: values.report_name, - data: { - columns: [], - sections: {}, - show_detail: 1 - } - }, - freeze: true - }).then((r) => { - frappe.set_route('query-report', values.report_name); - }); + frappe + .call({ + method: "erpnext.accounts.report.tax_detail.tax_detail.save_custom_report", + args: { + reference_report: "Tax Detail", + report_name: values.report_name, + data: { + columns: [], + sections: {}, + show_detail: 1, + }, + }, + freeze: true, + }) + .then((r) => { + frappe.set_route("query-report", values.report_name); + }); dialog.hide(); - } + }, }); dialog.show(); } @@ -431,20 +463,20 @@ function new_report() { function load_report() { get_reports(function load_report_cb(reports) { const dialog = new frappe.ui.Dialog({ - title: __('Load Report'), + title: __("Load Report"), fields: [ { - fieldname: 'report_name', - label: __('Report Name'), - fieldtype: 'Select', - options: Object.keys(reports) - } + fieldname: "report_name", + label: __("Report Name"), + fieldtype: "Select", + options: Object.keys(reports), + }, ], - primary_action_label: __('Load'), + primary_action_label: __("Load"), primary_action: function load_report_pa(values) { dialog.hide(); - frappe.set_route('query-report', values.report_name); - } + frappe.set_route("query-report", values.report_name); + }, }); dialog.show(); }); diff --git a/erpnext/accounts/report/tds_computation_summary/tds_computation_summary.js b/erpnext/accounts/report/tds_computation_summary/tds_computation_summary.js index c42028b61f50..054f085e3b76 100644 --- a/erpnext/accounts/report/tds_computation_summary/tds_computation_summary.js +++ b/erpnext/accounts/report/tds_computation_summary/tds_computation_summary.js @@ -3,60 +3,60 @@ /* eslint-disable */ frappe.query_reports["TDS Computation Summary"] = { - "filters": [ + filters: [ { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_default('company') + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_default("company"), }, { - "fieldname":"party_type", - "label": __("Party Type"), - "fieldtype": "Select", - "options": ["Supplier", "Customer"], - "reqd": 1, - "default": "Supplier", - "on_change": function(){ + fieldname: "party_type", + label: __("Party Type"), + fieldtype: "Select", + options: ["Supplier", "Customer"], + reqd: 1, + default: "Supplier", + on_change: function () { frappe.query_report.set_filter_value("party", ""); - } + }, }, { - "fieldname":"party", - "label": __("Party"), - "fieldtype": "Dynamic Link", - "get_options": function() { - var party_type = frappe.query_report.get_filter_value('party_type'); - var party = frappe.query_report.get_filter_value('party'); - if(party && !party_type) { + fieldname: "party", + label: __("Party"), + fieldtype: "Dynamic Link", + get_options: function () { + var party_type = frappe.query_report.get_filter_value("party_type"); + var party = frappe.query_report.get_filter_value("party"); + if (party && !party_type) { frappe.throw(__("Please select Party Type first")); } return party_type; }, - "get_query": function() { + get_query: function () { return { - "filters": { - "tax_withholding_category": ["!=",""], - } - } + filters: { + tax_withholding_category: ["!=", ""], + }, + }; }, }, { - "fieldname":"from_date", - "label": __("From Date"), - "fieldtype": "Date", - "default": frappe.datetime.add_months(frappe.datetime.get_today(), -1), - "reqd": 1, - "width": "60px" + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + default: frappe.datetime.add_months(frappe.datetime.get_today(), -1), + reqd: 1, + width: "60px", }, { - "fieldname":"to_date", - "label": __("To Date"), - "fieldtype": "Date", - "default": frappe.datetime.get_today(), - "reqd": 1, - "width": "60px" - } - ] -} + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + default: frappe.datetime.get_today(), + reqd: 1, + width: "60px", + }, + ], +}; diff --git a/erpnext/accounts/report/tds_payable_monthly/tds_payable_monthly.js b/erpnext/accounts/report/tds_payable_monthly/tds_payable_monthly.js index 6585ea0a293b..cf7e6669596a 100644 --- a/erpnext/accounts/report/tds_payable_monthly/tds_payable_monthly.js +++ b/erpnext/accounts/report/tds_payable_monthly/tds_payable_monthly.js @@ -3,60 +3,60 @@ /* eslint-disable */ frappe.query_reports["TDS Payable Monthly"] = { - "filters": [ + filters: [ { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_default('company') + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_default("company"), }, { - "fieldname":"party_type", - "label": __("Party Type"), - "fieldtype": "Select", - "options": ["Supplier", "Customer"], - "reqd": 1, - "default": "Supplier", - "on_change": function(){ + fieldname: "party_type", + label: __("Party Type"), + fieldtype: "Select", + options: ["Supplier", "Customer"], + reqd: 1, + default: "Supplier", + on_change: function () { frappe.query_report.set_filter_value("party", ""); - } + }, }, { - "fieldname":"party", - "label": __("Party"), - "fieldtype": "Dynamic Link", - "get_options": function() { - var party_type = frappe.query_report.get_filter_value('party_type'); - var party = frappe.query_report.get_filter_value('party'); - if(party && !party_type) { + fieldname: "party", + label: __("Party"), + fieldtype: "Dynamic Link", + get_options: function () { + var party_type = frappe.query_report.get_filter_value("party_type"); + var party = frappe.query_report.get_filter_value("party"); + if (party && !party_type) { frappe.throw(__("Please select Party Type first")); } return party_type; }, - "get_query": function() { + get_query: function () { return { - "filters": { - "tax_withholding_category": ["!=",""], - } - } + filters: { + tax_withholding_category: ["!=", ""], + }, + }; }, }, { - "fieldname":"from_date", - "label": __("From Date"), - "fieldtype": "Date", - "default": frappe.datetime.add_months(frappe.datetime.get_today(), -1), - "reqd": 1, - "width": "60px" + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + default: frappe.datetime.add_months(frappe.datetime.get_today(), -1), + reqd: 1, + width: "60px", }, { - "fieldname":"to_date", - "label": __("To Date"), - "fieldtype": "Date", - "default": frappe.datetime.get_today(), - "reqd": 1, - "width": "60px" - } - ] -} + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + default: frappe.datetime.get_today(), + reqd: 1, + width: "60px", + }, + ], +}; diff --git a/erpnext/accounts/report/trial_balance/trial_balance.js b/erpnext/accounts/report/trial_balance/trial_balance.js index ffb2931e902e..59b366a3dca4 100644 --- a/erpnext/accounts/report/trial_balance/trial_balance.js +++ b/erpnext/accounts/report/trial_balance/trial_balance.js @@ -1,118 +1,118 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -frappe.require("assets/erpnext/js/financial_statements.js", function() { +frappe.require("assets/erpnext/js/financial_statements.js", function () { frappe.query_reports["Trial Balance"] = { - "filters": [ + filters: [ { - "fieldname": "company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_user_default("Company"), - "reqd": 1 + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), + reqd: 1, }, { - "fieldname": "fiscal_year", - "label": __("Fiscal Year"), - "fieldtype": "Link", - "options": "Fiscal Year", - "default": erpnext.utils.get_fiscal_year(frappe.datetime.get_today()), - "reqd": 1, - "on_change": function(query_report) { + fieldname: "fiscal_year", + label: __("Fiscal Year"), + fieldtype: "Link", + options: "Fiscal Year", + default: erpnext.utils.get_fiscal_year(frappe.datetime.get_today()), + reqd: 1, + on_change: function (query_report) { var fiscal_year = query_report.get_values().fiscal_year; if (!fiscal_year) { return; } - frappe.model.with_doc("Fiscal Year", fiscal_year, function(r) { + frappe.model.with_doc("Fiscal Year", fiscal_year, function (r) { var fy = frappe.model.get_doc("Fiscal Year", fiscal_year); frappe.query_report.set_filter_value({ from_date: fy.year_start_date, - to_date: fy.year_end_date + to_date: fy.year_end_date, }); }); - } + }, }, { - "fieldname": "from_date", - "label": __("From Date"), - "fieldtype": "Date", - "default": frappe.defaults.get_user_default("year_start_date"), + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + default: frappe.defaults.get_user_default("year_start_date"), }, { - "fieldname": "to_date", - "label": __("To Date"), - "fieldtype": "Date", - "default": frappe.defaults.get_user_default("year_end_date"), + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + default: frappe.defaults.get_user_default("year_end_date"), }, { - "fieldname": "cost_center", - "label": __("Cost Center"), - "fieldtype": "Link", - "options": "Cost Center", - "get_query": function() { - var company = frappe.query_report.get_filter_value('company'); + fieldname: "cost_center", + label: __("Cost Center"), + fieldtype: "Link", + options: "Cost Center", + get_query: function () { + var company = frappe.query_report.get_filter_value("company"); return { - "doctype": "Cost Center", - "filters": { - "company": company, - } - } - } + doctype: "Cost Center", + filters: { + company: company, + }, + }; + }, }, { - "fieldname": "project", - "label": __("Project"), - "fieldtype": "Link", - "options": "Project" + fieldname: "project", + label: __("Project"), + fieldtype: "Link", + options: "Project", }, { - "fieldname": "finance_book", - "label": __("Finance Book"), - "fieldtype": "Link", - "options": "Finance Book", + fieldname: "finance_book", + label: __("Finance Book"), + fieldtype: "Link", + options: "Finance Book", }, { - "fieldname": "presentation_currency", - "label": __("Currency"), - "fieldtype": "Select", - "options": erpnext.get_presentation_currency_list() + fieldname: "presentation_currency", + label: __("Currency"), + fieldtype: "Select", + options: erpnext.get_presentation_currency_list(), }, { - "fieldname": "with_period_closing_entry", - "label": __("Period Closing Entry"), - "fieldtype": "Check", - "default": 1 + fieldname: "with_period_closing_entry", + label: __("Period Closing Entry"), + fieldtype: "Check", + default: 1, }, { - "fieldname": "show_zero_values", - "label": __("Show zero values"), - "fieldtype": "Check" + fieldname: "show_zero_values", + label: __("Show zero values"), + fieldtype: "Check", }, { - "fieldname": "show_unclosed_fy_pl_balances", - "label": __("Show unclosed fiscal year's P&L balances"), - "fieldtype": "Check" + fieldname: "show_unclosed_fy_pl_balances", + label: __("Show unclosed fiscal year's P&L balances"), + fieldtype: "Check", }, { - "fieldname": "include_default_book_entries", - "label": __("Include Default FB Entries"), - "fieldtype": "Check", - "default": 1 + fieldname: "include_default_book_entries", + label: __("Include Default FB Entries"), + fieldtype: "Check", + default: 1, }, { - "fieldname": "show_net_values", - "label": __("Show net values in opening and closing columns"), - "fieldtype": "Check", - "default": 1 - } + fieldname: "show_net_values", + label: __("Show net values in opening and closing columns"), + fieldtype: "Check", + default: 1, + }, ], - "formatter": erpnext.financial_statements.formatter, - "tree": true, - "name_field": "account", - "parent_field": "parent_account", - "initial_depth": 3 - } + formatter: erpnext.financial_statements.formatter, + tree: true, + name_field: "account", + parent_field: "parent_account", + initial_depth: 3, + }; - erpnext.utils.add_dimensions('Trial Balance', 6); + erpnext.utils.add_dimensions("Trial Balance", 6); }); diff --git a/erpnext/accounts/report/trial_balance_for_party/trial_balance_for_party.js b/erpnext/accounts/report/trial_balance_for_party/trial_balance_for_party.js index 0f7578cdc17a..ab1508bebd05 100644 --- a/erpnext/accounts/report/trial_balance_for_party/trial_balance_for_party.js +++ b/erpnext/accounts/report/trial_balance_for_party/trial_balance_for_party.js @@ -2,88 +2,88 @@ // For license information, please see license.txt frappe.query_reports["Trial Balance for Party"] = { - "filters": [ + filters: [ { - "fieldname": "company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_user_default("Company"), - "reqd": 1 + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), + reqd: 1, }, { - "fieldname": "fiscal_year", - "label": __("Fiscal Year"), - "fieldtype": "Link", - "options": "Fiscal Year", - "default": erpnext.utils.get_fiscal_year(frappe.datetime.get_today()), - "reqd": 1, - "on_change": function(query_report) { + fieldname: "fiscal_year", + label: __("Fiscal Year"), + fieldtype: "Link", + options: "Fiscal Year", + default: erpnext.utils.get_fiscal_year(frappe.datetime.get_today()), + reqd: 1, + on_change: function (query_report) { var fiscal_year = query_report.get_values().fiscal_year; if (!fiscal_year) { return; } - frappe.model.with_doc("Fiscal Year", fiscal_year, function(r) { + frappe.model.with_doc("Fiscal Year", fiscal_year, function (r) { var fy = frappe.model.get_doc("Fiscal Year", fiscal_year); frappe.query_report.set_filter_value({ from_date: fy.year_start_date, - to_date: fy.year_end_date + to_date: fy.year_end_date, }); }); - } + }, }, { - "fieldname": "from_date", - "label": __("From Date"), - "fieldtype": "Date", - "default": frappe.defaults.get_user_default("year_start_date"), + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + default: frappe.defaults.get_user_default("year_start_date"), }, { - "fieldname": "to_date", - "label": __("To Date"), - "fieldtype": "Date", - "default": frappe.defaults.get_user_default("year_end_date"), + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + default: frappe.defaults.get_user_default("year_end_date"), }, { - "fieldname":"party_type", - "label": __("Party Type"), - "fieldtype": "Link", - "options": "Party Type", - "default": "Customer", - "reqd": 1 + fieldname: "party_type", + label: __("Party Type"), + fieldtype: "Link", + options: "Party Type", + default: "Customer", + reqd: 1, }, { - "fieldname":"party", - "label": __("Party"), - "fieldtype": "Dynamic Link", - "get_options": function() { - var party_type = frappe.query_report.get_filter_value('party_type'); - var party = frappe.query_report.get_filter_value('party'); - if(party && !party_type) { + fieldname: "party", + label: __("Party"), + fieldtype: "Dynamic Link", + get_options: function () { + var party_type = frappe.query_report.get_filter_value("party_type"); + var party = frappe.query_report.get_filter_value("party"); + if (party && !party_type) { frappe.throw(__("Please select Party Type first")); } return party_type; - } + }, }, { - "fieldname": "account", - "label": __("Account"), - "fieldtype": "Link", - "options": "Account", - "get_query": function() { - var company = frappe.query_report.get_filter_value('company'); + fieldname: "account", + label: __("Account"), + fieldtype: "Link", + options: "Account", + get_query: function () { + var company = frappe.query_report.get_filter_value("company"); return { - "doctype": "Account", - "filters": { - "company": company, - } - } - } + doctype: "Account", + filters: { + company: company, + }, + }; + }, }, { - "fieldname": "show_zero_values", - "label": __("Show zero values"), - "fieldtype": "Check" - } - ] -} + fieldname: "show_zero_values", + label: __("Show zero values"), + fieldtype: "Check", + }, + ], +}; diff --git a/erpnext/accounts/report/voucher_wise_balance/voucher_wise_balance.js b/erpnext/accounts/report/voucher_wise_balance/voucher_wise_balance.js index 0c148f85fb87..37c506aea2fe 100644 --- a/erpnext/accounts/report/voucher_wise_balance/voucher_wise_balance.js +++ b/erpnext/accounts/report/voucher_wise_balance/voucher_wise_balance.js @@ -3,26 +3,26 @@ /* eslint-disable */ frappe.query_reports["Voucher-wise Balance"] = { - "filters": [ - { - "fieldname": "company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company" - }, - { - "fieldname":"from_date", - "label": __("From Date"), - "fieldtype": "Date", - "default": frappe.datetime.add_months(frappe.datetime.get_today(), -1), - "width": "60px" - }, - { - "fieldname":"to_date", - "label": __("To Date"), - "fieldtype": "Date", - "default": frappe.datetime.get_today(), - "width": "60px" - }, - ] + filters: [ + { + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + }, + { + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + default: frappe.datetime.add_months(frappe.datetime.get_today(), -1), + width: "60px", + }, + { + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + default: frappe.datetime.get_today(), + width: "60px", + }, + ], }; diff --git a/erpnext/assets/doctype/asset/asset.js b/erpnext/assets/doctype/asset/asset.js index 9356484e7a40..49c0b24e4cbc 100644 --- a/erpnext/assets/doctype/asset/asset.js +++ b/erpnext/assets/doctype/asset/asset.js @@ -4,135 +4,174 @@ frappe.provide("erpnext.asset"); frappe.provide("erpnext.accounts.dimensions"); -frappe.ui.form.on('Asset', { - onload: function(frm) { - frm.set_query("item_code", function() { +frappe.ui.form.on("Asset", { + onload: function (frm) { + frm.set_query("item_code", function () { return { - "filters": { - "is_fixed_asset": 1, - "is_stock_item": 0 - } + filters: { + is_fixed_asset: 1, + is_stock_item: 0, + }, }; }); - frm.set_query("warehouse", function() { + frm.set_query("warehouse", function () { return { - "filters": { - "company": frm.doc.company, - "is_group": 0 - } + filters: { + company: frm.doc.company, + is_group: 0, + }, }; }); - frm.set_query("department", function() { + frm.set_query("department", function () { return { - "filters": { - "company": frm.doc.company, - } + filters: { + company: frm.doc.company, + }, }; }); erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype); }, - company: function(frm) { + company: function (frm) { erpnext.accounts.dimensions.update_dimension(frm, frm.doctype); }, - setup: function(frm) { + setup: function (frm) { frm.make_methods = { - 'Asset Movement': () => { + "Asset Movement": () => { frappe.call({ - method: "erpnext.assets.doctype.asset.asset.make_asset_movement", - freeze: true, - args:{ - "assets": [{ name: cur_frm.doc.name }] - }, - callback: function (r) { - if (r.message) { - var doc = frappe.model.sync(r.message)[0]; - frappe.set_route("Form", doc.doctype, doc.name); - } - } - }); + method: "erpnext.assets.doctype.asset.asset.make_asset_movement", + freeze: true, + args: { + assets: [{ name: cur_frm.doc.name }], + }, + callback: function (r) { + if (r.message) { + var doc = frappe.model.sync(r.message)[0]; + frappe.set_route("Form", doc.doctype, doc.name); + } + }, + }); }, - } + }; frm.set_query("purchase_receipt", (doc) => { return { query: "erpnext.controllers.queries.get_purchase_receipts", - filters: { item_code: doc.item_code } - } + filters: { item_code: doc.item_code }, + }; }); frm.set_query("purchase_invoice", (doc) => { return { query: "erpnext.controllers.queries.get_purchase_invoices", - filters: { item_code: doc.item_code } - } + filters: { item_code: doc.item_code }, + }; }); }, - refresh: function(frm) { + refresh: function (frm) { frappe.ui.form.trigger("Asset", "is_existing_asset"); frm.toggle_display("next_depreciation_date", frm.doc.docstatus < 1); frm.events.make_schedules_editable(frm); - if (frm.doc.docstatus==1) { + if (frm.doc.docstatus == 1) { if (in_list(["Submitted", "Partially Depreciated", "Fully Depreciated"], frm.doc.status)) { - frm.add_custom_button(__("Transfer Asset"), function() { - erpnext.asset.transfer_asset(frm); - }, __("Manage")); - - frm.add_custom_button(__("Scrap Asset"), function() { - erpnext.asset.scrap_asset(frm); - }, __("Manage")); - - frm.add_custom_button(__("Sell Asset"), function() { - frm.trigger("make_sales_invoice"); - }, __("Manage")); - - } else if (frm.doc.status=='Scrapped') { - frm.add_custom_button(__("Restore Asset"), function() { - erpnext.asset.restore_asset(frm); - }, __("Manage")); + frm.add_custom_button( + __("Transfer Asset"), + function () { + erpnext.asset.transfer_asset(frm); + }, + __("Manage") + ); + + frm.add_custom_button( + __("Scrap Asset"), + function () { + erpnext.asset.scrap_asset(frm); + }, + __("Manage") + ); + + frm.add_custom_button( + __("Sell Asset"), + function () { + frm.trigger("make_sales_invoice"); + }, + __("Manage") + ); + } else if (frm.doc.status == "Scrapped") { + frm.add_custom_button( + __("Restore Asset"), + function () { + erpnext.asset.restore_asset(frm); + }, + __("Manage") + ); } if (frm.doc.maintenance_required && !frm.doc.maintenance_schedule) { - frm.add_custom_button(__("Maintain Asset"), function() { - frm.trigger("create_asset_maintenance"); - }, __("Manage")); + frm.add_custom_button( + __("Maintain Asset"), + function () { + frm.trigger("create_asset_maintenance"); + }, + __("Manage") + ); } - frm.add_custom_button(__("Repair Asset"), function() { - frm.trigger("create_asset_repair"); - }, __("Manage")); - - frm.add_custom_button(__("Split Asset"), function() { - frm.trigger("split_asset"); - }, __("Manage")); + frm.add_custom_button( + __("Repair Asset"), + function () { + frm.trigger("create_asset_repair"); + }, + __("Manage") + ); - if (frm.doc.status != 'Fully Depreciated') { - frm.add_custom_button(__("Adjust Asset Value"), function() { - frm.trigger("create_asset_value_adjustment"); - }, __("Manage")); + frm.add_custom_button( + __("Split Asset"), + function () { + frm.trigger("split_asset"); + }, + __("Manage") + ); + + if (frm.doc.status != "Fully Depreciated") { + frm.add_custom_button( + __("Adjust Asset Value"), + function () { + frm.trigger("create_asset_value_adjustment"); + }, + __("Manage") + ); } if (!frm.doc.calculate_depreciation) { - frm.add_custom_button(__("Create Depreciation Entry"), function() { - frm.trigger("make_journal_entry"); - }, __("Manage")); + frm.add_custom_button( + __("Create Depreciation Entry"), + function () { + frm.trigger("make_journal_entry"); + }, + __("Manage") + ); } if (frm.doc.purchase_receipt || !frm.doc.is_existing_asset) { - frm.add_custom_button(__("View General Ledger"), function() { - frappe.route_options = { - "voucher_no": frm.doc.name, - "from_date": frm.doc.available_for_use_date, - "to_date": frm.doc.available_for_use_date, - "company": frm.doc.company - }; - frappe.set_route("query-report", "General Ledger"); - }, __("Manage")); + frm.add_custom_button( + __("View General Ledger"), + function () { + frappe.route_options = { + voucher_no: frm.doc.name, + from_date: frm.doc.available_for_use_date, + to_date: frm.doc.available_for_use_date, + company: frm.doc.company, + }; + frappe.set_route("query-report", "General Ledger"); + }, + __("Manage") + ); } if (frm.doc.depr_entry_posting_status === "Failed") { @@ -148,10 +187,10 @@ frappe.ui.form.on('Asset', { frm.toggle_reqd("finance_books", frm.doc.calculate_depreciation); if (frm.doc.is_composite_asset && !frm.doc.capitalized_in) { - $('.primary-action').prop('hidden', true); - $('.form-message').text('Capitalize this asset to confirm'); + $(".primary-action").prop("hidden", true); + $(".form-message").text("Capitalize this asset to confirm"); - frm.add_custom_button(__("Capitalize Asset"), function() { + frm.add_custom_button(__("Capitalize Asset"), function () { frm.trigger("create_asset_capitalization"); }); } @@ -171,70 +210,74 @@ frappe.ui.form.on('Asset', { frm.dashboard.set_headline_alert(alert); }, - toggle_reference_doc: function(frm) { + toggle_reference_doc: function (frm) { if (frm.doc.purchase_receipt && frm.doc.purchase_invoice && frm.doc.docstatus === 1) { - frm.set_df_property('purchase_invoice', 'read_only', 1); - frm.set_df_property('purchase_receipt', 'read_only', 1); - } - else if (frm.doc.is_existing_asset || frm.doc.is_composite_asset) { - frm.toggle_reqd('purchase_receipt', 0); - frm.toggle_reqd('purchase_invoice', 0); - } - else if (frm.doc.purchase_receipt) { + frm.set_df_property("purchase_invoice", "read_only", 1); + frm.set_df_property("purchase_receipt", "read_only", 1); + } else if (frm.doc.is_existing_asset || frm.doc.is_composite_asset) { + frm.toggle_reqd("purchase_receipt", 0); + frm.toggle_reqd("purchase_invoice", 0); + } else if (frm.doc.purchase_receipt) { // if purchase receipt link is set then set PI disabled - frm.toggle_reqd('purchase_invoice', 0); - frm.set_df_property('purchase_invoice', 'read_only', 1); - } - else if (frm.doc.purchase_invoice) { + frm.toggle_reqd("purchase_invoice", 0); + frm.set_df_property("purchase_invoice", "read_only", 1); + } else if (frm.doc.purchase_invoice) { // if purchase invoice link is set then set PR disabled - frm.toggle_reqd('purchase_receipt', 0); - frm.set_df_property('purchase_receipt', 'read_only', 1); - } - else { - frm.toggle_reqd('purchase_receipt', 1); - frm.set_df_property('purchase_receipt', 'read_only', 0); - frm.toggle_reqd('purchase_invoice', 1); - frm.set_df_property('purchase_invoice', 'read_only', 0); + frm.toggle_reqd("purchase_receipt", 0); + frm.set_df_property("purchase_receipt", "read_only", 1); + } else { + frm.toggle_reqd("purchase_receipt", 1); + frm.set_df_property("purchase_receipt", "read_only", 0); + frm.toggle_reqd("purchase_invoice", 1); + frm.set_df_property("purchase_invoice", "read_only", 0); } }, - make_journal_entry: function(frm) { + make_journal_entry: function (frm) { frappe.call({ method: "erpnext.assets.doctype.asset.asset.make_journal_entry", args: { - asset_name: frm.doc.name + asset_name: frm.doc.name, }, - callback: function(r) { + callback: function (r) { if (r.message) { var doclist = frappe.model.sync(r.message); frappe.set_route("Form", doclist[0].doctype, doclist[0].name); } - } - }) + }, + }); }, - setup_chart: async function(frm) { - if(frm.doc.finance_books.length > 1) { - return + setup_chart: async function (frm) { + if (frm.doc.finance_books.length > 1) { + return; } - var x_intervals = [frappe.format(frm.doc.purchase_date, { fieldtype: 'Date' })]; + var x_intervals = [frappe.format(frm.doc.purchase_date, { fieldtype: "Date" })]; var asset_values = [frm.doc.gross_purchase_amount]; - if(frm.doc.calculate_depreciation) { - if(frm.doc.opening_accumulated_depreciation) { + if (frm.doc.calculate_depreciation) { + if (frm.doc.opening_accumulated_depreciation) { var depreciation_date = frappe.datetime.add_months( frm.doc.finance_books[0].depreciation_start_date, -1 * frm.doc.finance_books[0].frequency_of_depreciation ); - x_intervals.push(frappe.format(depreciation_date, { fieldtype: 'Date' })); - asset_values.push(flt(frm.doc.gross_purchase_amount - frm.doc.opening_accumulated_depreciation, precision('gross_purchase_amount'))); + x_intervals.push(frappe.format(depreciation_date, { fieldtype: "Date" })); + asset_values.push( + flt( + frm.doc.gross_purchase_amount - frm.doc.opening_accumulated_depreciation, + precision("gross_purchase_amount") + ) + ); } - $.each(frm.doc.schedules || [], function(i, v) { - x_intervals.push(frappe.format(v.schedule_date, { fieldtype: 'Date' })); - var asset_value = flt(frm.doc.gross_purchase_amount - v.accumulated_depreciation_amount, precision('gross_purchase_amount')); - if(v.journal_entry) { + $.each(frm.doc.schedules || [], function (i, v) { + x_intervals.push(frappe.format(v.schedule_date, { fieldtype: "Date" })); + var asset_value = flt( + frm.doc.gross_purchase_amount - v.accumulated_depreciation_amount, + precision("gross_purchase_amount") + ); + if (v.journal_entry) { asset_values.push(asset_value); } else { if (in_list(["Scrapped", "Sold"], frm.doc.status)) { @@ -245,25 +288,32 @@ frappe.ui.form.on('Asset', { } }); } else { - if(frm.doc.opening_accumulated_depreciation) { - x_intervals.push(frappe.format(frm.doc.creation.split(" ")[0], { fieldtype: 'Date' })); - asset_values.push(flt(frm.doc.gross_purchase_amount - frm.doc.opening_accumulated_depreciation, precision('gross_purchase_amount'))); + if (frm.doc.opening_accumulated_depreciation) { + x_intervals.push(frappe.format(frm.doc.creation.split(" ")[0], { fieldtype: "Date" })); + asset_values.push( + flt( + frm.doc.gross_purchase_amount - frm.doc.opening_accumulated_depreciation, + precision("gross_purchase_amount") + ) + ); } - let depr_entries = (await frappe.call({ - method: "get_manual_depreciation_entries", - doc: frm.doc, - })).message; - - $.each(depr_entries || [], function(i, v) { - x_intervals.push(frappe.format(v.posting_date, { fieldtype: 'Date' })); - let last_asset_value = asset_values[asset_values.length - 1] - asset_values.push(flt(last_asset_value - v.value, precision('gross_purchase_amount'))); + let depr_entries = ( + await frappe.call({ + method: "get_manual_depreciation_entries", + doc: frm.doc, + }) + ).message; + + $.each(depr_entries || [], function (i, v) { + x_intervals.push(frappe.format(v.posting_date, { fieldtype: "Date" })); + let last_asset_value = asset_values[asset_values.length - 1]; + asset_values.push(flt(last_asset_value - v.value, precision("gross_purchase_amount"))); }); } - if(in_list(["Scrapped", "Sold"], frm.doc.status)) { - x_intervals.push(frappe.format(frm.doc.disposal_date, { fieldtype: 'Date' })); + if (in_list(["Scrapped", "Sold"], frm.doc.status)) { + x_intervals.push(frappe.format(frm.doc.disposal_date, { fieldtype: "Date" })); asset_values.push(0); } @@ -271,62 +321,65 @@ frappe.ui.form.on('Asset', { title: "Asset Value", data: { labels: x_intervals, - datasets: [{ - color: 'green', - values: asset_values, - formatted: asset_values.map(d => d?.toFixed(2)) - }] + datasets: [ + { + color: "green", + values: asset_values, + formatted: asset_values.map((d) => d?.toFixed(2)), + }, + ], }, - type: 'line' + type: "line", }); }, - - item_code: function(frm) { - if(frm.doc.item_code && frm.doc.calculate_depreciation && frm.doc.gross_purchase_amount) { - frm.trigger('set_finance_book'); + item_code: function (frm) { + if (frm.doc.item_code && frm.doc.calculate_depreciation && frm.doc.gross_purchase_amount) { + frm.trigger("set_finance_book"); } else { - frm.set_value('finance_books', []); + frm.set_value("finance_books", []); } }, - set_finance_book: function(frm) { + set_finance_book: function (frm) { frappe.call({ method: "erpnext.assets.doctype.asset.asset.get_item_details", args: { item_code: frm.doc.item_code, asset_category: frm.doc.asset_category, - gross_purchase_amount: frm.doc.gross_purchase_amount + gross_purchase_amount: frm.doc.gross_purchase_amount, }, - callback: function(r, rt) { - if(r.message) { - frm.set_value('finance_books', r.message); + callback: function (r, rt) { + if (r.message) { + frm.set_value("finance_books", r.message); } - } - }) + }, + }); }, - is_existing_asset: function(frm) { + is_existing_asset: function (frm) { frm.trigger("toggle_reference_doc"); }, - is_composite_asset: function(frm) { - if(frm.doc.is_composite_asset) { - frm.set_value('gross_purchase_amount', 0); - frm.set_df_property('gross_purchase_amount', 'read_only', 1); + is_composite_asset: function (frm) { + if (frm.doc.is_composite_asset) { + frm.set_value("gross_purchase_amount", 0); + frm.set_df_property("gross_purchase_amount", "read_only", 1); } else { - frm.set_df_property('gross_purchase_amount', 'read_only', 0); + frm.set_df_property("gross_purchase_amount", "read_only", 0); } frm.trigger("toggle_reference_doc"); }, - make_schedules_editable: function(frm) { + make_schedules_editable: function (frm) { if (frm.doc.finance_books && frm.doc.finance_books.length) { - var is_manual_hence_editable = frm.doc.finance_books.filter(d => d.depreciation_method == "Manual").length > 0 - ? true : false; - var is_shift_hence_editable = frm.doc.finance_books.filter(d => d.shift_based).length > 0 - ? true : false; + var is_manual_hence_editable = + frm.doc.finance_books.filter((d) => d.depreciation_method == "Manual").length > 0 + ? true + : false; + var is_shift_hence_editable = + frm.doc.finance_books.filter((d) => d.shift_based).length > 0 ? true : false; frm.toggle_enable("schedules", is_manual_hence_editable || is_shift_hence_editable); frm.fields_dict["schedules"].grid.toggle_enable("schedule_date", is_manual_hence_editable); @@ -335,95 +388,95 @@ frappe.ui.form.on('Asset', { } }, - make_sales_invoice: function(frm) { + make_sales_invoice: function (frm) { frappe.call({ args: { - "asset": frm.doc.name, - "item_code": frm.doc.item_code, - "company": frm.doc.company, - "serial_no": frm.doc.serial_no + asset: frm.doc.name, + item_code: frm.doc.item_code, + company: frm.doc.company, + serial_no: frm.doc.serial_no, }, method: "erpnext.assets.doctype.asset.asset.make_sales_invoice", - callback: function(r) { + callback: function (r) { var doclist = frappe.model.sync(r.message); frappe.set_route("Form", doclist[0].doctype, doclist[0].name); - } - }) + }, + }); }, - create_asset_maintenance: function(frm) { + create_asset_maintenance: function (frm) { frappe.call({ args: { - "asset": frm.doc.name, - "item_code": frm.doc.item_code, - "item_name": frm.doc.item_name, - "asset_category": frm.doc.asset_category, - "company": frm.doc.company + asset: frm.doc.name, + item_code: frm.doc.item_code, + item_name: frm.doc.item_name, + asset_category: frm.doc.asset_category, + company: frm.doc.company, }, method: "erpnext.assets.doctype.asset.asset.create_asset_maintenance", - callback: function(r) { + callback: function (r) { var doclist = frappe.model.sync(r.message); frappe.set_route("Form", doclist[0].doctype, doclist[0].name); - } - }) + }, + }); }, - create_asset_repair: function(frm) { + create_asset_repair: function (frm) { frappe.call({ args: { - "asset": frm.doc.name, - "asset_name": frm.doc.asset_name + asset: frm.doc.name, + asset_name: frm.doc.asset_name, }, method: "erpnext.assets.doctype.asset.asset.create_asset_repair", - callback: function(r) { + callback: function (r) { var doclist = frappe.model.sync(r.message); frappe.set_route("Form", doclist[0].doctype, doclist[0].name); - } + }, }); }, - create_asset_capitalization: function(frm) { + create_asset_capitalization: function (frm) { frappe.call({ args: { - "asset": frm.doc.name, + asset: frm.doc.name, }, method: "erpnext.assets.doctype.asset.asset.create_asset_capitalization", - callback: function(r) { + callback: function (r) { var doclist = frappe.model.sync(r.message); frappe.set_route("Form", doclist[0].doctype, doclist[0].name); - } + }, }); }, - split_asset: function(frm) { - const title = __('Split Asset'); + split_asset: function (frm) { + const title = __("Split Asset"); const fields = [ { - fieldname: 'split_qty', - fieldtype: 'Int', - label: __('Split Qty'), - reqd: 1 - } + fieldname: "split_qty", + fieldtype: "Int", + label: __("Split Qty"), + reqd: 1, + }, ]; let dialog = new frappe.ui.Dialog({ title: title, - fields: fields + fields: fields, }); - dialog.set_primary_action(__('Split'), function() { + dialog.set_primary_action(__("Split"), function () { const dialog_data = dialog.get_values(); frappe.call({ args: { - "asset_name": frm.doc.name, - "split_qty": cint(dialog_data.split_qty) + asset_name: frm.doc.name, + split_qty: cint(dialog_data.split_qty), }, method: "erpnext.assets.doctype.asset.asset.split_asset", - callback: function(r) { + callback: function (r) { let doclist = frappe.model.sync(r.message); frappe.set_route("Form", doclist[0].doctype, doclist[0].name); - } + }, }); dialog.hide(); @@ -432,23 +485,23 @@ frappe.ui.form.on('Asset', { dialog.show(); }, - create_asset_value_adjustment: function(frm) { + create_asset_value_adjustment: function (frm) { frappe.call({ args: { - "asset": frm.doc.name, - "asset_category": frm.doc.asset_category, - "company": frm.doc.company + asset: frm.doc.name, + asset_category: frm.doc.asset_category, + company: frm.doc.company, }, method: "erpnext.assets.doctype.asset.asset.create_asset_value_adjustment", freeze: 1, - callback: function(r) { + callback: function (r) { var doclist = frappe.model.sync(r.message); frappe.set_route("Form", doclist[0].doctype, doclist[0].name); - } - }) + }, + }); }, - calculate_depreciation: function(frm) { + calculate_depreciation: function (frm) { frm.toggle_reqd("finance_books", frm.doc.calculate_depreciation); if (frm.doc.item_code && frm.doc.calculate_depreciation && frm.doc.gross_purchase_amount) { frm.trigger("set_finance_book"); @@ -457,243 +510,293 @@ frappe.ui.form.on('Asset', { } }, - gross_purchase_amount: function(frm) { + gross_purchase_amount: function (frm) { if (frm.doc.finance_books) { - frm.doc.finance_books.forEach(d => { + frm.doc.finance_books.forEach((d) => { frm.events.set_depreciation_rate(frm, d); - }) + }); } }, purchase_receipt: (frm) => { - frm.trigger('toggle_reference_doc'); + frm.trigger("toggle_reference_doc"); if (frm.doc.purchase_receipt) { if (frm.doc.item_code) { - frappe.db.get_doc('Purchase Receipt', frm.doc.purchase_receipt).then(pr_doc => { - frm.events.set_values_from_purchase_doc(frm, 'Purchase Receipt', pr_doc) + frappe.db.get_doc("Purchase Receipt", frm.doc.purchase_receipt).then((pr_doc) => { + frm.events.set_values_from_purchase_doc(frm, "Purchase Receipt", pr_doc); }); } else { - frm.set_value('purchase_receipt', ''); + frm.set_value("purchase_receipt", ""); frappe.msgprint({ - title: __('Not Allowed'), - message: __("Please select Item Code first") + title: __("Not Allowed"), + message: __("Please select Item Code first"), }); } } }, purchase_invoice: (frm) => { - frm.trigger('toggle_reference_doc'); + frm.trigger("toggle_reference_doc"); if (frm.doc.purchase_invoice) { if (frm.doc.item_code) { - frappe.db.get_doc('Purchase Invoice', frm.doc.purchase_invoice).then(pi_doc => { - frm.events.set_values_from_purchase_doc(frm, 'Purchase Invoice', pi_doc) + frappe.db.get_doc("Purchase Invoice", frm.doc.purchase_invoice).then((pi_doc) => { + frm.events.set_values_from_purchase_doc(frm, "Purchase Invoice", pi_doc); }); } else { - frm.set_value('purchase_invoice', ''); + frm.set_value("purchase_invoice", ""); frappe.msgprint({ - title: __('Not Allowed'), - message: __("Please select Item Code first") + title: __("Not Allowed"), + message: __("Please select Item Code first"), }); } } }, - set_values_from_purchase_doc: function(frm, doctype, purchase_doc) { - frm.set_value('company', purchase_doc.company); + set_values_from_purchase_doc: function (frm, doctype, purchase_doc) { + frm.set_value("company", purchase_doc.company); if (purchase_doc.bill_date) { - frm.set_value('purchase_date', purchase_doc.bill_date); + frm.set_value("purchase_date", purchase_doc.bill_date); } else { - frm.set_value('purchase_date', purchase_doc.posting_date); + frm.set_value("purchase_date", purchase_doc.posting_date); } if (!frm.doc.is_existing_asset && !frm.doc.available_for_use_date) { - frm.set_value('available_for_use_date', frm.doc.purchase_date); + frm.set_value("available_for_use_date", frm.doc.purchase_date); } - const item = purchase_doc.items.find(item => item.item_code === frm.doc.item_code); + const item = purchase_doc.items.find((item) => item.item_code === frm.doc.item_code); if (!item) { - doctype_field = frappe.scrub(doctype) - frm.set_value(doctype_field, ''); + doctype_field = frappe.scrub(doctype); + frm.set_value(doctype_field, ""); frappe.msgprint({ - title: __('Invalid {0}', [__(doctype)]), - message: __('The selected {0} does not contain the selected Asset Item.', [__(doctype)]), - indicator: 'red' + title: __("Invalid {0}", [__(doctype)]), + message: __("The selected {0} does not contain the selected Asset Item.", [__(doctype)]), + indicator: "red", }); } - frappe.db.get_value('Item', item.item_code, 'is_grouped_asset', (r) => { + frappe.db.get_value("Item", item.item_code, "is_grouped_asset", (r) => { var asset_quantity = r.is_grouped_asset ? item.qty : 1; - var purchase_amount = flt(item.valuation_rate * asset_quantity, precision('gross_purchase_amount')); - - frm.set_value('gross_purchase_amount', purchase_amount); - frm.set_value('purchase_receipt_amount', purchase_amount); - frm.set_value('asset_quantity', asset_quantity); - frm.set_value('cost_center', item.cost_center || purchase_doc.cost_center); - if(item.asset_location) { frm.set_value('location', item.asset_location); } + var purchase_amount = flt( + item.valuation_rate * asset_quantity, + precision("gross_purchase_amount") + ); + + frm.set_value("gross_purchase_amount", purchase_amount); + frm.set_value("purchase_receipt_amount", purchase_amount); + frm.set_value("asset_quantity", asset_quantity); + frm.set_value("cost_center", item.cost_center || purchase_doc.cost_center); + if (item.asset_location) { + frm.set_value("location", item.asset_location); + } }); }, - set_depreciation_rate: function(frm, row) { - if (row.total_number_of_depreciations && row.frequency_of_depreciation - && row.expected_value_after_useful_life) { + set_depreciation_rate: function (frm, row) { + if ( + row.total_number_of_depreciations && + row.frequency_of_depreciation && + row.expected_value_after_useful_life + ) { frappe.call({ method: "get_depreciation_rate", doc: frm.doc, args: row, - callback: function(r) { + callback: function (r) { if (r.message) { frappe.flags.dont_change_rate = true; - frappe.model.set_value(row.doctype, row.name, - "rate_of_depreciation", flt(r.message, precision("rate_of_depreciation", row))); + frappe.model.set_value( + row.doctype, + row.name, + "rate_of_depreciation", + flt(r.message, precision("rate_of_depreciation", row)) + ); } - } + }, }); } }, - set_salvage_value_percentage_or_expected_value_after_useful_life: function(frm, row, salvage_value_percentage_changed, expected_value_after_useful_life_changed) { + set_salvage_value_percentage_or_expected_value_after_useful_life: function ( + frm, + row, + salvage_value_percentage_changed, + expected_value_after_useful_life_changed + ) { if (expected_value_after_useful_life_changed) { frappe.flags.from_set_salvage_value_percentage_or_expected_value_after_useful_life = true; - const new_salvage_value_percentage = flt((row.expected_value_after_useful_life * 100) / frm.doc.gross_purchase_amount, precision("salvage_value_percentage", row)); - frappe.model.set_value(row.doctype, row.name, "salvage_value_percentage", new_salvage_value_percentage); + const new_salvage_value_percentage = flt( + (row.expected_value_after_useful_life * 100) / frm.doc.gross_purchase_amount, + precision("salvage_value_percentage", row) + ); + frappe.model.set_value( + row.doctype, + row.name, + "salvage_value_percentage", + new_salvage_value_percentage + ); frappe.flags.from_set_salvage_value_percentage_or_expected_value_after_useful_life = false; } else if (salvage_value_percentage_changed) { frappe.flags.from_set_salvage_value_percentage_or_expected_value_after_useful_life = true; - const new_expected_value_after_useful_life = flt(frm.doc.gross_purchase_amount * (row.salvage_value_percentage / 100), precision('gross_purchase_amount')); - frappe.model.set_value(row.doctype, row.name, "expected_value_after_useful_life", new_expected_value_after_useful_life); + const new_expected_value_after_useful_life = flt( + frm.doc.gross_purchase_amount * (row.salvage_value_percentage / 100), + precision("gross_purchase_amount") + ); + frappe.model.set_value( + row.doctype, + row.name, + "expected_value_after_useful_life", + new_expected_value_after_useful_life + ); frappe.flags.from_set_salvage_value_percentage_or_expected_value_after_useful_life = false; } }, }); -frappe.ui.form.on('Asset Finance Book', { - depreciation_method: function(frm, cdt, cdn) { +frappe.ui.form.on("Asset Finance Book", { + depreciation_method: function (frm, cdt, cdn) { const row = locals[cdt][cdn]; frm.events.set_depreciation_rate(frm, row); frm.events.make_schedules_editable(frm); }, - expected_value_after_useful_life: function(frm, cdt, cdn) { + expected_value_after_useful_life: function (frm, cdt, cdn) { const row = locals[cdt][cdn]; if (!frappe.flags.from_set_salvage_value_percentage_or_expected_value_after_useful_life) { - frm.events.set_salvage_value_percentage_or_expected_value_after_useful_life(frm, row, false, true); + frm.events.set_salvage_value_percentage_or_expected_value_after_useful_life( + frm, + row, + false, + true + ); } frm.events.set_depreciation_rate(frm, row); }, - salvage_value_percentage: function(frm, cdt, cdn) { + salvage_value_percentage: function (frm, cdt, cdn) { const row = locals[cdt][cdn]; if (!frappe.flags.from_set_salvage_value_percentage_or_expected_value_after_useful_life) { - frm.events.set_salvage_value_percentage_or_expected_value_after_useful_life(frm, row, true, false); + frm.events.set_salvage_value_percentage_or_expected_value_after_useful_life( + frm, + row, + true, + false + ); } }, - frequency_of_depreciation: function(frm, cdt, cdn) { + frequency_of_depreciation: function (frm, cdt, cdn) { const row = locals[cdt][cdn]; frm.events.set_depreciation_rate(frm, row); }, - total_number_of_depreciations: function(frm, cdt, cdn) { + total_number_of_depreciations: function (frm, cdt, cdn) { const row = locals[cdt][cdn]; frm.events.set_depreciation_rate(frm, row); }, - rate_of_depreciation: function(frm, cdt, cdn) { - if(!frappe.flags.dont_change_rate) { + rate_of_depreciation: function (frm, cdt, cdn) { + if (!frappe.flags.dont_change_rate) { frappe.model.set_value(cdt, cdn, "expected_value_after_useful_life", 0); } frappe.flags.dont_change_rate = false; }, - depreciation_start_date: function(frm, cdt, cdn) { + depreciation_start_date: function (frm, cdt, cdn) { const book = locals[cdt][cdn]; - if (frm.doc.available_for_use_date && book.depreciation_start_date == frm.doc.available_for_use_date) { + if ( + frm.doc.available_for_use_date && + book.depreciation_start_date == frm.doc.available_for_use_date + ) { frappe.msgprint(__("Depreciation Posting Date should not be equal to Available for Use Date.")); book.depreciation_start_date = ""; frm.refresh_field("finance_books"); } - } + }, }); -frappe.ui.form.on('Depreciation Schedule', { - make_depreciation_entry: function(frm, cdt, cdn) { +frappe.ui.form.on("Depreciation Schedule", { + make_depreciation_entry: function (frm, cdt, cdn) { var row = locals[cdt][cdn]; if (!row.journal_entry) { frappe.call({ method: "erpnext.assets.doctype.asset.depreciation.make_depreciation_entry", args: { - "asset_name": frm.doc.name, - "date": row.schedule_date + asset_name: frm.doc.name, + date: row.schedule_date, }, - callback: function(r) { + callback: function (r) { frappe.model.sync(r.message); frm.refresh(); - } - }) + }, + }); } }, - depreciation_amount: function(frm, cdt, cdn) { + depreciation_amount: function (frm, cdt, cdn) { erpnext.asset.set_accumulated_depreciation(frm, locals[cdt][cdn].finance_book_id); - } - + }, }); -erpnext.asset.set_accumulated_depreciation = function(frm, finance_book_id) { +erpnext.asset.set_accumulated_depreciation = function (frm, finance_book_id) { var depreciation_method = frm.doc.finance_books[Number(finance_book_id) - 1].depreciation_method; - if(depreciation_method != "Manual") return; + if (depreciation_method != "Manual") return; var accumulated_depreciation = flt(frm.doc.opening_accumulated_depreciation); - $.each(frm.doc.schedules || [], function(i, row) { + $.each(frm.doc.schedules || [], function (i, row) { if (row.finance_book_id === finance_book_id) { - accumulated_depreciation += flt(row.depreciation_amount); - frappe.model.set_value(row.doctype, row.name, "accumulated_depreciation_amount", accumulated_depreciation); - }; - }) + accumulated_depreciation += flt(row.depreciation_amount); + frappe.model.set_value( + row.doctype, + row.name, + "accumulated_depreciation_amount", + accumulated_depreciation + ); + } + }); }; -erpnext.asset.scrap_asset = function(frm) { +erpnext.asset.scrap_asset = function (frm) { frappe.confirm(__("Do you really want to scrap this asset?"), function () { frappe.call({ args: { - "asset_name": frm.doc.name + asset_name: frm.doc.name, }, method: "erpnext.assets.doctype.asset.depreciation.scrap_asset", - callback: function(r) { + callback: function (r) { cur_frm.reload_doc(); - } - }) - }) + }, + }); + }); }; -erpnext.asset.restore_asset = function(frm) { +erpnext.asset.restore_asset = function (frm) { frappe.confirm(__("Do you really want to restore this scrapped asset?"), function () { frappe.call({ args: { - "asset_name": frm.doc.name + asset_name: frm.doc.name, }, method: "erpnext.assets.doctype.asset.depreciation.restore_asset", - callback: function(r) { + callback: function (r) { cur_frm.reload_doc(); - } - }) - }) + }, + }); + }); }; -erpnext.asset.transfer_asset = function() { +erpnext.asset.transfer_asset = function () { frappe.call({ method: "erpnext.assets.doctype.asset.asset.make_asset_movement", freeze: true, - args:{ - "assets": [{ name: cur_frm.doc.name }], - "purpose": "Transfer" + args: { + assets: [{ name: cur_frm.doc.name }], + purpose: "Transfer", }, callback: function (r) { if (r.message) { var doc = frappe.model.sync(r.message)[0]; frappe.set_route("Form", doc.doctype, doc.name); } - } + }, }); }; diff --git a/erpnext/assets/doctype/asset/asset_list.js b/erpnext/assets/doctype/asset/asset_list.js index 5f53b005aafe..712958adcfc5 100644 --- a/erpnext/assets/doctype/asset/asset_list.js +++ b/erpnext/assets/doctype/asset/asset_list.js @@ -1,56 +1,46 @@ -frappe.listview_settings['Asset'] = { - add_fields: ['status'], +frappe.listview_settings["Asset"] = { + add_fields: ["status"], get_indicator: function (doc) { if (doc.status === "Fully Depreciated") { return [__("Fully Depreciated"), "green", "status,=,Fully Depreciated"]; - } else if (doc.status === "Partially Depreciated") { return [__("Partially Depreciated"), "grey", "status,=,Partially Depreciated"]; - } else if (doc.status === "Sold") { return [__("Sold"), "green", "status,=,Sold"]; - } else if (["Capitalized", "Decapitalized"].includes(doc.status)) { return [__(doc.status), "grey", "status,=," + doc.status]; - } else if (doc.status === "Scrapped") { return [__("Scrapped"), "grey", "status,=,Scrapped"]; - } else if (doc.status === "In Maintenance") { return [__("In Maintenance"), "orange", "status,=,In Maintenance"]; - } else if (doc.status === "Out of Order") { return [__("Out of Order"), "grey", "status,=,Out of Order"]; - } else if (doc.status === "Issue") { return [__("Issue"), "orange", "status,=,Issue"]; - } else if (doc.status === "Receipt") { return [__("Receipt"), "green", "status,=,Receipt"]; - } else if (doc.status === "Submitted") { return [__("Submitted"), "blue", "status,=,Submitted"]; - } else if (doc.status === "Draft") { return [__("Draft"), "red", "status,=,Draft"]; } }, - onload: function(me) { - me.page.add_action_item(__("Make Asset Movement"), function() { + onload: function (me) { + me.page.add_action_item(__("Make Asset Movement"), function () { const assets = me.get_checked_items(); frappe.call({ method: "erpnext.assets.doctype.asset.asset.make_asset_movement", freeze: true, - args:{ - "assets": assets + args: { + assets: assets, }, callback: function (r) { if (r.message) { var doc = frappe.model.sync(r.message)[0]; frappe.set_route("Form", doc.doctype, doc.name); } - } + }, }); }); }, -} +}; diff --git a/erpnext/assets/doctype/asset_capitalization/asset_capitalization.js b/erpnext/assets/doctype/asset_capitalization/asset_capitalization.js index e3e57ec87b22..6ac6289c8372 100644 --- a/erpnext/assets/doctype/asset_capitalization/asset_capitalization.js +++ b/erpnext/assets/doctype/asset_capitalization/asset_capitalization.js @@ -3,7 +3,6 @@ frappe.provide("erpnext.assets"); - erpnext.assets.AssetCapitalization = class AssetCapitalization extends erpnext.stock.StockController { setup() { this.setup_posting_date_time_check(); @@ -17,7 +16,10 @@ erpnext.assets.AssetCapitalization = class AssetCapitalization extends erpnext.s refresh() { this.show_general_ledger(); - if ((this.frm.doc.stock_items && this.frm.doc.stock_items.length) || !this.frm.doc.target_is_fixed_asset) { + if ( + (this.frm.doc.stock_items && this.frm.doc.stock_items.length) || + !this.frm.doc.target_is_fixed_asset + ) { this.show_stock_ledger(); } @@ -32,68 +34,77 @@ erpnext.assets.AssetCapitalization = class AssetCapitalization extends erpnext.s me.setup_warehouse_query(); - me.frm.set_query("target_item_code", function() { + me.frm.set_query("target_item_code", function () { if (me.frm.doc.entry_type == "Capitalization") { - return erpnext.queries.item({"is_stock_item": 0, "is_fixed_asset": 1}); + return erpnext.queries.item({ is_stock_item: 0, is_fixed_asset: 1 }); } else { - return erpnext.queries.item({"is_stock_item": 1, "is_fixed_asset": 0}); + return erpnext.queries.item({ is_stock_item: 1, is_fixed_asset: 0 }); } }); - me.frm.set_query("target_asset", function() { + me.frm.set_query("target_asset", function () { return { - filters: {'is_composite_asset': 1, 'docstatus': 0 } - } + filters: { is_composite_asset: 1, docstatus: 0 }, + }; }); - me.frm.set_query("asset", "asset_items", function() { + me.frm.set_query("asset", "asset_items", function () { var filters = { - 'status': ["not in", ["Draft", "Scrapped", "Sold", "Capitalized", "Decapitalized"]], - 'docstatus': 1 + status: ["not in", ["Draft", "Scrapped", "Sold", "Capitalized", "Decapitalized"]], + docstatus: 1, }; if (me.frm.doc.target_asset) { - filters['name'] = ['!=', me.frm.doc.target_asset]; + filters["name"] = ["!=", me.frm.doc.target_asset]; } return { - filters: filters + filters: filters, }; }); - me.frm.set_query("item_code", "stock_items", function() { - return erpnext.queries.item({"is_stock_item": 1}); + me.frm.set_query("item_code", "stock_items", function () { + return erpnext.queries.item({ is_stock_item: 1 }); }); - me.frm.set_query("item_code", "service_items", function() { - return erpnext.queries.item({"is_stock_item": 0, "is_fixed_asset": 0}); + me.frm.set_query("item_code", "service_items", function () { + return erpnext.queries.item({ is_stock_item: 0, is_fixed_asset: 0 }); }); - me.frm.set_query('batch_no', 'stock_items', function(doc, cdt, cdn) { + me.frm.set_query("batch_no", "stock_items", function (doc, cdt, cdn) { var item = locals[cdt][cdn]; if (!item.item_code) { frappe.throw(__("Please enter Item Code to get Batch Number")); } else { var filters = { - 'item_code': item.item_code, - 'posting_date': me.frm.doc.posting_date || frappe.datetime.nowdate(), - 'warehouse': item.warehouse + item_code: item.item_code, + posting_date: me.frm.doc.posting_date || frappe.datetime.nowdate(), + warehouse: item.warehouse, }; return { query: "erpnext.controllers.queries.get_batch_no", - filters: filters + filters: filters, }; } }); - me.frm.set_query('expense_account', 'service_items', function() { + me.frm.set_query("expense_account", "service_items", function () { return { filters: { - "account_type": ['in', ["Tax", "Expense Account", "Income Account", "Expenses Included In Valuation", "Expenses Included In Asset Valuation"]], - "is_group": 0, - "company": me.frm.doc.company - } + account_type: [ + "in", + [ + "Tax", + "Expense Account", + "Income Account", + "Expenses Included In Valuation", + "Expenses Included In Asset Valuation", + ], + ], + is_group: 0, + company: me.frm.doc.company, + }, }; }); } @@ -103,7 +114,10 @@ erpnext.assets.AssetCapitalization = class AssetCapitalization extends erpnext.s } target_asset() { - if (this.frm.doc.target_asset && this.frm.doc.capitalization_method === "Choose a WIP composite asset") { + if ( + this.frm.doc.target_asset && + this.frm.doc.capitalization_method === "Choose a WIP composite asset" + ) { this.set_consumed_stock_items_tagged_to_wip_composite_asset(this.frm.doc.target_asset); this.get_target_asset_details(); } @@ -120,7 +134,7 @@ erpnext.assets.AssetCapitalization = class AssetCapitalization extends erpnext.s }, callback: function (r) { if (!r.exc && r.message) { - if(r.message[0] && r.message[0].length) { + if (r.message[0] && r.message[0].length) { me.frm.clear_table("stock_items"); for (let item of r.message[0]) { me.frm.add_child("stock_items", item); @@ -137,7 +151,7 @@ erpnext.assets.AssetCapitalization = class AssetCapitalization extends erpnext.s me.calculate_totals(); } - } + }, }); } } @@ -169,7 +183,7 @@ erpnext.assets.AssetCapitalization = class AssetCapitalization extends erpnext.s if (this.frm.doc.posting_date) { frappe.run_serially([ () => this.get_all_item_warehouse_details(), - () => this.get_all_asset_values() + () => this.get_all_asset_values(), ]); } } @@ -225,15 +239,15 @@ erpnext.assets.AssetCapitalization = class AssetCapitalization extends erpnext.s } stock_items_add(doc, cdt, cdn) { - erpnext.accounts.dimensions.copy_dimension_from_first_row(this.frm, cdt, cdn, 'stock_items'); + erpnext.accounts.dimensions.copy_dimension_from_first_row(this.frm, cdt, cdn, "stock_items"); } asset_items_add(doc, cdt, cdn) { - erpnext.accounts.dimensions.copy_dimension_from_first_row(this.frm, cdt, cdn, 'asset_items'); + erpnext.accounts.dimensions.copy_dimension_from_first_row(this.frm, cdt, cdn, "asset_items"); } serivce_items_add(doc, cdt, cdn) { - erpnext.accounts.dimensions.copy_dimension_from_first_row(this.frm, cdt, cdn, 'service_items'); + erpnext.accounts.dimensions.copy_dimension_from_first_row(this.frm, cdt, cdn, "service_items"); } get_target_item_details() { @@ -251,7 +265,7 @@ erpnext.assets.AssetCapitalization = class AssetCapitalization extends erpnext.s if (!r.exc) { me.frm.refresh_fields(); } - } + }, }); } } @@ -271,7 +285,7 @@ erpnext.assets.AssetCapitalization = class AssetCapitalization extends erpnext.s if (!r.exc) { me.frm.refresh_fields(); } - } + }, }); } } @@ -293,13 +307,13 @@ erpnext.assets.AssetCapitalization = class AssetCapitalization extends erpnext.s company: me.frm.doc.company, posting_date: me.frm.doc.posting_date, posting_time: me.frm.doc.posting_time, - } + }, }, callback: function (r) { if (!r.exc) { me.calculate_totals(); } - } + }, }); } } @@ -320,13 +334,13 @@ erpnext.assets.AssetCapitalization = class AssetCapitalization extends erpnext.s finance_book: row.finance_book || me.frm.doc.finance_book, posting_date: me.frm.doc.posting_date, posting_time: me.frm.doc.posting_time, - } + }, }, callback: function (r) { if (!r.exc) { me.calculate_totals(); } - } + }, }); } } @@ -344,13 +358,13 @@ erpnext.assets.AssetCapitalization = class AssetCapitalization extends erpnext.s qty: flt(row.qty), expense_account: row.expense_account, company: me.frm.doc.company, - } + }, }, callback: function (r) { if (!r.exc) { me.calculate_totals(); } - } + }, }); } } @@ -363,23 +377,23 @@ erpnext.assets.AssetCapitalization = class AssetCapitalization extends erpnext.s child: item, args: { args: { - 'item_code': item.item_code, - 'warehouse': cstr(item.warehouse), - 'qty': flt(item.stock_qty), - 'serial_no': item.serial_no, - 'posting_date': me.frm.doc.posting_date, - 'posting_time': me.frm.doc.posting_time, - 'company': me.frm.doc.company, - 'voucher_type': me.frm.doc.doctype, - 'voucher_no': me.frm.doc.name, - 'allow_zero_valuation': 1 - } + item_code: item.item_code, + warehouse: cstr(item.warehouse), + qty: flt(item.stock_qty), + serial_no: item.serial_no, + posting_date: me.frm.doc.posting_date, + posting_time: me.frm.doc.posting_time, + company: me.frm.doc.company, + voucher_type: me.frm.doc.doctype, + voucher_no: me.frm.doc.name, + allow_zero_valuation: 1, + }, }, - callback: function(r) { + callback: function (r) { if (!r.exc) { me.calculate_totals(); } - } + }, }); } } @@ -389,11 +403,11 @@ erpnext.assets.AssetCapitalization = class AssetCapitalization extends erpnext.s return me.frm.call({ method: "set_warehouse_details", doc: me.frm.doc, - callback: function(r) { + callback: function (r) { if (!r.exc) { me.calculate_totals(); } - } + }, }); } @@ -402,11 +416,11 @@ erpnext.assets.AssetCapitalization = class AssetCapitalization extends erpnext.s return me.frm.call({ method: "set_asset_values", doc: me.frm.doc, - callback: function(r) { + callback: function (r) { if (!r.exc) { me.calculate_totals(); } - } + }, }); } @@ -418,33 +432,38 @@ erpnext.assets.AssetCapitalization = class AssetCapitalization extends erpnext.s me.frm.doc.service_items_total = 0; $.each(me.frm.doc.stock_items || [], function (i, d) { - d.amount = flt(flt(d.stock_qty) * flt(d.valuation_rate), precision('amount', d)); + d.amount = flt(flt(d.stock_qty) * flt(d.valuation_rate), precision("amount", d)); me.frm.doc.stock_items_total += d.amount; }); $.each(me.frm.doc.asset_items || [], function (i, d) { - d.asset_value = flt(flt(d.asset_value), precision('asset_value', d)); + d.asset_value = flt(flt(d.asset_value), precision("asset_value", d)); me.frm.doc.asset_items_total += d.asset_value; }); $.each(me.frm.doc.service_items || [], function (i, d) { - d.amount = flt(flt(d.qty) * flt(d.rate), precision('amount', d)); + d.amount = flt(flt(d.qty) * flt(d.rate), precision("amount", d)); me.frm.doc.service_items_total += d.amount; }); - me.frm.doc.stock_items_total = flt(me.frm.doc.stock_items_total, precision('stock_items_total')); - me.frm.doc.asset_items_total = flt(me.frm.doc.asset_items_total, precision('asset_items_total')); - me.frm.doc.service_items_total = flt(me.frm.doc.service_items_total, precision('service_items_total')); + me.frm.doc.stock_items_total = flt(me.frm.doc.stock_items_total, precision("stock_items_total")); + me.frm.doc.asset_items_total = flt(me.frm.doc.asset_items_total, precision("asset_items_total")); + me.frm.doc.service_items_total = flt( + me.frm.doc.service_items_total, + precision("service_items_total") + ); - me.frm.doc.total_value = me.frm.doc.stock_items_total + me.frm.doc.asset_items_total + me.frm.doc.service_items_total; - me.frm.doc.total_value = flt(me.frm.doc.total_value, precision('total_value')); + me.frm.doc.total_value = + me.frm.doc.stock_items_total + me.frm.doc.asset_items_total + me.frm.doc.service_items_total; + me.frm.doc.total_value = flt(me.frm.doc.total_value, precision("total_value")); - me.frm.doc.target_qty = flt(me.frm.doc.target_qty, precision('target_qty')); - me.frm.doc.target_incoming_rate = me.frm.doc.target_qty ? me.frm.doc.total_value / flt(me.frm.doc.target_qty) + me.frm.doc.target_qty = flt(me.frm.doc.target_qty, precision("target_qty")); + me.frm.doc.target_incoming_rate = me.frm.doc.target_qty + ? me.frm.doc.total_value / flt(me.frm.doc.target_qty) : me.frm.doc.total_value; me.frm.refresh_fields(); } }; -cur_frm.cscript = new erpnext.assets.AssetCapitalization({frm: cur_frm}); +cur_frm.cscript = new erpnext.assets.AssetCapitalization({ frm: cur_frm }); diff --git a/erpnext/assets/doctype/asset_category/asset_category.js b/erpnext/assets/doctype/asset_category/asset_category.js index 7dde14ea0e61..046b62f244e2 100644 --- a/erpnext/assets/doctype/asset_category/asset_category.js +++ b/erpnext/assets/doctype/asset_category/asset_category.js @@ -1,56 +1,55 @@ // Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Asset Category', { - onload: function(frm) { - frm.add_fetch('company_name', 'accumulated_depreciation_account', 'accumulated_depreciation_account'); - frm.add_fetch('company_name', 'depreciation_expense_account', 'depreciation_expense_account'); +frappe.ui.form.on("Asset Category", { + onload: function (frm) { + frm.add_fetch("company_name", "accumulated_depreciation_account", "accumulated_depreciation_account"); + frm.add_fetch("company_name", "depreciation_expense_account", "depreciation_expense_account"); - frm.set_query('fixed_asset_account', 'accounts', function(doc, cdt, cdn) { - var d = locals[cdt][cdn]; + frm.set_query("fixed_asset_account", "accounts", function (doc, cdt, cdn) { + var d = locals[cdt][cdn]; return { - "filters": { - "account_type": "Fixed Asset", - "root_type": "Asset", - "is_group": 0, - "company": d.company_name - } + filters: { + account_type: "Fixed Asset", + root_type: "Asset", + is_group: 0, + company: d.company_name, + }, }; }); - frm.set_query('accumulated_depreciation_account', 'accounts', function(doc, cdt, cdn) { - var d = locals[cdt][cdn]; + frm.set_query("accumulated_depreciation_account", "accounts", function (doc, cdt, cdn) { + var d = locals[cdt][cdn]; return { - "filters": { - "account_type": "Accumulated Depreciation", - "is_group": 0, - "company": d.company_name - } + filters: { + account_type: "Accumulated Depreciation", + is_group: 0, + company: d.company_name, + }, }; }); - frm.set_query('depreciation_expense_account', 'accounts', function(doc, cdt, cdn) { - var d = locals[cdt][cdn]; + frm.set_query("depreciation_expense_account", "accounts", function (doc, cdt, cdn) { + var d = locals[cdt][cdn]; return { - "filters": { - "account_type": "Depreciation", - "root_type": ["in", ["Expense", "Income"]], - "is_group": 0, - "company": d.company_name - } + filters: { + account_type: "Depreciation", + root_type: ["in", ["Expense", "Income"]], + is_group: 0, + company: d.company_name, + }, }; }); - frm.set_query('capital_work_in_progress_account', 'accounts', function(doc, cdt, cdn) { - var d = locals[cdt][cdn]; + frm.set_query("capital_work_in_progress_account", "accounts", function (doc, cdt, cdn) { + var d = locals[cdt][cdn]; return { - "filters": { - "account_type": "Capital Work in Progress", - "is_group": 0, - "company": d.company_name - } + filters: { + account_type: "Capital Work in Progress", + is_group: 0, + company: d.company_name, + }, }; }); - - } + }, }); diff --git a/erpnext/assets/doctype/asset_maintenance/asset_maintenance.js b/erpnext/assets/doctype/asset_maintenance/asset_maintenance.js index 5c03b98873b6..83dabab89357 100644 --- a/erpnext/assets/doctype/asset_maintenance/asset_maintenance.js +++ b/erpnext/assets/doctype/asset_maintenance/asset_maintenance.js @@ -1,49 +1,47 @@ // Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Asset Maintenance', { +frappe.ui.form.on("Asset Maintenance", { setup: (frm) => { - frm.set_query("assign_to", "asset_maintenance_tasks", function(doc) { + frm.set_query("assign_to", "asset_maintenance_tasks", function (doc) { return { query: "erpnext.assets.doctype.asset_maintenance.asset_maintenance.get_team_members", filters: { - maintenance_team: doc.maintenance_team - } + maintenance_team: doc.maintenance_team, + }, }; }); - frm.set_indicator_formatter('maintenance_status', - function(doc) { - let indicator = 'blue'; - if (doc.maintenance_status == 'Overdue') { - indicator = 'orange'; - } - if (doc.maintenance_status == 'Cancelled') { - indicator = 'red'; - } - return indicator; + frm.set_indicator_formatter("maintenance_status", function (doc) { + let indicator = "blue"; + if (doc.maintenance_status == "Overdue") { + indicator = "orange"; + } + if (doc.maintenance_status == "Cancelled") { + indicator = "red"; } - ); + return indicator; + }); }, refresh: (frm) => { - if(!frm.is_new()) { - frm.trigger('make_dashboard'); + if (!frm.is_new()) { + frm.trigger("make_dashboard"); } }, make_dashboard: (frm) => { - if(!frm.is_new()) { + if (!frm.is_new()) { frappe.call({ - method: 'erpnext.assets.doctype.asset_maintenance.asset_maintenance.get_maintenance_log', - args: {asset_name: frm.doc.asset_name}, + method: "erpnext.assets.doctype.asset_maintenance.asset_maintenance.get_maintenance_log", + args: { asset_name: frm.doc.asset_name }, callback: (r) => { - if(!r.message) { + if (!r.message) { return; } - const section = frm.dashboard.add_section('', __("Maintenance Log")); - var rows = $('
      ').appendTo(section); + const section = frm.dashboard.add_section("", __("Maintenance Log")); + var rows = $("
      ").appendTo(section); // show - (r.message || []).forEach(function(d) { + (r.message || []).forEach(function (d) { $(`
      { get_next_due_date(frm, cdt, cdn); }, - periodicity: (frm, cdt, cdn) => { + periodicity: (frm, cdt, cdn) => { get_next_due_date(frm, cdt, cdn); }, - last_completion_date: (frm, cdt, cdn) => { + last_completion_date: (frm, cdt, cdn) => { get_next_due_date(frm, cdt, cdn); }, - end_date: (frm, cdt, cdn) => { + end_date: (frm, cdt, cdn) => { get_next_due_date(frm, cdt, cdn); - } + }, }); var get_next_due_date = function (frm, cdt, cdn) { var d = locals[cdt][cdn]; if (d.start_date && d.periodicity) { return frappe.call({ - method: 'erpnext.assets.doctype.asset_maintenance.asset_maintenance.calculate_next_due_date', + method: "erpnext.assets.doctype.asset_maintenance.asset_maintenance.calculate_next_due_date", args: { start_date: d.start_date, periodicity: d.periodicity, end_date: d.end_date, last_completion_date: d.last_completion_date, - next_due_date: d.next_due_date + next_due_date: d.next_due_date, }, - callback: function(r) { + callback: function (r) { if (r.message) { frappe.model.set_value(cdt, cdn, "next_due_date", r.message); - } - else { + } else { frappe.model.set_value(cdt, cdn, "next_due_date", ""); } - } + }, }); } }; diff --git a/erpnext/assets/doctype/asset_maintenance_log/asset_maintenance_log.js b/erpnext/assets/doctype/asset_maintenance_log/asset_maintenance_log.js index bcdc3acf0ac8..47a2128c3792 100644 --- a/erpnext/assets/doctype/asset_maintenance_log/asset_maintenance_log.js +++ b/erpnext/assets/doctype/asset_maintenance_log/asset_maintenance_log.js @@ -1,15 +1,15 @@ // Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Asset Maintenance Log', { +frappe.ui.form.on("Asset Maintenance Log", { asset_maintenance: (frm) => { - frm.set_query('task', function(doc) { + frm.set_query("task", function (doc) { return { query: "erpnext.assets.doctype.asset_maintenance_log.asset_maintenance_log.get_maintenance_tasks", filters: { - 'asset_maintenance': doc.asset_maintenance - } + asset_maintenance: doc.asset_maintenance, + }, }; }); - } + }, }); diff --git a/erpnext/assets/doctype/asset_maintenance_log/asset_maintenance_log_calendar.js b/erpnext/assets/doctype/asset_maintenance_log/asset_maintenance_log_calendar.js index c804b31e908b..7b7b5085369d 100644 --- a/erpnext/assets/doctype/asset_maintenance_log/asset_maintenance_log_calendar.js +++ b/erpnext/assets/doctype/asset_maintenance_log/asset_maintenance_log_calendar.js @@ -3,20 +3,20 @@ frappe.views.calendar["Asset Maintenance Log"] = { field_map: { - "start": "due_date", - "end": "due_date", - "id": "name", - "title": "task", - "allDay": "allDay", - "progress": "progress" + start: "due_date", + end: "due_date", + id: "name", + title: "task", + allDay: "allDay", + progress: "progress", }, filters: [ { - "fieldtype": "Link", - "fieldname": "asset_name", - "options": "Asset Maintenance", - "label": __("Asset Maintenance") - } + fieldtype: "Link", + fieldname: "asset_name", + options: "Asset Maintenance", + label: __("Asset Maintenance"), + }, ], - get_events_method: "frappe.desk.calendar.get_events" + get_events_method: "frappe.desk.calendar.get_events", }; diff --git a/erpnext/assets/doctype/asset_maintenance_log/asset_maintenance_log_list.js b/erpnext/assets/doctype/asset_maintenance_log/asset_maintenance_log_list.js index 23000e60eff3..13f2444742d6 100644 --- a/erpnext/assets/doctype/asset_maintenance_log/asset_maintenance_log_list.js +++ b/erpnext/assets/doctype/asset_maintenance_log/asset_maintenance_log_list.js @@ -1,15 +1,15 @@ -frappe.listview_settings['Asset Maintenance Log'] = { +frappe.listview_settings["Asset Maintenance Log"] = { add_fields: ["maintenance_status"], has_indicator_for_draft: 1, - get_indicator: function(doc) { - if (doc.maintenance_status=="Planned") { + get_indicator: function (doc) { + if (doc.maintenance_status == "Planned") { return [__(doc.maintenance_status), "orange", "status,=," + doc.maintenance_status]; - } else if (doc.maintenance_status=="Completed") { + } else if (doc.maintenance_status == "Completed") { return [__(doc.maintenance_status), "green", "status,=," + doc.maintenance_status]; - } else if (doc.maintenance_status=="Cancelled") { + } else if (doc.maintenance_status == "Cancelled") { return [__(doc.maintenance_status), "red", "status,=," + doc.maintenance_status]; - } else if (doc.maintenance_status=="Overdue") { + } else if (doc.maintenance_status == "Overdue") { return [__(doc.maintenance_status), "red", "status,=," + doc.maintenance_status]; } - } + }, }; diff --git a/erpnext/assets/doctype/asset_maintenance_team/asset_maintenance_team.js b/erpnext/assets/doctype/asset_maintenance_team/asset_maintenance_team.js index c94e3dbc3c00..859876519008 100644 --- a/erpnext/assets/doctype/asset_maintenance_team/asset_maintenance_team.js +++ b/erpnext/assets/doctype/asset_maintenance_team/asset_maintenance_team.js @@ -1,8 +1,6 @@ // Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Asset Maintenance Team', { - refresh: function() { - - } +frappe.ui.form.on("Asset Maintenance Team", { + refresh: function () {}, }); diff --git a/erpnext/assets/doctype/asset_movement/asset_movement.js b/erpnext/assets/doctype/asset_movement/asset_movement.js index 4ccc3f8013bf..e445c90f308c 100644 --- a/erpnext/assets/doctype/asset_movement/asset_movement.js +++ b/erpnext/assets/doctype/asset_movement/asset_movement.js @@ -1,104 +1,107 @@ // Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Asset Movement', { +frappe.ui.form.on("Asset Movement", { setup: (frm) => { frm.set_query("to_employee", "assets", (doc) => { return { filters: { - company: doc.company - } + company: doc.company, + }, }; - }) + }); frm.set_query("from_employee", "assets", (doc) => { return { filters: { - company: doc.company - } + company: doc.company, + }, }; - }) + }); frm.set_query("reference_name", (doc) => { return { filters: { company: doc.company, - docstatus: 1 - } + docstatus: 1, + }, }; - }) + }); frm.set_query("reference_doctype", () => { return { filters: { - name: ["in", ["Purchase Receipt", "Purchase Invoice"]] - } + name: ["in", ["Purchase Receipt", "Purchase Invoice"]], + }, }; }), - frm.set_query("asset", "assets", () => { - return { - filters: { - status: ["not in", ["Draft"]] - } - } - }) + frm.set_query("asset", "assets", () => { + return { + filters: { + status: ["not in", ["Draft"]], + }, + }; + }); }, onload: (frm) => { - frm.trigger('set_required_fields'); + frm.trigger("set_required_fields"); }, purpose: (frm) => { - frm.trigger('set_required_fields'); + frm.trigger("set_required_fields"); }, set_required_fields: (frm, cdt, cdn) => { let fieldnames_to_be_altered; - if (frm.doc.purpose === 'Transfer') { + if (frm.doc.purpose === "Transfer") { fieldnames_to_be_altered = { target_location: { read_only: 0, reqd: 1 }, source_location: { read_only: 1, reqd: 1 }, from_employee: { read_only: 1, reqd: 0 }, - to_employee: { read_only: 1, reqd: 0 } + to_employee: { read_only: 1, reqd: 0 }, }; - } - else if (frm.doc.purpose === 'Receipt') { + } else if (frm.doc.purpose === "Receipt") { fieldnames_to_be_altered = { target_location: { read_only: 0, reqd: 1 }, source_location: { read_only: 1, reqd: 0 }, from_employee: { read_only: 0, reqd: 0 }, - to_employee: { read_only: 1, reqd: 0 } + to_employee: { read_only: 1, reqd: 0 }, }; - } - else if (frm.doc.purpose === 'Issue') { + } else if (frm.doc.purpose === "Issue") { fieldnames_to_be_altered = { target_location: { read_only: 1, reqd: 0 }, source_location: { read_only: 1, reqd: 0 }, from_employee: { read_only: 1, reqd: 0 }, - to_employee: { read_only: 0, reqd: 1 } + to_employee: { read_only: 0, reqd: 1 }, }; } if (fieldnames_to_be_altered) { - Object.keys(fieldnames_to_be_altered).forEach(fieldname => { + Object.keys(fieldnames_to_be_altered).forEach((fieldname) => { let property_to_be_altered = fieldnames_to_be_altered[fieldname]; - Object.keys(property_to_be_altered).forEach(property => { + Object.keys(property_to_be_altered).forEach((property) => { let value = property_to_be_altered[property]; - frm.fields_dict['assets'].grid.update_docfield_property(fieldname, property, value); + frm.fields_dict["assets"].grid.update_docfield_property(fieldname, property, value); }); }); - frm.refresh_field('assets'); + frm.refresh_field("assets"); } - } + }, }); -frappe.ui.form.on('Asset Movement Item', { - asset: function(frm, cdt, cdn) { +frappe.ui.form.on("Asset Movement Item", { + asset: function (frm, cdt, cdn) { // on manual entry of an asset auto sets their source location / employee const asset_name = locals[cdt][cdn].asset; - if (asset_name){ - frappe.db.get_doc('Asset', asset_name).then((asset_doc) => { - if(asset_doc.location) frappe.model.set_value(cdt, cdn, 'source_location', asset_doc.location); - if(asset_doc.custodian) frappe.model.set_value(cdt, cdn, 'from_employee', asset_doc.custodian); - }).catch((err) => { - console.log(err); // eslint-disable-line - }); + if (asset_name) { + frappe.db + .get_doc("Asset", asset_name) + .then((asset_doc) => { + if (asset_doc.location) + frappe.model.set_value(cdt, cdn, "source_location", asset_doc.location); + if (asset_doc.custodian) + frappe.model.set_value(cdt, cdn, "from_employee", asset_doc.custodian); + }) + .catch((err) => { + console.log(err); // eslint-disable-line + }); } - } + }, }); diff --git a/erpnext/assets/doctype/asset_repair/asset_repair.js b/erpnext/assets/doctype/asset_repair/asset_repair.js index f9ed2cc34487..0ce178f4e6b3 100644 --- a/erpnext/assets/doctype/asset_repair/asset_repair.js +++ b/erpnext/assets/doctype/asset_repair/asset_repair.js @@ -1,40 +1,40 @@ // Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Asset Repair', { - setup: function(frm) { - frm.fields_dict.cost_center.get_query = function(doc) { +frappe.ui.form.on("Asset Repair", { + setup: function (frm) { + frm.fields_dict.cost_center.get_query = function (doc) { return { filters: { - 'is_group': 0, - 'company': doc.company - } + is_group: 0, + company: doc.company, + }, }; }; - frm.fields_dict.project.get_query = function(doc) { + frm.fields_dict.project.get_query = function (doc) { return { filters: { - 'company': doc.company - } + company: doc.company, + }, }; }; - frm.fields_dict.warehouse.get_query = function(doc) { + frm.fields_dict.warehouse.get_query = function (doc) { return { filters: { - 'is_group': 0, - 'company': doc.company - } + is_group: 0, + company: doc.company, + }, }; }; }, - refresh: function(frm) { + refresh: function (frm) { if (frm.doc.docstatus) { - frm.add_custom_button(__("View General Ledger"), function() { + frm.add_custom_button(__("View General Ledger"), function () { frappe.route_options = { - "voucher_no": frm.doc.name + voucher_no: frm.doc.name, }; frappe.set_route("query-report", "General Ledger"); }); @@ -43,55 +43,55 @@ frappe.ui.form.on('Asset Repair', { repair_status: (frm) => { if (frm.doc.completion_date && frm.doc.repair_status == "Completed") { - frappe.call ({ + frappe.call({ method: "erpnext.assets.doctype.asset_repair.asset_repair.get_downtime", args: { - "failure_date":frm.doc.failure_date, - "completion_date":frm.doc.completion_date + failure_date: frm.doc.failure_date, + completion_date: frm.doc.completion_date, }, - callback: function(r) { - if(r.message) { + callback: function (r) { + if (r.message) { frm.set_value("downtime", r.message + " Hrs"); } - } + }, }); } if (frm.doc.repair_status == "Completed") { - frm.set_value('completion_date', frappe.datetime.now_datetime()); + frm.set_value("completion_date", frappe.datetime.now_datetime()); } }, stock_items_on_form_rendered() { erpnext.setup_serial_or_batch_no(); - } + }, }); -frappe.ui.form.on('Asset Repair Consumed Item', { - item_code: function(frm, cdt, cdn) { +frappe.ui.form.on("Asset Repair Consumed Item", { + item_code: function (frm, cdt, cdn) { var item = locals[cdt][cdn]; let item_args = { - 'item_code': item.item_code, - 'warehouse': frm.doc.warehouse, - 'qty': item.consumed_quantity, - 'serial_no': item.serial_no, - 'company': frm.doc.company, + item_code: item.item_code, + warehouse: frm.doc.warehouse, + qty: item.consumed_quantity, + serial_no: item.serial_no, + company: frm.doc.company, }; frappe.call({ - method: 'erpnext.stock.utils.get_incoming_rate', + method: "erpnext.stock.utils.get_incoming_rate", args: { - args: item_args + args: item_args, + }, + callback: function (r) { + frappe.model.set_value(cdt, cdn, "valuation_rate", r.message); }, - callback: function(r) { - frappe.model.set_value(cdt, cdn, 'valuation_rate', r.message); - } }); }, - consumed_quantity: function(frm, cdt, cdn) { + consumed_quantity: function (frm, cdt, cdn) { var row = locals[cdt][cdn]; - frappe.model.set_value(cdt, cdn, 'total_value', row.consumed_quantity * row.valuation_rate); + frappe.model.set_value(cdt, cdn, "total_value", row.consumed_quantity * row.valuation_rate); }, }); diff --git a/erpnext/assets/doctype/asset_repair/asset_repair_list.js b/erpnext/assets/doctype/asset_repair/asset_repair_list.js index 86376f400467..633c39ba77f3 100644 --- a/erpnext/assets/doctype/asset_repair/asset_repair_list.js +++ b/erpnext/assets/doctype/asset_repair/asset_repair_list.js @@ -1,12 +1,12 @@ -frappe.listview_settings['Asset Repair'] = { +frappe.listview_settings["Asset Repair"] = { add_fields: ["repair_status"], - get_indicator: function(doc) { - if(doc.repair_status=="Pending") { + get_indicator: function (doc) { + if (doc.repair_status == "Pending") { return [__("Pending"), "orange"]; - } else if(doc.repair_status=="Completed") { + } else if (doc.repair_status == "Completed") { return [__("Completed"), "green"]; - } else if(doc.repair_status=="Cancelled") { + } else if (doc.repair_status == "Cancelled") { return [__("Cancelled"), "red"]; } - } + }, }; diff --git a/erpnext/assets/doctype/asset_shift_allocation/asset_shift_allocation.js b/erpnext/assets/doctype/asset_shift_allocation/asset_shift_allocation.js index 2bd41c137732..fd92ce7f2fe4 100644 --- a/erpnext/assets/doctype/asset_shift_allocation/asset_shift_allocation.js +++ b/erpnext/assets/doctype/asset_shift_allocation/asset_shift_allocation.js @@ -1,15 +1,15 @@ // Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Asset Shift Allocation', { - onload: function(frm) { +frappe.ui.form.on("Asset Shift Allocation", { + onload: function (frm) { frm.events.make_schedules_editable(frm); }, - make_schedules_editable: function(frm) { + make_schedules_editable: function (frm) { frm.toggle_enable("depreciation_schedule", true); frm.fields_dict["depreciation_schedule"].grid.toggle_enable("schedule_date", false); frm.fields_dict["depreciation_schedule"].grid.toggle_enable("depreciation_amount", false); frm.fields_dict["depreciation_schedule"].grid.toggle_enable("shift", true); - } -}); \ No newline at end of file + }, +}); diff --git a/erpnext/assets/doctype/asset_shift_factor/asset_shift_factor.js b/erpnext/assets/doctype/asset_shift_factor/asset_shift_factor.js index e6552d8370d5..4795b0672ae3 100644 --- a/erpnext/assets/doctype/asset_shift_factor/asset_shift_factor.js +++ b/erpnext/assets/doctype/asset_shift_factor/asset_shift_factor.js @@ -1,8 +1,7 @@ // Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Asset Shift Factor', { +frappe.ui.form.on("Asset Shift Factor", { // refresh: function(frm) { - // } }); diff --git a/erpnext/assets/doctype/asset_value_adjustment/asset_value_adjustment.js b/erpnext/assets/doctype/asset_value_adjustment/asset_value_adjustment.js index d07f40cdf422..7fbe6d0bd124 100644 --- a/erpnext/assets/doctype/asset_value_adjustment/asset_value_adjustment.js +++ b/erpnext/assets/doctype/asset_value_adjustment/asset_value_adjustment.js @@ -3,61 +3,61 @@ frappe.provide("erpnext.accounts.dimensions"); -frappe.ui.form.on('Asset Value Adjustment', { - setup: function(frm) { - frm.add_fetch('company', 'cost_center', 'cost_center'); - frm.set_query('cost_center', function() { +frappe.ui.form.on("Asset Value Adjustment", { + setup: function (frm) { + frm.add_fetch("company", "cost_center", "cost_center"); + frm.set_query("cost_center", function () { return { filters: { company: frm.doc.company, - is_group: 0 - } - } + is_group: 0, + }, + }; }); - frm.set_query('asset', function() { + frm.set_query("asset", function () { return { filters: { calculate_depreciation: 1, - docstatus: 1 - } + docstatus: 1, + }, }; }); }, - onload: function(frm) { - if(frm.is_new() && frm.doc.asset) { + onload: function (frm) { + if (frm.is_new() && frm.doc.asset) { frm.trigger("set_current_asset_value"); } erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype); }, - company: function(frm) { + company: function (frm) { erpnext.accounts.dimensions.update_dimension(frm, frm.doctype); }, - asset: function(frm) { + asset: function (frm) { frm.trigger("set_current_asset_value"); }, - finance_book: function(frm) { + finance_book: function (frm) { frm.trigger("set_current_asset_value"); }, - set_current_asset_value: function(frm) { + set_current_asset_value: function (frm) { if (frm.doc.asset) { frm.call({ method: "erpnext.assets.doctype.asset.asset.get_asset_value_after_depreciation", args: { asset_name: frm.doc.asset, - finance_book: frm.doc.finance_book + finance_book: frm.doc.finance_book, }, - callback: function(r) { + callback: function (r) { if (r.message) { - frm.set_value('current_asset_value', r.message); + frm.set_value("current_asset_value", r.message); } - } + }, }); } - } + }, }); diff --git a/erpnext/assets/doctype/location/location.js b/erpnext/assets/doctype/location/location.js index 0f069b2fd8e3..97d723915881 100644 --- a/erpnext/assets/doctype/location/location.js +++ b/erpnext/assets/doctype/location/location.js @@ -1,13 +1,13 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Location', { +frappe.ui.form.on("Location", { setup: function (frm) { frm.set_query("parent_location", function () { return { - "filters": { - "is_group": 1 - } + filters: { + is_group: 1, + }, }; }); }, @@ -15,10 +15,9 @@ frappe.ui.form.on('Location', { onload_post_render(frm) { if (!frm.doc.location && frm.doc.latitude && frm.doc.longitude) { frm.fields_dict.location.map.setView([frm.doc.latitude, frm.doc.longitude], 13); - } - else { - frm.doc.latitude = frm.fields_dict.location.map.getCenter()['lat']; - frm.doc.longitude = frm.fields_dict.location.map.getCenter()['lng']; + } else { + frm.doc.latitude = frm.fields_dict.location.map.getCenter()["lat"]; + frm.doc.longitude = frm.fields_dict.location.map.getCenter()["lng"]; } }, }); diff --git a/erpnext/assets/doctype/location/location_tree.js b/erpnext/assets/doctype/location/location_tree.js index 3e105f6ca49a..c3484c2469b2 100644 --- a/erpnext/assets/doctype/location/location_tree.js +++ b/erpnext/assets/doctype/location/location_tree.js @@ -1,7 +1,7 @@ frappe.treeview_settings["Location"] = { ignore_fields: ["parent_location"], - get_tree_nodes: 'erpnext.assets.doctype.location.location.get_children', - add_tree_node: 'erpnext.assets.doctype.location.location.add_node', + get_tree_nodes: "erpnext.assets.doctype.location.location.get_children", + add_tree_node: "erpnext.assets.doctype.location.location.add_node", filters: [ { fieldname: "location", @@ -10,9 +10,9 @@ frappe.treeview_settings["Location"] = { label: __("Location"), get_query: function () { return { - filters: [["Location", "is_group", "=", 1]] + filters: [["Location", "is_group", "=", 1]], }; - } + }, }, ], breadcrumb: "Assets", @@ -24,10 +24,10 @@ frappe.treeview_settings["Location"] = { action: function () { frappe.new_doc("Location", true); }, - condition: 'frappe.boot.user.can_create.indexOf("Location") !== -1' - } + condition: 'frappe.boot.user.can_create.indexOf("Location") !== -1', + }, ], onload: function (treeview) { treeview.make_tree(); - } + }, }; diff --git a/erpnext/assets/doctype/maintenance_team_member/maintenance_team_member.js b/erpnext/assets/doctype/maintenance_team_member/maintenance_team_member.js index 2db712546c67..6f3521ffd85c 100644 --- a/erpnext/assets/doctype/maintenance_team_member/maintenance_team_member.js +++ b/erpnext/assets/doctype/maintenance_team_member/maintenance_team_member.js @@ -1,8 +1,6 @@ // Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Maintenance Team Member', { - refresh: function() { - - } +frappe.ui.form.on("Maintenance Team Member", { + refresh: function () {}, }); diff --git a/erpnext/assets/report/fixed_asset_register/fixed_asset_register.js b/erpnext/assets/report/fixed_asset_register/fixed_asset_register.js index 0497addf44a7..7e9ecd4d8fcb 100644 --- a/erpnext/assets/report/fixed_asset_register/fixed_asset_register.js +++ b/erpnext/assets/report/fixed_asset_register/fixed_asset_register.js @@ -3,103 +3,103 @@ /* eslint-disable */ frappe.query_reports["Fixed Asset Register"] = { - "filters": [ + filters: [ { - fieldname:"company", + fieldname: "company", label: __("Company"), fieldtype: "Link", options: "Company", default: frappe.defaults.get_user_default("Company"), - reqd: 1 + reqd: 1, }, { - fieldname:"status", + fieldname: "status", label: __("Status"), fieldtype: "Select", options: "\nIn Location\nDisposed", - default: 'In Location' + default: "In Location", }, { - fieldname:"asset_category", + fieldname: "asset_category", label: __("Asset Category"), fieldtype: "Link", - options: "Asset Category" + options: "Asset Category", }, { - fieldname:"cost_center", + fieldname: "cost_center", label: __("Cost Center"), fieldtype: "Link", - options: "Cost Center" + options: "Cost Center", }, { - fieldname:"group_by", + fieldname: "group_by", label: __("Group By"), fieldtype: "Select", options: ["--Select a group--", "Asset Category", "Location"], default: "--Select a group--", - reqd: 1 + reqd: 1, }, { - fieldname:"only_existing_assets", + fieldname: "only_existing_assets", label: __("Only existing assets"), - fieldtype: "Check" + fieldtype: "Check", }, { - fieldname:"finance_book", + fieldname: "finance_book", label: __("Finance Book"), fieldtype: "Link", options: "Finance Book", }, { - "fieldname": "include_default_book_assets", - "label": __("Include Default FB Assets"), - "fieldtype": "Check", - "default": 1 + fieldname: "include_default_book_assets", + label: __("Include Default FB Assets"), + fieldtype: "Check", + default: 1, }, { - "fieldname":"filter_based_on", - "label": __("Period Based On"), - "fieldtype": "Select", - "options": ["--Select a period--", "Fiscal Year", "Date Range"], - "default": "--Select a period--", + fieldname: "filter_based_on", + label: __("Period Based On"), + fieldtype: "Select", + options: ["--Select a period--", "Fiscal Year", "Date Range"], + default: "--Select a period--", }, { - "fieldname":"from_date", - "label": __("Start Date"), - "fieldtype": "Date", - "default": frappe.datetime.add_months(frappe.datetime.nowdate(), -12), - "depends_on": "eval: doc.filter_based_on == 'Date Range'", + fieldname: "from_date", + label: __("Start Date"), + fieldtype: "Date", + default: frappe.datetime.add_months(frappe.datetime.nowdate(), -12), + depends_on: "eval: doc.filter_based_on == 'Date Range'", }, { - "fieldname":"to_date", - "label": __("End Date"), - "fieldtype": "Date", - "default": frappe.datetime.nowdate(), - "depends_on": "eval: doc.filter_based_on == 'Date Range'", + fieldname: "to_date", + label: __("End Date"), + fieldtype: "Date", + default: frappe.datetime.nowdate(), + depends_on: "eval: doc.filter_based_on == 'Date Range'", }, { - "fieldname":"from_fiscal_year", - "label": __("Start Year"), - "fieldtype": "Link", - "options": "Fiscal Year", - "default": erpnext.utils.get_fiscal_year(frappe.datetime.get_today()), - "depends_on": "eval: doc.filter_based_on == 'Fiscal Year'", + fieldname: "from_fiscal_year", + label: __("Start Year"), + fieldtype: "Link", + options: "Fiscal Year", + default: erpnext.utils.get_fiscal_year(frappe.datetime.get_today()), + depends_on: "eval: doc.filter_based_on == 'Fiscal Year'", }, { - "fieldname":"to_fiscal_year", - "label": __("End Year"), - "fieldtype": "Link", - "options": "Fiscal Year", - "default": erpnext.utils.get_fiscal_year(frappe.datetime.get_today()), - "depends_on": "eval: doc.filter_based_on == 'Fiscal Year'", + fieldname: "to_fiscal_year", + label: __("End Year"), + fieldtype: "Link", + options: "Fiscal Year", + default: erpnext.utils.get_fiscal_year(frappe.datetime.get_today()), + depends_on: "eval: doc.filter_based_on == 'Fiscal Year'", }, { - "fieldname":"date_based_on", - "label": __("Date Based On"), - "fieldtype": "Select", - "options": ["Purchase Date", "Available For Use Date"], - "default": "Purchase Date", - "depends_on": "eval: doc.filter_based_on == 'Date Range' || doc.filter_based_on == 'Fiscal Year'", + fieldname: "date_based_on", + label: __("Date Based On"), + fieldtype: "Select", + options: ["Purchase Date", "Available For Use Date"], + default: "Purchase Date", + depends_on: "eval: doc.filter_based_on == 'Date Range' || doc.filter_based_on == 'Fiscal Year'", }, - ] + ], }; diff --git a/erpnext/bulk_transaction/doctype/bulk_transaction_log/bulk_transaction_log.js b/erpnext/bulk_transaction/doctype/bulk_transaction_log/bulk_transaction_log.js index dc54d606e7a1..9ee0c499d985 100644 --- a/erpnext/bulk_transaction/doctype/bulk_transaction_log/bulk_transaction_log.js +++ b/erpnext/bulk_transaction/doctype/bulk_transaction_log/bulk_transaction_log.js @@ -3,17 +3,31 @@ frappe.ui.form.on("Bulk Transaction Log", { refresh(frm) { - frm.add_custom_button(__('Succeeded Entries'), function() { - frappe.set_route('List', 'Bulk Transaction Log Detail', {'date': frm.doc.date, 'transaction_status': "Success"}); - }, __("View")); - frm.add_custom_button(__('Failed Entries'), function() { - frappe.set_route('List', 'Bulk Transaction Log Detail', {'date': frm.doc.date, 'transaction_status': "Failed"}); - }, __("View")); + frm.add_custom_button( + __("Succeeded Entries"), + function () { + frappe.set_route("List", "Bulk Transaction Log Detail", { + date: frm.doc.date, + transaction_status: "Success", + }); + }, + __("View") + ); + frm.add_custom_button( + __("Failed Entries"), + function () { + frappe.set_route("List", "Bulk Transaction Log Detail", { + date: frm.doc.date, + transaction_status: "Failed", + }); + }, + __("View") + ); if (frm.doc.failed) { - frm.add_custom_button(__('Retry Failed Transactions'), function() { + frm.add_custom_button(__("Retry Failed Transactions"), function () { frappe.call({ method: "erpnext.utilities.bulk_transaction.retry", - args: {date: frm.doc.date} + args: { date: frm.doc.date }, }); }); } diff --git a/erpnext/buying/doctype/buying_settings/buying_settings.js b/erpnext/buying/doctype/buying_settings/buying_settings.js index 32431fc39106..11b920aea71b 100644 --- a/erpnext/buying/doctype/buying_settings/buying_settings.js +++ b/erpnext/buying/doctype/buying_settings/buying_settings.js @@ -1,31 +1,38 @@ // Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Buying Settings', { +frappe.ui.form.on("Buying Settings", { // refresh: function(frm) { - // } }); -frappe.tour['Buying Settings'] = [ +frappe.tour["Buying Settings"] = [ { fieldname: "supp_master_name", title: "Supplier Naming By", - description: __("By default, the Supplier Name is set as per the Supplier Name entered. If you want Suppliers to be named by a Naming Series choose the 'Naming Series' option."), + description: __( + "By default, the Supplier Name is set as per the Supplier Name entered. If you want Suppliers to be named by a Naming Series choose the 'Naming Series' option." + ), }, { fieldname: "buying_price_list", title: "Default Buying Price List", - description: __("Configure the default Price List when creating a new Purchase transaction. Item prices will be fetched from this Price List.") + description: __( + "Configure the default Price List when creating a new Purchase transaction. Item prices will be fetched from this Price List." + ), }, { fieldname: "po_required", title: "Purchase Order Required for Purchase Invoice & Receipt Creation", - description: __("If this option is configured 'Yes', ERPNext will prevent you from creating a Purchase Invoice or Receipt without creating a Purchase Order first. This configuration can be overridden for a particular supplier by enabling the 'Allow Purchase Invoice Creation Without Purchase Order' checkbox in the Supplier master.") + description: __( + "If this option is configured 'Yes', ERPNext will prevent you from creating a Purchase Invoice or Receipt without creating a Purchase Order first. This configuration can be overridden for a particular supplier by enabling the 'Allow Purchase Invoice Creation Without Purchase Order' checkbox in the Supplier master." + ), }, { fieldname: "pr_required", title: "Purchase Receipt Required for Purchase Invoice Creation", - description: __("If this option is configured 'Yes', ERPNext will prevent you from creating a Purchase Invoice without creating a Purchase Receipt first. This configuration can be overridden for a particular supplier by enabling the 'Allow Purchase Invoice Creation Without Purchase Receipt' checkbox in the Supplier master.") - } + description: __( + "If this option is configured 'Yes', ERPNext will prevent you from creating a Purchase Invoice without creating a Purchase Receipt first. This configuration can be overridden for a particular supplier by enabling the 'Allow Purchase Invoice Creation Without Purchase Receipt' checkbox in the Supplier master." + ), + }, ]; diff --git a/erpnext/buying/doctype/purchase_order/purchase_order_list.js b/erpnext/buying/doctype/purchase_order/purchase_order_list.js index 6594746cfc56..c1bf1f3b8d95 100644 --- a/erpnext/buying/doctype/purchase_order/purchase_order_list.js +++ b/erpnext/buying/doctype/purchase_order/purchase_order_list.js @@ -1,6 +1,14 @@ -frappe.listview_settings['Purchase Order'] = { - add_fields: ["base_grand_total", "company", "currency", "supplier", - "supplier_name", "per_received", "per_billed", "status"], +frappe.listview_settings["Purchase Order"] = { + add_fields: [ + "base_grand_total", + "company", + "currency", + "supplier", + "supplier_name", + "per_received", + "per_billed", + "status", + ], get_indicator: function (doc) { if (doc.status === "Closed") { return [__("Closed"), "green", "status,=,Closed"]; @@ -10,15 +18,25 @@ frappe.listview_settings['Purchase Order'] = { return [__("Delivered"), "green", "status,=,Closed"]; } else if (flt(doc.per_received, 2) < 100 && doc.status !== "Closed") { if (flt(doc.per_billed, 2) < 100) { - return [__("To Receive and Bill"), "orange", - "per_received,<,100|per_billed,<,100|status,!=,Closed"]; + return [ + __("To Receive and Bill"), + "orange", + "per_received,<,100|per_billed,<,100|status,!=,Closed", + ]; } else { - return [__("To Receive"), "orange", - "per_received,<,100|per_billed,=,100|status,!=,Closed"]; + return [__("To Receive"), "orange", "per_received,<,100|per_billed,=,100|status,!=,Closed"]; } - } else if (flt(doc.per_received, 2) >= 100 && flt(doc.per_billed, 2) < 100 && doc.status !== "Closed") { + } else if ( + flt(doc.per_received, 2) >= 100 && + flt(doc.per_billed, 2) < 100 && + doc.status !== "Closed" + ) { return [__("To Bill"), "orange", "per_received,=,100|per_billed,<,100|status,!=,Closed"]; - } else if (flt(doc.per_received, 2) >= 100 && flt(doc.per_billed, 2) == 100 && doc.status !== "Closed") { + } else if ( + flt(doc.per_received, 2) >= 100 && + flt(doc.per_billed, 2) == 100 && + doc.status !== "Closed" + ) { return [__("Completed"), "green", "per_received,=,100|per_billed,=,100|status,!=,Closed"]; } }, @@ -26,25 +44,23 @@ frappe.listview_settings['Purchase Order'] = { var method = "erpnext.buying.doctype.purchase_order.purchase_order.close_or_unclose_purchase_orders"; listview.page.add_menu_item(__("Close"), function () { - listview.call_for_selected_items(method, { "status": "Closed" }); + listview.call_for_selected_items(method, { status: "Closed" }); }); listview.page.add_menu_item(__("Reopen"), function () { - listview.call_for_selected_items(method, { "status": "Submitted" }); + listview.call_for_selected_items(method, { status: "Submitted" }); }); - - listview.page.add_action_item(__("Purchase Invoice"), ()=>{ + listview.page.add_action_item(__("Purchase Invoice"), () => { erpnext.bulk_transaction_processing.create(listview, "Purchase Order", "Purchase Invoice"); }); - listview.page.add_action_item(__("Purchase Receipt"), ()=>{ + listview.page.add_action_item(__("Purchase Receipt"), () => { erpnext.bulk_transaction_processing.create(listview, "Purchase Order", "Purchase Receipt"); }); - listview.page.add_action_item(__("Advance Payment"), ()=>{ + listview.page.add_action_item(__("Advance Payment"), () => { erpnext.bulk_transaction_processing.create(listview, "Purchase Order", "Payment Entry"); }); - - } + }, }; diff --git a/erpnext/buying/doctype/supplier/supplier.js b/erpnext/buying/doctype/supplier/supplier.js index e0e33b6848bd..23f25b288762 100644 --- a/erpnext/buying/doctype/supplier/supplier.js +++ b/erpnext/buying/doctype/supplier/supplier.js @@ -3,49 +3,49 @@ frappe.ui.form.on("Supplier", { setup: function (frm) { - frm.set_query('default_price_list', { 'buying': 1 }); + frm.set_query("default_price_list", { buying: 1 }); if (frm.doc.__islocal == 1) { frm.set_value("represents_company", ""); } - frm.set_query('account', 'accounts', function (doc, cdt, cdn) { + frm.set_query("account", "accounts", function (doc, cdt, cdn) { var d = locals[cdt][cdn]; return { filters: { - 'account_type': 'Payable', - 'company': d.company, - "is_group": 0 - } - } + account_type: "Payable", + company: d.company, + is_group: 0, + }, + }; }); - frm.set_query("default_bank_account", function() { + frm.set_query("default_bank_account", function () { return { filters: { - "is_company_account":1 - } - } + is_company_account: 1, + }, + }; }); - frm.set_query("supplier_primary_contact", function(doc) { + frm.set_query("supplier_primary_contact", function (doc) { return { query: "erpnext.buying.doctype.supplier.supplier.get_supplier_primary_contact", filters: { - "supplier": doc.name - } + supplier: doc.name, + }, }; }); - frm.set_query("supplier_primary_address", function(doc) { + frm.set_query("supplier_primary_address", function (doc) { return { filters: { - "link_doctype": "Supplier", - "link_name": doc.name - } + link_doctype: "Supplier", + link_name: doc.name, + }, }; }); }, refresh: function (frm) { - frappe.dynamic_link = { doc: frm.doc, fieldname: 'name', doctype: 'Supplier' } + frappe.dynamic_link = { doc: frm.doc, fieldname: "name", doctype: "Supplier" }; if (frappe.defaults.get_default("supp_master_name") != "Naming Series") { frm.toggle_display("naming_series", false); @@ -54,65 +54,94 @@ frappe.ui.form.on("Supplier", { } if (frm.doc.__islocal) { - hide_field(['address_html','contact_html']); + hide_field(["address_html", "contact_html"]); frappe.contacts.clear_address_and_contact(frm); - } - else { - unhide_field(['address_html','contact_html']); + } else { + unhide_field(["address_html", "contact_html"]); frappe.contacts.render_address_and_contact(frm); // custom buttons - frm.add_custom_button(__('Accounting Ledger'), function () { - frappe.set_route('query-report', 'General Ledger', - { party_type: 'Supplier', party: frm.doc.name, party_name: frm.doc.supplier_name }); - }, __("View")); - - frm.add_custom_button(__('Accounts Payable'), function () { - frappe.set_route('query-report', 'Accounts Payable', { party_type: "Supplier", party: frm.doc.name }); - }, __("View")); + frm.add_custom_button( + __("Accounting Ledger"), + function () { + frappe.set_route("query-report", "General Ledger", { + party_type: "Supplier", + party: frm.doc.name, + party_name: frm.doc.supplier_name, + }); + }, + __("View") + ); + + frm.add_custom_button( + __("Accounts Payable"), + function () { + frappe.set_route("query-report", "Accounts Payable", { + party_type: "Supplier", + party: frm.doc.name, + }); + }, + __("View") + ); - frm.add_custom_button(__('Bank Account'), function () { - erpnext.utils.make_bank_account(frm.doc.doctype, frm.doc.name); - }, __('Create')); + frm.add_custom_button( + __("Bank Account"), + function () { + erpnext.utils.make_bank_account(frm.doc.doctype, frm.doc.name); + }, + __("Create") + ); - frm.add_custom_button(__('Pricing Rule'), function () { - erpnext.utils.make_pricing_rule(frm.doc.doctype, frm.doc.name); - }, __('Create')); + frm.add_custom_button( + __("Pricing Rule"), + function () { + erpnext.utils.make_pricing_rule(frm.doc.doctype, frm.doc.name); + }, + __("Create") + ); - frm.add_custom_button(__('Get Supplier Group Details'), function () { - frm.trigger("get_supplier_group_details"); - }, __('Actions')); + frm.add_custom_button( + __("Get Supplier Group Details"), + function () { + frm.trigger("get_supplier_group_details"); + }, + __("Actions") + ); if (cint(frappe.defaults.get_default("enable_common_party_accounting"))) { - frm.add_custom_button(__('Link with Customer'), function () { - frm.trigger('show_party_link_dialog'); - }, __('Actions')); + frm.add_custom_button( + __("Link with Customer"), + function () { + frm.trigger("show_party_link_dialog"); + }, + __("Actions") + ); } // indicators erpnext.utils.set_party_dashboard_indicators(frm); } }, - get_supplier_group_details: function(frm) { + get_supplier_group_details: function (frm) { frappe.call({ method: "get_supplier_group_details", doc: frm.doc, - callback: function() { + callback: function () { frm.refresh(); - } + }, }); }, - supplier_primary_address: function(frm) { + supplier_primary_address: function (frm) { if (frm.doc.supplier_primary_address) { frappe.call({ - method: 'frappe.contacts.doctype.address.address.get_address_display', + method: "frappe.contacts.doctype.address.address.get_address_display", args: { - "address_dict": frm.doc.supplier_primary_address + address_dict: frm.doc.supplier_primary_address, }, - callback: function(r) { + callback: function (r) { frm.set_value("primary_address", r.message); - } + }, }); } if (!frm.doc.supplier_primary_address) { @@ -120,56 +149,60 @@ frappe.ui.form.on("Supplier", { } }, - supplier_primary_contact: function(frm) { + supplier_primary_contact: function (frm) { if (!frm.doc.supplier_primary_contact) { frm.set_value("mobile_no", ""); frm.set_value("email_id", ""); } }, - is_internal_supplier: function(frm) { + is_internal_supplier: function (frm) { if (frm.doc.is_internal_supplier == 1) { frm.toggle_reqd("represents_company", true); - } - else { + } else { frm.toggle_reqd("represents_company", false); } }, - show_party_link_dialog: function(frm) { + show_party_link_dialog: function (frm) { const dialog = new frappe.ui.Dialog({ - title: __('Select a Customer'), - fields: [{ - fieldtype: 'Link', label: __('Customer'), - options: 'Customer', fieldname: 'customer', reqd: 1 - }], - primary_action: function({ customer }) { + title: __("Select a Customer"), + fields: [ + { + fieldtype: "Link", + label: __("Customer"), + options: "Customer", + fieldname: "customer", + reqd: 1, + }, + ], + primary_action: function ({ customer }) { frappe.call({ - method: 'erpnext.accounts.doctype.party_link.party_link.create_party_link', + method: "erpnext.accounts.doctype.party_link.party_link.create_party_link", args: { - primary_role: 'Supplier', + primary_role: "Supplier", primary_party: frm.doc.name, - secondary_party: customer + secondary_party: customer, }, freeze: true, - callback: function() { + callback: function () { dialog.hide(); frappe.msgprint({ - message: __('Successfully linked to Customer'), - alert: true + message: __("Successfully linked to Customer"), + alert: true, }); }, - error: function() { + error: function () { dialog.hide(); frappe.msgprint({ - message: __('Linking to Customer Failed. Please try again.'), - title: __('Linking Failed'), - indicator: 'red' + message: __("Linking to Customer Failed. Please try again."), + title: __("Linking Failed"), + indicator: "red", }); - } + }, }); }, - primary_action_label: __('Create Link') + primary_action_label: __("Create Link"), }); dialog.show(); - } + }, }); diff --git a/erpnext/buying/doctype/supplier/supplier_list.js b/erpnext/buying/doctype/supplier/supplier_list.js index c776b001a5a6..987c1e02038c 100644 --- a/erpnext/buying/doctype/supplier/supplier_list.js +++ b/erpnext/buying/doctype/supplier/supplier_list.js @@ -1,8 +1,8 @@ -frappe.listview_settings['Supplier'] = { +frappe.listview_settings["Supplier"] = { add_fields: ["supplier_name", "supplier_group", "image", "on_hold"], - get_indicator: function(doc) { - if(cint(doc.on_hold)) { + get_indicator: function (doc) { + if (cint(doc.on_hold)) { return [__("On Hold"), "red"]; } - } + }, }; diff --git a/erpnext/buying/doctype/supplier_quotation/supplier_quotation_list.js b/erpnext/buying/doctype/supplier_quotation/supplier_quotation_list.js index 73685caa0b44..99fe24d8770c 100644 --- a/erpnext/buying/doctype/supplier_quotation/supplier_quotation_list.js +++ b/erpnext/buying/doctype/supplier_quotation/supplier_quotation_list.js @@ -1,22 +1,22 @@ -frappe.listview_settings['Supplier Quotation'] = { +frappe.listview_settings["Supplier Quotation"] = { add_fields: ["supplier", "base_grand_total", "status", "company", "currency"], - get_indicator: function(doc) { - if(doc.status==="Ordered") { + get_indicator: function (doc) { + if (doc.status === "Ordered") { return [__("Ordered"), "green", "status,=,Ordered"]; - } else if(doc.status==="Rejected") { + } else if (doc.status === "Rejected") { return [__("Lost"), "gray", "status,=,Lost"]; - } else if(doc.status==="Expired") { + } else if (doc.status === "Expired") { return [__("Expired"), "gray", "status,=,Expired"]; } }, - onload: function(listview) { - listview.page.add_action_item(__("Purchase Order"), ()=>{ + onload: function (listview) { + listview.page.add_action_item(__("Purchase Order"), () => { erpnext.bulk_transaction_processing.create(listview, "Supplier Quotation", "Purchase Order"); }); - listview.page.add_action_item(__("Purchase Invoice"), ()=>{ + listview.page.add_action_item(__("Purchase Invoice"), () => { erpnext.bulk_transaction_processing.create(listview, "Supplier Quotation", "Purchase Invoice"); }); - } + }, }; diff --git a/erpnext/buying/doctype/supplier_scorecard/supplier_scorecard.js b/erpnext/buying/doctype/supplier_scorecard/supplier_scorecard.js index b4cd852c32f4..0ff0e8622593 100644 --- a/erpnext/buying/doctype/supplier_scorecard/supplier_scorecard.js +++ b/erpnext/buying/doctype/supplier_scorecard/supplier_scorecard.js @@ -4,55 +4,51 @@ /* global frappe, refresh_field */ frappe.ui.form.on("Supplier Scorecard", { - setup: function(frm) { - if (frm.doc.indicator_color !== "") { - frm.set_indicator_formatter("status", function(doc) { + setup: function (frm) { + if (frm.doc.indicator_color !== "") { + frm.set_indicator_formatter("status", function (doc) { return doc.indicator_color.toLowerCase(); }); } }, - onload: function(frm) { - if (frm.doc.__unsaved == 1) { + onload: function (frm) { + if (frm.doc.__unsaved == 1) { loadAllStandings(frm); } }, - load_criteria: function(frm) { + load_criteria: function (frm) { frappe.call({ method: "erpnext.buying.doctype.supplier_scorecard_criteria.supplier_scorecard_criteria.get_criteria_list", - callback: function(r) { - frm.set_value('criteria', []); - for (var i = 0; i < r.message.length; i++) - { + callback: function (r) { + frm.set_value("criteria", []); + for (var i = 0; i < r.message.length; i++) { var row = frm.add_child("criteria"); row.criteria_name = r.message[i].name; frm.script_manager.trigger("criteria_name", row.doctype, row.name); } refresh_field("criteria"); - } + }, }); - } - + }, }); frappe.ui.form.on("Supplier Scorecard Scoring Standing", { - - standing_name: function(frm, cdt, cdn) { + standing_name: function (frm, cdt, cdn) { var d = frappe.get_doc(cdt, cdn); if (d.standing_name) { return frm.call({ method: "erpnext.buying.doctype.supplier_scorecard_standing.supplier_scorecard_standing.get_scoring_standing", child: d, args: { - standing_name: d.standing_name - } + standing_name: d.standing_name, + }, }); } - } + }, }); frappe.ui.form.on("Supplier Scorecard Scoring Criteria", { - - criteria_name: function(frm, cdt, cdn) { + criteria_name: function (frm, cdt, cdn) { var d = frappe.get_doc(cdt, cdn); if (d.criteria_name) { return frm.call({ @@ -60,36 +56,34 @@ frappe.ui.form.on("Supplier Scorecard Scoring Criteria", { args: { fieldname: "weight", doctype: "Supplier Scorecard Criteria", - filters: {name: d.criteria_name} + filters: { name: d.criteria_name }, }, - callback: function(r) { - if(r.message){ + callback: function (r) { + if (r.message) { d.weight = r.message.weight; - frm.refresh_field('criteria', 'weight'); + frm.refresh_field("criteria", "weight"); } - } + }, }); } - } + }, }); -var loadAllStandings = function(frm) { +var loadAllStandings = function (frm) { frappe.call({ method: "erpnext.buying.doctype.supplier_scorecard_standing.supplier_scorecard_standing.get_standings_list", - callback: function(r) { - for (var j = 0; j < frm.doc.standings.length; j++) - { - if(!frm.doc.standings[j].hasOwnProperty("standing_name")) { + callback: function (r) { + for (var j = 0; j < frm.doc.standings.length; j++) { + if (!frm.doc.standings[j].hasOwnProperty("standing_name")) { frm.get_field("standings").grid.grid_rows[j].remove(); } } - for (var i = 0; i < r.message.length; i++) - { + for (var i = 0; i < r.message.length; i++) { var new_row = frm.add_child("standings"); new_row.standing_name = r.message[i].name; frm.script_manager.trigger("standing_name", new_row.doctype, new_row.name); } refresh_field("standings"); - } + }, }); }; diff --git a/erpnext/buying/doctype/supplier_scorecard/supplier_scorecard_list.js b/erpnext/buying/doctype/supplier_scorecard/supplier_scorecard_list.js index dc5474e3b43c..f6af3d456d4a 100644 --- a/erpnext/buying/doctype/supplier_scorecard/supplier_scorecard_list.js +++ b/erpnext/buying/doctype/supplier_scorecard/supplier_scorecard_list.js @@ -5,13 +5,11 @@ frappe.listview_settings["Supplier Scorecard"] = { add_fields: ["indicator_color", "status"], - get_indicator: function(doc) { - + get_indicator: function (doc) { if (doc.indicator_color) { return [__(doc.status), doc.indicator_color.toLowerCase(), "status,=," + doc.status]; } else { return [__("Unknown"), "gray", "status,=,''"]; } }, - }; diff --git a/erpnext/buying/doctype/supplier_scorecard_criteria/supplier_scorecard_criteria.js b/erpnext/buying/doctype/supplier_scorecard_criteria/supplier_scorecard_criteria.js index 9f8a2dee81da..4bd05676f8cd 100644 --- a/erpnext/buying/doctype/supplier_scorecard_criteria/supplier_scorecard_criteria.js +++ b/erpnext/buying/doctype/supplier_scorecard_criteria/supplier_scorecard_criteria.js @@ -4,5 +4,5 @@ /* global frappe */ frappe.ui.form.on("Supplier Scorecard Criteria", { - refresh: function() {} + refresh: function () {}, }); diff --git a/erpnext/buying/doctype/supplier_scorecard_period/supplier_scorecard_period.js b/erpnext/buying/doctype/supplier_scorecard_period/supplier_scorecard_period.js index a4cdeb31957b..267822f8ff4a 100644 --- a/erpnext/buying/doctype/supplier_scorecard_period/supplier_scorecard_period.js +++ b/erpnext/buying/doctype/supplier_scorecard_period/supplier_scorecard_period.js @@ -3,14 +3,13 @@ /* global frappe */ - frappe.ui.form.on("Supplier Scorecard Period", { - onload: function(frm) { + onload: function (frm) { let criteria_grid = frm.get_field("criteria").grid; criteria_grid.toggle_enable("criteria_name", false); criteria_grid.toggle_enable("weight", false); criteria_grid.toggle_display("max_score", true); criteria_grid.toggle_display("formula", true); criteria_grid.toggle_display("score", true); - } + }, }); diff --git a/erpnext/buying/doctype/supplier_scorecard_standing/supplier_scorecard_standing.js b/erpnext/buying/doctype/supplier_scorecard_standing/supplier_scorecard_standing.js index dccfcc34bb92..025b23a812f7 100644 --- a/erpnext/buying/doctype/supplier_scorecard_standing/supplier_scorecard_standing.js +++ b/erpnext/buying/doctype/supplier_scorecard_standing/supplier_scorecard_standing.js @@ -4,7 +4,5 @@ /* global frappe */ frappe.ui.form.on("Supplier Scorecard Standing", { - refresh: function() { - - } + refresh: function () {}, }); diff --git a/erpnext/buying/doctype/supplier_scorecard_variable/supplier_scorecard_variable.js b/erpnext/buying/doctype/supplier_scorecard_variable/supplier_scorecard_variable.js index 2d74fdd190a5..67af0edd27fb 100644 --- a/erpnext/buying/doctype/supplier_scorecard_variable/supplier_scorecard_variable.js +++ b/erpnext/buying/doctype/supplier_scorecard_variable/supplier_scorecard_variable.js @@ -4,7 +4,5 @@ /* global frappe */ frappe.ui.form.on("Supplier Scorecard Variable", { - refresh: function() { - - } + refresh: function () {}, }); diff --git a/erpnext/buying/report/procurement_tracker/procurement_tracker.js b/erpnext/buying/report/procurement_tracker/procurement_tracker.js index 283d56c94696..7127c60b286c 100644 --- a/erpnext/buying/report/procurement_tracker/procurement_tracker.js +++ b/erpnext/buying/report/procurement_tracker/procurement_tracker.js @@ -3,7 +3,7 @@ /* eslint-disable */ frappe.query_reports["Procurement Tracker"] = { - "filters": [ + filters: [ { fieldname: "company", label: __("Company"), @@ -30,10 +30,10 @@ frappe.query_reports["Procurement Tracker"] = { default: frappe.defaults.get_user_default("year_start_date"), }, { - fieldname:"to_date", + fieldname: "to_date", label: __("To Date"), fieldtype: "Date", default: frappe.defaults.get_user_default("year_end_date"), }, - ] -} + ], +}; diff --git a/erpnext/buying/report/purchase_analytics/purchase_analytics.js b/erpnext/buying/report/purchase_analytics/purchase_analytics.js index a884f06d2c2f..91958d520a76 100644 --- a/erpnext/buying/report/purchase_analytics/purchase_analytics.js +++ b/erpnext/buying/report/purchase_analytics/purchase_analytics.js @@ -3,47 +3,47 @@ /* eslint-disable */ frappe.query_reports["Purchase Analytics"] = { - "filters": [ + filters: [ { fieldname: "tree_type", label: __("Tree Type"), fieldtype: "Select", - options: ["Supplier Group","Supplier","Item Group","Item"], + options: ["Supplier Group", "Supplier", "Item Group", "Item"], default: "Supplier", - reqd: 1 + reqd: 1, }, { fieldname: "doc_type", label: __("based_on"), fieldtype: "Select", - options: ["Purchase Order","Purchase Receipt","Purchase Invoice"], + options: ["Purchase Order", "Purchase Receipt", "Purchase Invoice"], default: "Purchase Invoice", - reqd: 1 + reqd: 1, }, { fieldname: "value_quantity", label: __("Value Or Qty"), fieldtype: "Select", options: [ - { "value": "Value", "label": __("Value") }, - { "value": "Quantity", "label": __("Quantity") }, + { value: "Value", label: __("Value") }, + { value: "Quantity", label: __("Quantity") }, ], default: "Value", - reqd: 1 + reqd: 1, }, { fieldname: "from_date", label: __("From Date"), fieldtype: "Date", default: frappe.defaults.get_user_default("year_start_date"), - reqd: 1 + reqd: 1, }, { - fieldname:"to_date", + fieldname: "to_date", label: __("To Date"), fieldtype: "Date", default: frappe.defaults.get_user_default("year_end_date"), - reqd: 1 + reqd: 1, }, { fieldname: "company", @@ -51,22 +51,21 @@ frappe.query_reports["Purchase Analytics"] = { fieldtype: "Link", options: "Company", default: frappe.defaults.get_user_default("Company"), - reqd: 1 + reqd: 1, }, { fieldname: "range", label: __("Range"), fieldtype: "Select", options: [ - { "value": "Weekly", "label": __("Weekly") }, - { "value": "Monthly", "label": __("Monthly") }, - { "value": "Quarterly", "label": __("Quarterly") }, - { "value": "Yearly", "label": __("Yearly") } + { value: "Weekly", label: __("Weekly") }, + { value: "Monthly", label: __("Monthly") }, + { value: "Quarterly", label: __("Quarterly") }, + { value: "Yearly", label: __("Yearly") }, ], default: "Monthly", - reqd: 1 - } - + reqd: 1, + }, ], get_datatable_options(options) { return Object.assign(options, { @@ -75,9 +74,7 @@ frappe.query_reports["Purchase Analytics"] = { onCheckRow: function (data) { if (!data) return; - const data_doctype = $( - data[2].html - )[0].attributes.getNamedItem("data-doctype").value; + const data_doctype = $(data[2].html)[0].attributes.getNamedItem("data-doctype").value; const tree_type = frappe.query_report.filters[0].value; if (data_doctype != tree_type) return; @@ -85,23 +82,17 @@ frappe.query_reports["Purchase Analytics"] = { length = data.length; if (tree_type == "Supplier") { - row_values = data - .slice(4, length - 1) - .map(function (column) { - return column.content; - }); + row_values = data.slice(4, length - 1).map(function (column) { + return column.content; + }); } else if (tree_type == "Item") { - row_values = data - .slice(5, length - 1) - .map(function (column) { - return column.content; - }); + row_values = data.slice(5, length - 1).map(function (column) { + return column.content; + }); } else { - row_values = data - .slice(3, length - 1) - .map(function (column) { - return column.content; - }); + row_values = data.slice(3, length - 1).map(function (column) { + return column.content; + }); } entry = { @@ -112,13 +103,13 @@ frappe.query_reports["Purchase Analytics"] = { let raw_data = frappe.query_report.chart.data; let new_datasets = raw_data.datasets; - let element_found = new_datasets.some((element, index, array)=>{ - if(element.name == row_name){ - array.splice(index, 1) - return true + let element_found = new_datasets.some((element, index, array) => { + if (element.name == row_name) { + array.splice(index, 1); + return true; } - return false - }) + return false; + }); if (!element_found) { new_datasets.push(entry); @@ -127,12 +118,14 @@ frappe.query_reports["Purchase Analytics"] = { labels: raw_data.labels, datasets: new_datasets, }; - const new_options = Object.assign({}, frappe.query_report.chart_options, {data: new_data}); + const new_options = Object.assign({}, frappe.query_report.chart_options, { + data: new_data, + }); frappe.query_report.render_chart(new_options); frappe.query_report.raw_chart_data = new_data; }, }, }); - } -} + }, +}; diff --git a/erpnext/buying/report/purchase_order_analysis/purchase_order_analysis.js b/erpnext/buying/report/purchase_order_analysis/purchase_order_analysis.js index 721e54e46f58..ad2a9e887371 100644 --- a/erpnext/buying/report/purchase_order_analysis/purchase_order_analysis.js +++ b/erpnext/buying/report/purchase_order_analysis/purchase_order_analysis.js @@ -3,78 +3,78 @@ /* eslint-disable */ frappe.query_reports["Purchase Order Analysis"] = { - "filters": [ + filters: [ { - "fieldname": "company", - "label": __("Company"), - "fieldtype": "Link", - "width": "80", - "options": "Company", - "reqd": 1, - "default": frappe.defaults.get_default("company") + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + width: "80", + options: "Company", + reqd: 1, + default: frappe.defaults.get_default("company"), }, { - "fieldname":"from_date", - "label": __("From Date"), - "fieldtype": "Date", - "width": "80", - "reqd": 1, - "default": frappe.datetime.add_months(frappe.datetime.get_today(), -1), + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + width: "80", + reqd: 1, + default: frappe.datetime.add_months(frappe.datetime.get_today(), -1), }, { - "fieldname":"to_date", - "label": __("To Date"), - "fieldtype": "Date", - "width": "80", - "reqd": 1, - "default": frappe.datetime.get_today() + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + width: "80", + reqd: 1, + default: frappe.datetime.get_today(), }, { - "fieldname":"project", - "label": __("Project"), - "fieldtype": "Link", - "width": "80", - "options": "Project" + fieldname: "project", + label: __("Project"), + fieldtype: "Link", + width: "80", + options: "Project", }, { - "fieldname": "name", - "label": __("Purchase Order"), - "fieldtype": "Link", - "width": "80", - "options": "Purchase Order", - "get_query": () =>{ + fieldname: "name", + label: __("Purchase Order"), + fieldtype: "Link", + width: "80", + options: "Purchase Order", + get_query: () => { return { - filters: { "docstatus": 1 } - } - } + filters: { docstatus: 1 }, + }; + }, }, { - "fieldname": "status", - "label": __("Status"), - "fieldtype": "MultiSelectList", - "width": "80", - get_data: function(txt) { - let status = ["To Bill", "To Receive", "To Receive and Bill", "Completed"] - let options = [] - for (let option of status){ + fieldname: "status", + label: __("Status"), + fieldtype: "MultiSelectList", + width: "80", + get_data: function (txt) { + let status = ["To Bill", "To Receive", "To Receive and Bill", "Completed"]; + let options = []; + for (let option of status) { options.push({ - "value": option, - "label": __(option), - "description": "" - }) + value: option, + label: __(option), + description: "", + }); } - return options - } + return options; + }, }, { - "fieldname": "group_by_po", - "label": __("Group by Purchase Order"), - "fieldtype": "Check", - "default": 0 - } + fieldname: "group_by_po", + label: __("Group by Purchase Order"), + fieldtype: "Check", + default: 0, + }, ], - "formatter": function (value, row, column, data, default_formatter) { + formatter: function (value, row, column, data, default_formatter) { value = default_formatter(value, row, column, data); let format_fields = ["received_qty", "billed_amount"]; @@ -82,5 +82,5 @@ frappe.query_reports["Purchase Order Analysis"] = { value = "" + value + ""; } return value; - } + }, }; diff --git a/erpnext/buying/report/purchase_order_trends/purchase_order_trends.js b/erpnext/buying/report/purchase_order_trends/purchase_order_trends.js index 90919dcc6a3c..366fff191a01 100644 --- a/erpnext/buying/report/purchase_order_trends/purchase_order_trends.js +++ b/erpnext/buying/report/purchase_order_trends/purchase_order_trends.js @@ -1,8 +1,8 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -frappe.require("assets/erpnext/js/purchase_trends_filters.js", function() { +frappe.require("assets/erpnext/js/purchase_trends_filters.js", function () { frappe.query_reports["Purchase Order Trends"] = { - filters: erpnext.get_purchase_trends_filters() - } + filters: erpnext.get_purchase_trends_filters(), + }; }); diff --git a/erpnext/buying/report/requested_items_to_order_and_receive/requested_items_to_order_and_receive.js b/erpnext/buying/report/requested_items_to_order_and_receive/requested_items_to_order_and_receive.js index d727584d0aa2..5dd309bc9154 100644 --- a/erpnext/buying/report/requested_items_to_order_and_receive/requested_items_to_order_and_receive.js +++ b/erpnext/buying/report/requested_items_to_order_and_receive/requested_items_to_order_and_receive.js @@ -3,74 +3,74 @@ /* eslint-disable */ frappe.query_reports["Requested Items to Order and Receive"] = { - "filters": [ + filters: [ { - "fieldname": "company", - "label": __("Company"), - "fieldtype": "Link", - "width": "80", - "options": "Company", - "reqd": 1, - "default": frappe.defaults.get_default("company") + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + width: "80", + options: "Company", + reqd: 1, + default: frappe.defaults.get_default("company"), }, { - "fieldname":"from_date", - "label": __("From Date"), - "fieldtype": "Date", - "width": "80", - "reqd": 1, - "default": frappe.datetime.add_months(frappe.datetime.get_today(), -1), + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + width: "80", + reqd: 1, + default: frappe.datetime.add_months(frappe.datetime.get_today(), -1), }, { - "fieldname":"to_date", - "label": __("To Date"), - "fieldtype": "Date", - "width": "80", - "reqd": 1, - "default": frappe.datetime.get_today() + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + width: "80", + reqd: 1, + default: frappe.datetime.get_today(), }, { - "fieldname": "material_request", - "label": __("Material Request"), - "fieldtype": "Link", - "width": "80", - "options": "Material Request", - "get_query": () => { + fieldname: "material_request", + label: __("Material Request"), + fieldtype: "Link", + width: "80", + options: "Material Request", + get_query: () => { return { filters: { - "docstatus": 1, - "material_request_type": "Purchase", - "per_received": ["<", 100] - } - } - } + docstatus: 1, + material_request_type: "Purchase", + per_received: ["<", 100], + }, + }; + }, }, { - "fieldname": "item_code", - "label": __("Item"), - "fieldtype": "Link", - "width": "80", - "options": "Item", - "get_query": () => { + fieldname: "item_code", + label: __("Item"), + fieldtype: "Link", + width: "80", + options: "Item", + get_query: () => { return { - query: "erpnext.controllers.queries.item_query" - } - } + query: "erpnext.controllers.queries.item_query", + }; + }, }, { - "fieldname": "group_by_mr", - "label": __("Group by Material Request"), - "fieldtype": "Check", - "default": 0 - } + fieldname: "group_by_mr", + label: __("Group by Material Request"), + fieldtype: "Check", + default: 0, + }, ], - "formatter": function (value, row, column, data, default_formatter) { + formatter: function (value, row, column, data, default_formatter) { value = default_formatter(value, row, column, data); if (column.fieldname == "ordered_qty" && data && data.ordered_qty > 0) { value = "" + value + ""; } return value; - } + }, }; diff --git a/erpnext/buying/report/subcontract_order_summary/subcontract_order_summary.js b/erpnext/buying/report/subcontract_order_summary/subcontract_order_summary.js index 075671f4ec69..ab413925d5f9 100644 --- a/erpnext/buying/report/subcontract_order_summary/subcontract_order_summary.js +++ b/erpnext/buying/report/subcontract_order_summary/subcontract_order_summary.js @@ -3,40 +3,40 @@ /* eslint-disable */ frappe.query_reports["Subcontract Order Summary"] = { - "filters": [ + filters: [ { label: __("Company"), fieldname: "company", fieldtype: "Link", options: "Company", default: frappe.defaults.get_user_default("Company"), - reqd: 1 + reqd: 1, }, { label: __("From Date"), fieldname: "from_date", fieldtype: "Date", default: frappe.datetime.add_months(frappe.datetime.get_today(), -1), - reqd: 1 + reqd: 1, }, { label: __("To Date"), fieldname: "to_date", fieldtype: "Date", default: frappe.datetime.get_today(), - reqd: 1 + reqd: 1, }, { label: __("Order Type"), fieldname: "order_type", fieldtype: "Select", options: ["Purchase Order", "Subcontracting Order"], - default: "Subcontracting Order" + default: "Subcontracting Order", }, { label: __("Subcontract Order"), fieldname: "name", - fieldtype: "Data" - } - ] -}; \ No newline at end of file + fieldtype: "Data", + }, + ], +}; diff --git a/erpnext/buying/report/subcontracted_item_to_be_received/subcontracted_item_to_be_received.js b/erpnext/buying/report/subcontracted_item_to_be_received/subcontracted_item_to_be_received.js index 9db769d59bf8..44fbb3408ffb 100644 --- a/erpnext/buying/report/subcontracted_item_to_be_received/subcontracted_item_to_be_received.js +++ b/erpnext/buying/report/subcontracted_item_to_be_received/subcontracted_item_to_be_received.js @@ -3,34 +3,34 @@ /* eslint-disable */ frappe.query_reports["Subcontracted Item To Be Received"] = { - "filters": [ + filters: [ { label: __("Order Type"), fieldname: "order_type", fieldtype: "Select", options: ["Purchase Order", "Subcontracting Order"], - default: "Subcontracting Order" + default: "Subcontracting Order", }, { fieldname: "supplier", label: __("Supplier"), fieldtype: "Link", options: "Supplier", - reqd: 1 + reqd: 1, }, { - fieldname:"from_date", + fieldname: "from_date", label: __("From Date"), fieldtype: "Date", default: frappe.datetime.add_months(frappe.datetime.get_today(), -1), - reqd: 1 + reqd: 1, }, { - fieldname:"to_date", + fieldname: "to_date", label: __("To Date"), fieldtype: "Date", default: frappe.datetime.get_today(), - reqd: 1 + reqd: 1, }, - ] + ], }; diff --git a/erpnext/buying/report/subcontracted_raw_materials_to_be_transferred/subcontracted_raw_materials_to_be_transferred.js b/erpnext/buying/report/subcontracted_raw_materials_to_be_transferred/subcontracted_raw_materials_to_be_transferred.js index 7e5338f353b4..da19b5bbd36d 100644 --- a/erpnext/buying/report/subcontracted_raw_materials_to_be_transferred/subcontracted_raw_materials_to_be_transferred.js +++ b/erpnext/buying/report/subcontracted_raw_materials_to_be_transferred/subcontracted_raw_materials_to_be_transferred.js @@ -3,34 +3,34 @@ /* eslint-disable */ frappe.query_reports["Subcontracted Raw Materials To Be Transferred"] = { - "filters": [ + filters: [ { label: __("Order Type"), fieldname: "order_type", fieldtype: "Select", options: ["Purchase Order", "Subcontracting Order"], - default: "Subcontracting Order" + default: "Subcontracting Order", }, { fieldname: "supplier", label: __("Supplier"), fieldtype: "Link", options: "Supplier", - reqd: 1 + reqd: 1, }, { - fieldname:"from_date", + fieldname: "from_date", label: __("From Date"), fieldtype: "Date", default: frappe.datetime.add_months(frappe.datetime.get_today(), -1), - reqd: 1 + reqd: 1, }, { - fieldname:"to_date", + fieldname: "to_date", label: __("To Date"), fieldtype: "Date", default: frappe.datetime.get_today(), - reqd: 1 + reqd: 1, }, - ] -} + ], +}; diff --git a/erpnext/buying/report/supplier_quotation_comparison/supplier_quotation_comparison.js b/erpnext/buying/report/supplier_quotation_comparison/supplier_quotation_comparison.js index 579c0a65ad94..c109abd8146a 100644 --- a/erpnext/buying/report/supplier_quotation_comparison/supplier_quotation_comparison.js +++ b/erpnext/buying/report/supplier_quotation_comparison/supplier_quotation_comparison.js @@ -9,23 +9,23 @@ frappe.query_reports["Supplier Quotation Comparison"] = { options: "Company", fieldname: "company", default: frappe.defaults.get_user_default("Company"), - "reqd": 1 + reqd: 1, }, { - "fieldname":"from_date", - "label": __("From Date"), - "fieldtype": "Date", - "width": "80", - "reqd": 1, - "default": frappe.datetime.add_months(frappe.datetime.get_today(), -1), + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + width: "80", + reqd: 1, + default: frappe.datetime.add_months(frappe.datetime.get_today(), -1), }, { - "fieldname":"to_date", - "label": __("To Date"), - "fieldtype": "Date", - "width": "80", - "reqd": 1, - "default": frappe.datetime.get_today() + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + width: "80", + reqd: 1, + default: frappe.datetime.get_today(), }, { default: "", @@ -34,34 +34,34 @@ frappe.query_reports["Supplier Quotation Comparison"] = { fieldname: "item_code", fieldtype: "Link", get_query: () => { - let quote = frappe.query_report.get_filter_value('supplier_quotation'); + let quote = frappe.query_report.get_filter_value("supplier_quotation"); if (quote != "") { return { query: "erpnext.stock.doctype.quality_inspection.quality_inspection.item_query", filters: { - "from": "Supplier Quotation Item", - "parent": quote - } - } + from: "Supplier Quotation Item", + parent: quote, + }, + }; } - } + }, }, { fieldname: "supplier", label: __("Supplier"), fieldtype: "MultiSelectList", - get_data: function(txt) { - return frappe.db.get_link_options('Supplier', txt); - } + get_data: function (txt) { + return frappe.db.get_link_options("Supplier", txt); + }, }, { fieldtype: "MultiSelectList", label: __("Supplier Quotation"), fieldname: "supplier_quotation", default: "", - get_data: function(txt) { - return frappe.db.get_link_options('Supplier Quotation', txt, {'docstatus': ["<", 2]}); - } + get_data: function (txt) { + return frappe.db.get_link_options("Supplier Quotation", txt, { docstatus: ["<", 2] }); + }, }, { fieldtype: "Link", @@ -70,37 +70,36 @@ frappe.query_reports["Supplier Quotation Comparison"] = { fieldname: "request_for_quotation", default: "", get_query: () => { - return { filters: { "docstatus": ["<", 2] } } - } + return { filters: { docstatus: ["<", 2] } }; + }, }, { - "fieldname":"group_by", - "label": __("Group by"), - "fieldtype": "Select", - "options": [__("Group by Supplier"), __("Group by Item")], - "default": __("Group by Supplier") + fieldname: "group_by", + label: __("Group by"), + fieldtype: "Select", + options: [__("Group by Supplier"), __("Group by Item")], + default: __("Group by Supplier"), }, { fieldtype: "Check", label: __("Include Expired"), fieldname: "include_expired", - default: 0 - } + default: 0, + }, ], formatter: (value, row, column, data, default_formatter) => { value = default_formatter(value, row, column, data); - if(column.fieldname === "valid_till" && data.valid_till){ - if(frappe.datetime.get_diff(data.valid_till, frappe.datetime.nowdate()) <= 1){ + if (column.fieldname === "valid_till" && data.valid_till) { + if (frappe.datetime.get_diff(data.valid_till, frappe.datetime.nowdate()) <= 1) { value = `
      ${value}
      `; - } - else if (frappe.datetime.get_diff(data.valid_till, frappe.datetime.nowdate()) <= 7){ + } else if (frappe.datetime.get_diff(data.valid_till, frappe.datetime.nowdate()) <= 7) { value = `
      ${value}
      `; } } - if(column.fieldname === "price_per_unit" && data.price_per_unit && data.min && data.min === 1){ + if (column.fieldname === "price_per_unit" && data.price_per_unit && data.min && data.min === 1) { value = `
      ${value}
      `; } return value; @@ -108,48 +107,53 @@ frappe.query_reports["Supplier Quotation Comparison"] = { onload: (report) => { // Create a button for setting the default supplier - report.page.add_inner_button(__("Select Default Supplier"), () => { - let reporter = frappe.query_reports["Supplier Quotation Comparison"]; - - //Always make a new one so that the latest values get updated - reporter.make_default_supplier_dialog(report); - }, __("Tools")); + report.page.add_inner_button( + __("Select Default Supplier"), + () => { + let reporter = frappe.query_reports["Supplier Quotation Comparison"]; + //Always make a new one so that the latest values get updated + reporter.make_default_supplier_dialog(report); + }, + __("Tools") + ); }, make_default_supplier_dialog: (report) => { // Get the name of the item to change - if(!report.data) return; + if (!report.data) return; let filters = report.get_values(); let item_code = filters.item_code; // Get a list of the suppliers (with a blank as well) for the user to select - let suppliers = $.map(report.data, (row, idx)=>{ return row.supplier_name }) + let suppliers = $.map(report.data, (row, idx) => { + return row.supplier_name; + }); // Create a dialog window for the user to pick their supplier let dialog = new frappe.ui.Dialog({ - title: __('Select Default Supplier'), + title: __("Select Default Supplier"), fields: [ { reqd: 1, - label: 'Supplier', - fieldtype: 'Link', - options: 'Supplier', - fieldname: 'supplier', + label: "Supplier", + fieldtype: "Link", + options: "Supplier", + fieldname: "supplier", get_query: () => { return { filters: { - 'name': ['in', suppliers] - } - } - } - } - ] + name: ["in", suppliers], + }, + }; + }, + }, + ], }); dialog.set_primary_action(__("Set Default Supplier"), () => { let values = dialog.get_values(); - if(values) { + if (values) { // Set the default_supplier field of the appropriate Item to the selected supplier frappe.call({ method: "frappe.client.set_value", @@ -163,10 +167,10 @@ frappe.query_reports["Supplier Quotation Comparison"] = { callback: (r) => { frappe.msgprint(__("Successfully Set Supplier")); dialog.hide(); - } + }, }); } }); dialog.show(); - } -} + }, +}; diff --git a/erpnext/crm/doctype/appointment/appointment.js b/erpnext/crm/doctype/appointment/appointment.js index ca38121b1cfd..54aa9a6b716d 100644 --- a/erpnext/crm/doctype/appointment/appointment.js +++ b/erpnext/crm/doctype/appointment/appointment.js @@ -1,26 +1,26 @@ // Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Appointment', { - refresh: function(frm) { - if(frm.doc.lead){ - frm.add_custom_button(frm.doc.lead,()=>{ +frappe.ui.form.on("Appointment", { + refresh: function (frm) { + if (frm.doc.lead) { + frm.add_custom_button(frm.doc.lead, () => { frappe.set_route("Form", "Lead", frm.doc.lead); }); } - if(frm.doc.calendar_event){ - frm.add_custom_button(__(frm.doc.calendar_event),()=>{ + if (frm.doc.calendar_event) { + frm.add_custom_button(__(frm.doc.calendar_event), () => { frappe.set_route("Form", "Event", frm.doc.calendar_event); }); } }, - onload: function(frm){ - frm.set_query("appointment_with", function(){ + onload: function (frm) { + frm.set_query("appointment_with", function () { return { - filters : { - "name": ["in", ["Customer", "Lead"]] - } + filters: { + name: ["in", ["Customer", "Lead"]], + }, }; }); - } + }, }); diff --git a/erpnext/crm/doctype/appointment_booking_settings/appointment_booking_settings.js b/erpnext/crm/doctype/appointment_booking_settings/appointment_booking_settings.js index 0c64eb8e822b..255e665a4d2f 100644 --- a/erpnext/crm/doctype/appointment_booking_settings/appointment_booking_settings.js +++ b/erpnext/crm/doctype/appointment_booking_settings/appointment_booking_settings.js @@ -1,10 +1,14 @@ -frappe.ui.form.on('Appointment Booking Settings', 'validate',check_times); +frappe.ui.form.on("Appointment Booking Settings", "validate", check_times); function check_times(frm) { $.each(frm.doc.availability_of_slots || [], function (i, d) { - let from_time = Date.parse('01/01/2019 ' + d.from_time); - let to_time = Date.parse('01/01/2019 ' + d.to_time); + let from_time = Date.parse("01/01/2019 " + d.from_time); + let to_time = Date.parse("01/01/2019 " + d.to_time); if (from_time > to_time) { - frappe.throw(__('In row {0} of Appointment Booking Slots: "To Time" must be later than "From Time".', [i + 1])); + frappe.throw( + __('In row {0} of Appointment Booking Slots: "To Time" must be later than "From Time".', [ + i + 1, + ]) + ); } }); } diff --git a/erpnext/crm/doctype/campaign/campaign.js b/erpnext/crm/doctype/campaign/campaign.js index cac45c682cbf..9e4a0a953621 100644 --- a/erpnext/crm/doctype/campaign/campaign.js +++ b/erpnext/crm/doctype/campaign/campaign.js @@ -1,17 +1,25 @@ // Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Campaign', { - refresh: function(frm) { +frappe.ui.form.on("Campaign", { + refresh: function (frm) { erpnext.toggle_naming_series(); if (frm.is_new()) { - frm.toggle_display("naming_series", frappe.boot.sysdefaults.campaign_naming_by=="Naming Series"); + frm.toggle_display( + "naming_series", + frappe.boot.sysdefaults.campaign_naming_by == "Naming Series" + ); } else { - cur_frm.add_custom_button(__("View Leads"), function() { - frappe.route_options = {"source": "Campaign", "campaign_name": frm.doc.name}; - frappe.set_route("List", "Lead"); - }, "fa fa-list", true); + cur_frm.add_custom_button( + __("View Leads"), + function () { + frappe.route_options = { source: "Campaign", campaign_name: frm.doc.name }; + frappe.set_route("List", "Lead"); + }, + "fa fa-list", + true + ); } - } + }, }); diff --git a/erpnext/crm/doctype/competitor/competitor.js b/erpnext/crm/doctype/competitor/competitor.js index a5b617dc74ce..abd59346b8aa 100644 --- a/erpnext/crm/doctype/competitor/competitor.js +++ b/erpnext/crm/doctype/competitor/competitor.js @@ -1,8 +1,7 @@ // Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Competitor', { +frappe.ui.form.on("Competitor", { // refresh: function(frm) { - // } }); diff --git a/erpnext/crm/doctype/contract/contract.js b/erpnext/crm/doctype/contract/contract.js index 7848de7a7279..8d44c22db28f 100644 --- a/erpnext/crm/doctype/contract/contract.js +++ b/erpnext/crm/doctype/contract/contract.js @@ -5,12 +5,12 @@ frappe.ui.form.on("Contract", { contract_template: function (frm) { if (frm.doc.contract_template) { frappe.call({ - method: 'erpnext.crm.doctype.contract_template.contract_template.get_contract_template', + method: "erpnext.crm.doctype.contract_template.contract_template.get_contract_template", args: { template_name: frm.doc.contract_template, - doc: frm.doc + doc: frm.doc, }, - callback: function(r) { + callback: function (r) { if (r && r.message) { let contract_template = r.message.contract_template; frm.set_value("contract_terms", r.message.contract_terms); @@ -18,15 +18,15 @@ frappe.ui.form.on("Contract", { if (frm.doc.requires_fulfilment) { // Populate the fulfilment terms table from a contract template, if any - r.message.contract_template.fulfilment_terms.forEach(element => { + r.message.contract_template.fulfilment_terms.forEach((element) => { let d = frm.add_child("fulfilment_terms"); d.requirement = element.requirement; }); frm.refresh_field("fulfilment_terms"); } } - } + }, }); } - } + }, }); diff --git a/erpnext/crm/doctype/contract/contract_list.js b/erpnext/crm/doctype/contract/contract_list.js index 7d5609651a15..e1f8c22f70ea 100644 --- a/erpnext/crm/doctype/contract/contract_list.js +++ b/erpnext/crm/doctype/contract/contract_list.js @@ -1,4 +1,4 @@ -frappe.listview_settings['Contract'] = { +frappe.listview_settings["Contract"] = { add_fields: ["status"], get_indicator: function (doc) { if (doc.status == "Unsigned") { diff --git a/erpnext/crm/doctype/contract_fulfilment_checklist/contract_fulfilment_checklist.js b/erpnext/crm/doctype/contract_fulfilment_checklist/contract_fulfilment_checklist.js index f0525b13e22a..bdc3fcc4696c 100644 --- a/erpnext/crm/doctype/contract_fulfilment_checklist/contract_fulfilment_checklist.js +++ b/erpnext/crm/doctype/contract_fulfilment_checklist/contract_fulfilment_checklist.js @@ -1,8 +1,6 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Contract Fulfilment Checklist', { - refresh: function(frm) { - - } +frappe.ui.form.on("Contract Fulfilment Checklist", { + refresh: function (frm) {}, }); diff --git a/erpnext/crm/doctype/contract_template/contract_template.js b/erpnext/crm/doctype/contract_template/contract_template.js index 4f7c9a8dc976..5044bbe996c1 100644 --- a/erpnext/crm/doctype/contract_template/contract_template.js +++ b/erpnext/crm/doctype/contract_template/contract_template.js @@ -1,8 +1,6 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Contract Template', { - refresh: function(frm) { - - } +frappe.ui.form.on("Contract Template", { + refresh: function (frm) {}, }); diff --git a/erpnext/crm/doctype/crm_settings/crm_settings.js b/erpnext/crm/doctype/crm_settings/crm_settings.js index c6569d8122ee..0fb695a3da49 100644 --- a/erpnext/crm/doctype/crm_settings/crm_settings.js +++ b/erpnext/crm/doctype/crm_settings/crm_settings.js @@ -1,8 +1,7 @@ // Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('CRM Settings', { +frappe.ui.form.on("CRM Settings", { // refresh: function(frm) { - // } }); diff --git a/erpnext/crm/doctype/email_campaign/email_campaign.js b/erpnext/crm/doctype/email_campaign/email_campaign.js index b0e935360945..7b090a06ef5b 100644 --- a/erpnext/crm/doctype/email_campaign/email_campaign.js +++ b/erpnext/crm/doctype/email_campaign/email_campaign.js @@ -1,8 +1,8 @@ // Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Email Campaign', { - email_campaign_for: function(frm) { - frm.set_value('recipient', ''); - } +frappe.ui.form.on("Email Campaign", { + email_campaign_for: function (frm) { + frm.set_value("recipient", ""); + }, }); diff --git a/erpnext/crm/doctype/email_campaign/email_campaign_list.js b/erpnext/crm/doctype/email_campaign/email_campaign_list.js index adc399da0f0c..3020921e2e4c 100644 --- a/erpnext/crm/doctype/email_campaign/email_campaign_list.js +++ b/erpnext/crm/doctype/email_campaign/email_campaign_list.js @@ -1,11 +1,11 @@ -frappe.listview_settings['Email Campaign'] = { - get_indicator: function(doc) { +frappe.listview_settings["Email Campaign"] = { + get_indicator: function (doc) { var colors = { - "Unsubscribed": "red", - "Scheduled": "blue", + Unsubscribed: "red", + Scheduled: "blue", "In Progress": "orange", - "Completed": "green" + Completed: "green", }; return [__(doc.status), colors[doc.status], "status,=," + doc.status]; - } + }, }; diff --git a/erpnext/crm/doctype/lead/lead.js b/erpnext/crm/doctype/lead/lead.js index b98a27ede8e8..8336130d50b9 100644 --- a/erpnext/crm/doctype/lead/lead.js +++ b/erpnext/crm/doctype/lead/lead.js @@ -5,46 +5,50 @@ frappe.provide("erpnext"); cur_frm.email_field = "email_id"; erpnext.LeadController = class LeadController extends frappe.ui.form.Controller { - setup () { + setup() { this.frm.make_methods = { - 'Customer': this.make_customer, - 'Quotation': this.make_quotation, - 'Opportunity': this.make_opportunity + Customer: this.make_customer, + Quotation: this.make_quotation, + Opportunity: this.make_opportunity, }; // For avoiding integration issues. - this.frm.set_df_property('first_name', 'reqd', true); + this.frm.set_df_property("first_name", "reqd", true); } - onload () { + onload() { this.frm.set_query("customer", function (doc, cdt, cdn) { - return { query: "erpnext.controllers.queries.customer_query" } + return { query: "erpnext.controllers.queries.customer_query" }; }); this.frm.set_query("lead_owner", function (doc, cdt, cdn) { - return { query: "frappe.core.doctype.user.user.user_query" } + return { query: "frappe.core.doctype.user.user.user_query" }; }); } - refresh () { + refresh() { var me = this; let doc = this.frm.doc; erpnext.toggle_naming_series(); frappe.dynamic_link = { doc: doc, - fieldname: 'name', - doctype: 'Lead' + fieldname: "name", + doctype: "Lead", }; if (!this.frm.is_new() && doc.__onload && !doc.__onload.is_customer) { this.frm.add_custom_button(__("Customer"), this.make_customer, __("Create")); - this.frm.add_custom_button(__("Opportunity"), function() { - me.frm.trigger("make_opportunity"); - }, __("Create")); + this.frm.add_custom_button( + __("Opportunity"), + function () { + me.frm.trigger("make_opportunity"); + }, + __("Create") + ); this.frm.add_custom_button(__("Quotation"), this.make_quotation, __("Create")); if (!doc.__onload.linked_prospects.length) { this.frm.add_custom_button(__("Prospect"), this.make_prospect, __("Create")); - this.frm.add_custom_button(__('Add to Prospect'), this.add_lead_to_prospect, __('Action')); + this.frm.add_custom_button(__("Add to Prospect"), this.add_lead_to_prospect, __("Action")); } } @@ -58,50 +62,54 @@ erpnext.LeadController = class LeadController extends frappe.ui.form.Controller this.show_activities(); } - add_lead_to_prospect () { - frappe.prompt([ - { - fieldname: 'prospect', - label: __('Prospect'), - fieldtype: 'Link', - options: 'Prospect', - reqd: 1 - } - ], - function(data) { - frappe.call({ - method: 'erpnext.crm.doctype.lead.lead.add_lead_to_prospect', - args: { - 'lead': cur_frm.doc.name, - 'prospect': data.prospect - }, - callback: function(r) { - if (!r.exc) { - frm.reload_doc(); - } + add_lead_to_prospect() { + frappe.prompt( + [ + { + fieldname: "prospect", + label: __("Prospect"), + fieldtype: "Link", + options: "Prospect", + reqd: 1, }, - freeze: true, - freeze_message: __('Adding Lead to Prospect...') - }); - }, __('Add Lead to Prospect'), __('Add')); + ], + function (data) { + frappe.call({ + method: "erpnext.crm.doctype.lead.lead.add_lead_to_prospect", + args: { + lead: cur_frm.doc.name, + prospect: data.prospect, + }, + callback: function (r) { + if (!r.exc) { + frm.reload_doc(); + } + }, + freeze: true, + freeze_message: __("Adding Lead to Prospect..."), + }); + }, + __("Add Lead to Prospect"), + __("Add") + ); } - make_customer () { + make_customer() { frappe.model.open_mapped_doc({ method: "erpnext.crm.doctype.lead.lead.make_customer", - frm: cur_frm - }) + frm: cur_frm, + }); } - make_quotation () { + make_quotation() { frappe.model.open_mapped_doc({ method: "erpnext.crm.doctype.lead.lead.make_quotation", - frm: cur_frm - }) + frm: cur_frm, + }); } - make_prospect () { - frappe.model.with_doctype("Prospect", function() { + make_prospect() { + frappe.model.with_doctype("Prospect", function () { let prospect = frappe.model.get_new_doc("Prospect"); prospect.company_name = cur_frm.doc.company_name; prospect.no_of_employees = cur_frm.doc.no_of_employees; @@ -113,14 +121,14 @@ erpnext.LeadController = class LeadController extends frappe.ui.form.Controller prospect.prospect_owner = cur_frm.doc.lead_owner; prospect.notes = cur_frm.doc.notes; - let leads_row = frappe.model.add_child(prospect, 'leads'); + let leads_row = frappe.model.add_child(prospect, "leads"); leads_row.lead = cur_frm.doc.name; frappe.set_route("Form", "Prospect", prospect.name); }); } - company_name () { + company_name() { if (!this.frm.doc.lead_name) { this.frm.set_value("lead_name", this.frm.doc.company_name); } @@ -149,86 +157,91 @@ erpnext.LeadController = class LeadController extends frappe.ui.form.Controller } }; - extend_cscript(cur_frm.cscript, new erpnext.LeadController({ frm: cur_frm })); frappe.ui.form.on("Lead", { - make_opportunity: async function(frm) { - let existing_prospect = (await frappe.db.get_value("Prospect Lead", - { - "lead": frm.doc.name - }, - "name", null, "Prospect" - )).message.name; + make_opportunity: async function (frm) { + let existing_prospect = ( + await frappe.db.get_value( + "Prospect Lead", + { + lead: frm.doc.name, + }, + "name", + null, + "Prospect" + ) + ).message.name; if (!existing_prospect) { var fields = [ { - "label": "Create Prospect", - "fieldname": "create_prospect", - "fieldtype": "Check", - "default": 1 + label: "Create Prospect", + fieldname: "create_prospect", + fieldtype: "Check", + default: 1, }, { - "label": "Prospect Name", - "fieldname": "prospect_name", - "fieldtype": "Data", - "default": frm.doc.company_name, - "depends_on": "create_prospect" - } + label: "Prospect Name", + fieldname: "prospect_name", + fieldtype: "Data", + default: frm.doc.company_name, + depends_on: "create_prospect", + }, ]; } - let existing_contact = (await frappe.db.get_value("Contact", - { - "first_name": frm.doc.first_name || frm.doc.lead_name, - "last_name": frm.doc.last_name - }, - "name" - )).message.name; + let existing_contact = ( + await frappe.db.get_value( + "Contact", + { + first_name: frm.doc.first_name || frm.doc.lead_name, + last_name: frm.doc.last_name, + }, + "name" + ) + ).message.name; if (!existing_contact) { - fields.push( - { - "label": "Create Contact", - "fieldname": "create_contact", - "fieldtype": "Check", - "default": "1" - } - ); + fields.push({ + label: "Create Contact", + fieldname: "create_contact", + fieldtype: "Check", + default: "1", + }); } if (fields) { var d = new frappe.ui.Dialog({ - title: __('Create Opportunity'), + title: __("Create Opportunity"), fields: fields, - primary_action: function() { + primary_action: function () { var data = d.get_values(); frappe.call({ - method: 'create_prospect_and_contact', + method: "create_prospect_and_contact", doc: frm.doc, args: { data: data, }, freeze: true, - callback: function(r) { + callback: function (r) { if (!r.exc) { frappe.model.open_mapped_doc({ method: "erpnext.crm.doctype.lead.lead.make_opportunity", - frm: frm + frm: frm, }); } d.hide(); - } + }, }); }, - primary_action_label: __('Create') + primary_action_label: __("Create"), }); d.show(); } else { frappe.model.open_mapped_doc({ method: "erpnext.crm.doctype.lead.lead.make_opportunity", - frm: frm + frm: frm, }); } - } -}); \ No newline at end of file + }, +}); diff --git a/erpnext/crm/doctype/lead/lead_list.js b/erpnext/crm/doctype/lead/lead_list.js index dbeaf608ffc4..97415251a93e 100644 --- a/erpnext/crm/doctype/lead/lead_list.js +++ b/erpnext/crm/doctype/lead/lead_list.js @@ -1,28 +1,42 @@ -frappe.listview_settings['Lead'] = { - onload: function(listview) { +frappe.listview_settings["Lead"] = { + onload: function (listview) { if (frappe.boot.user.can_create.includes("Prospect")) { - listview.page.add_action_item(__("Create Prospect"), function() { - frappe.model.with_doctype("Prospect", function() { + listview.page.add_action_item(__("Create Prospect"), function () { + frappe.model.with_doctype("Prospect", function () { let prospect = frappe.model.get_new_doc("Prospect"); let leads = listview.get_checked_items(); - frappe.db.get_value("Lead", leads[0].name, ["company_name", "no_of_employees", "industry", "market_segment", "territory", "fax", "website", "lead_owner"], (r) => { - prospect.company_name = r.company_name; - prospect.no_of_employees = r.no_of_employees; - prospect.industry = r.industry; - prospect.market_segment = r.market_segment; - prospect.territory = r.territory; - prospect.fax = r.fax; - prospect.website = r.website; - prospect.prospect_owner = r.lead_owner; + frappe.db.get_value( + "Lead", + leads[0].name, + [ + "company_name", + "no_of_employees", + "industry", + "market_segment", + "territory", + "fax", + "website", + "lead_owner", + ], + (r) => { + prospect.company_name = r.company_name; + prospect.no_of_employees = r.no_of_employees; + prospect.industry = r.industry; + prospect.market_segment = r.market_segment; + prospect.territory = r.territory; + prospect.fax = r.fax; + prospect.website = r.website; + prospect.prospect_owner = r.lead_owner; - leads.forEach(function(lead) { - let lead_prospect_row = frappe.model.add_child(prospect, 'leads'); - lead_prospect_row.lead = lead.name; - }); - frappe.set_route("Form", "Prospect", prospect.name); - }); + leads.forEach(function (lead) { + let lead_prospect_row = frappe.model.add_child(prospect, "leads"); + lead_prospect_row.lead = lead.name; + }); + frappe.set_route("Form", "Prospect", prospect.name); + } + ); }); }); } - } + }, }; diff --git a/erpnext/crm/doctype/lead_source/lead_source.js b/erpnext/crm/doctype/lead_source/lead_source.js index 3cbe64920905..5efc750601a1 100644 --- a/erpnext/crm/doctype/lead_source/lead_source.js +++ b/erpnext/crm/doctype/lead_source/lead_source.js @@ -1,8 +1,7 @@ // Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Lead Source', { +frappe.ui.form.on("Lead Source", { // refresh: function(frm) { - // } }); diff --git a/erpnext/crm/doctype/linkedin_settings/linkedin_settings.js b/erpnext/crm/doctype/linkedin_settings/linkedin_settings.js index 7d6b3955cde5..70cf4df95198 100644 --- a/erpnext/crm/doctype/linkedin_settings/linkedin_settings.js +++ b/erpnext/crm/doctype/linkedin_settings/linkedin_settings.js @@ -1,23 +1,29 @@ // Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('LinkedIn Settings', { - onload: function(frm) { - if (frm.doc.session_status == 'Expired' && frm.doc.consumer_key && frm.doc.consumer_secret) { +frappe.ui.form.on("LinkedIn Settings", { + onload: function (frm) { + if (frm.doc.session_status == "Expired" && frm.doc.consumer_key && frm.doc.consumer_secret) { frappe.confirm( - __('Session not valid. Do you want to login?'), - function(){ + __("Session not valid. Do you want to login?"), + function () { frm.trigger("login"); }, - function(){ + function () { window.close(); } ); } - frm.dashboard.set_headline(__("For more information, {0}.", [`${__('click here')}`])); + frm.dashboard.set_headline( + __("For more information, {0}.", [ + `${__( + "click here" + )}`, + ]) + ); }, - refresh: function(frm) { - if (frm.doc.session_status=="Expired"){ + refresh: function (frm) { + if (frm.doc.session_status == "Expired") { let msg = __("Session not active. Save document to login."); frm.dashboard.set_headline_alert( `
      @@ -28,19 +34,18 @@ frappe.ui.form.on('LinkedIn Settings', { ); } - if (frm.doc.session_status=="Active"){ + if (frm.doc.session_status == "Active") { let d = new Date(frm.doc.modified); - d.setDate(d.getDate()+60); + d.setDate(d.getDate() + 60); let dn = new Date(); let days = d.getTime() - dn.getTime(); - days = Math.floor(days/(1000 * 3600 * 24)); - let msg,color; + days = Math.floor(days / (1000 * 3600 * 24)); + let msg, color; - if (days>0){ + if (days > 0) { msg = __("Your session will be expire in {0} days.", [days]); color = "green"; - } - else { + } else { msg = __("Session is expired. Save doc to login."); color = "red"; } @@ -54,21 +59,23 @@ frappe.ui.form.on('LinkedIn Settings', { ); } }, - login: function(frm) { - if (frm.doc.consumer_key && frm.doc.consumer_secret){ + login: function (frm) { + if (frm.doc.consumer_key && frm.doc.consumer_secret) { frappe.dom.freeze(); - frappe.call({ - doc: frm.doc, - method: "get_authorization_url", - callback : function(r) { - window.location.href = r.message; - } - }).fail(function() { - frappe.dom.unfreeze(); - }); + frappe + .call({ + doc: frm.doc, + method: "get_authorization_url", + callback: function (r) { + window.location.href = r.message; + }, + }) + .fail(function () { + frappe.dom.unfreeze(); + }); } }, - after_save: function(frm) { + after_save: function (frm) { frm.trigger("login"); - } + }, }); diff --git a/erpnext/crm/doctype/lost_reason_detail/lost_reason_detail.js b/erpnext/crm/doctype/lost_reason_detail/lost_reason_detail.js index 08fbdad4a5a1..c3081f8a4d03 100644 --- a/erpnext/crm/doctype/lost_reason_detail/lost_reason_detail.js +++ b/erpnext/crm/doctype/lost_reason_detail/lost_reason_detail.js @@ -1,8 +1,6 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Lost Reason Detail', { - refresh: function() { - - } +frappe.ui.form.on("Lost Reason Detail", { + refresh: function () {}, }); diff --git a/erpnext/crm/doctype/market_segment/market_segment.js b/erpnext/crm/doctype/market_segment/market_segment.js index 94ffdee75d9c..b089c52b5c9c 100644 --- a/erpnext/crm/doctype/market_segment/market_segment.js +++ b/erpnext/crm/doctype/market_segment/market_segment.js @@ -1,8 +1,6 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Market Segment', { - refresh: function(frm) { - - } +frappe.ui.form.on("Market Segment", { + refresh: function (frm) {}, }); diff --git a/erpnext/crm/doctype/opportunity/opportunity_list.js b/erpnext/crm/doctype/opportunity/opportunity_list.js index 24b05145fd2a..5028ae178c75 100644 --- a/erpnext/crm/doctype/opportunity/opportunity_list.js +++ b/erpnext/crm/doctype/opportunity/opportunity_list.js @@ -1,31 +1,31 @@ -frappe.listview_settings['Opportunity'] = { +frappe.listview_settings["Opportunity"] = { add_fields: ["customer_name", "opportunity_type", "opportunity_from", "status"], - get_indicator: function(doc) { + get_indicator: function (doc) { var indicator = [__(doc.status), frappe.utils.guess_colour(doc.status), "status,=," + doc.status]; - if(doc.status=="Quotation") { + if (doc.status == "Quotation") { indicator[1] = "green"; } return indicator; }, - onload: function(listview) { + onload: function (listview) { var method = "erpnext.crm.doctype.opportunity.opportunity.set_multiple_status"; - listview.page.add_menu_item(__("Set as Open"), function() { - listview.call_for_selected_items(method, {"status": "Open"}); + listview.page.add_menu_item(__("Set as Open"), function () { + listview.call_for_selected_items(method, { status: "Open" }); }); - listview.page.add_menu_item(__("Set as Closed"), function() { - listview.call_for_selected_items(method, {"status": "Closed"}); + listview.page.add_menu_item(__("Set as Closed"), function () { + listview.call_for_selected_items(method, { status: "Closed" }); }); - if(listview.page.fields_dict.opportunity_from) { - listview.page.fields_dict.opportunity_from.get_query = function() { + if (listview.page.fields_dict.opportunity_from) { + listview.page.fields_dict.opportunity_from.get_query = function () { return { - "filters": { - "name": ["in", ["Customer", "Lead"]], - } + filters: { + name: ["in", ["Customer", "Lead"]], + }, }; }; } - } + }, }; diff --git a/erpnext/crm/doctype/opportunity_lost_reason/opportunity_lost_reason.js b/erpnext/crm/doctype/opportunity_lost_reason/opportunity_lost_reason.js index 877dd592b22f..3f08355442f7 100644 --- a/erpnext/crm/doctype/opportunity_lost_reason/opportunity_lost_reason.js +++ b/erpnext/crm/doctype/opportunity_lost_reason/opportunity_lost_reason.js @@ -1,8 +1,6 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Opportunity Lost Reason', { - refresh: function() { - - } +frappe.ui.form.on("Opportunity Lost Reason", { + refresh: function () {}, }); diff --git a/erpnext/crm/doctype/opportunity_type/opportunity_type.js b/erpnext/crm/doctype/opportunity_type/opportunity_type.js index 174625e73c69..18213ad0cdf3 100644 --- a/erpnext/crm/doctype/opportunity_type/opportunity_type.js +++ b/erpnext/crm/doctype/opportunity_type/opportunity_type.js @@ -1,8 +1,6 @@ // Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Opportunity Type', { - refresh: function(frm) { - - } +frappe.ui.form.on("Opportunity Type", { + refresh: function (frm) {}, }); diff --git a/erpnext/crm/doctype/prospect/prospect.js b/erpnext/crm/doctype/prospect/prospect.js index 495ed291ae94..62039b33b983 100644 --- a/erpnext/crm/doctype/prospect/prospect.js +++ b/erpnext/crm/doctype/prospect/prospect.js @@ -1,25 +1,33 @@ // Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Prospect', { - refresh (frm) { +frappe.ui.form.on("Prospect", { + refresh(frm) { frappe.dynamic_link = { doc: frm.doc, fieldname: "name", doctype: frm.doctype }; if (!frm.is_new() && frappe.boot.user.can_create.includes("Customer")) { - frm.add_custom_button(__("Customer"), function() { - frappe.model.open_mapped_doc({ - method: "erpnext.crm.doctype.prospect.prospect.make_customer", - frm: frm - }); - }, __("Create")); + frm.add_custom_button( + __("Customer"), + function () { + frappe.model.open_mapped_doc({ + method: "erpnext.crm.doctype.prospect.prospect.make_customer", + frm: frm, + }); + }, + __("Create") + ); } if (!frm.is_new() && frappe.boot.user.can_create.includes("Opportunity")) { - frm.add_custom_button(__("Opportunity"), function() { - frappe.model.open_mapped_doc({ - method: "erpnext.crm.doctype.prospect.prospect.make_opportunity", - frm: frm - }); - }, __("Create")); + frm.add_custom_button( + __("Opportunity"), + function () { + frappe.model.open_mapped_doc({ + method: "erpnext.crm.doctype.prospect.prospect.make_opportunity", + frm: frm, + }); + }, + __("Create") + ); } if (!frm.is_new()) { @@ -31,7 +39,7 @@ frappe.ui.form.on('Prospect', { frm.trigger("show_activities"); }, - show_notes (frm) { + show_notes(frm) { const crm_notes = new erpnext.utils.CRMNotes({ frm: frm, notes_wrapper: $(frm.fields_dict.notes_html.wrapper), @@ -39,7 +47,7 @@ frappe.ui.form.on('Prospect', { crm_notes.refresh(); }, - show_activities (frm) { + show_activities(frm) { const crm_activities = new erpnext.utils.CRMActivities({ frm: frm, open_activities_wrapper: $(frm.fields_dict.open_activities_html.wrapper), @@ -47,6 +55,5 @@ frappe.ui.form.on('Prospect', { form_wrapper: $(frm.wrapper), }); crm_activities.refresh(); - } - + }, }); diff --git a/erpnext/crm/doctype/sales_stage/sales_stage.js b/erpnext/crm/doctype/sales_stage/sales_stage.js index 0447f783ce63..c6811665a63b 100644 --- a/erpnext/crm/doctype/sales_stage/sales_stage.js +++ b/erpnext/crm/doctype/sales_stage/sales_stage.js @@ -1,8 +1,6 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Sales Stage', { - refresh: function(frm) { - - } +frappe.ui.form.on("Sales Stage", { + refresh: function (frm) {}, }); diff --git a/erpnext/crm/doctype/social_media_post/social_media_post.js b/erpnext/crm/doctype/social_media_post/social_media_post.js index d4ac0bad16cf..f7d0efc83d73 100644 --- a/erpnext/crm/doctype/social_media_post/social_media_post.js +++ b/erpnext/crm/doctype/social_media_post/social_media_post.js @@ -1,7 +1,7 @@ // Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Social Media Post', { - validate: function(frm) { +frappe.ui.form.on("Social Media Post", { + validate: function (frm) { if (frm.doc.twitter === 0 && frm.doc.linkedin === 0) { frappe.throw(__("Select atleast one Social Media Platform to Share on.")); } @@ -12,111 +12,116 @@ frappe.ui.form.on('Social Media Post', { frappe.throw(__("Scheduled Time must be a future time.")); } } - frm.trigger('validate_tweet_length'); + frm.trigger("validate_tweet_length"); }, - text: function(frm) { + text: function (frm) { if (frm.doc.text) { - frm.set_df_property('text', 'description', `${frm.doc.text.length}/280`); - frm.refresh_field('text'); - frm.trigger('validate_tweet_length'); + frm.set_df_property("text", "description", `${frm.doc.text.length}/280`); + frm.refresh_field("text"); + frm.trigger("validate_tweet_length"); } }, - validate_tweet_length: function(frm) { + validate_tweet_length: function (frm) { if (frm.doc.text && frm.doc.text.length > 280) { frappe.throw(__("Tweet length Must be less than 280.")); } }, - onload: function(frm) { - frm.trigger('make_dashboard'); + onload: function (frm) { + frm.trigger("make_dashboard"); }, - make_dashboard: function(frm) { + make_dashboard: function (frm) { if (frm.doc.post_status == "Posted") { frappe.call({ doc: frm.doc, - method: 'get_post', + method: "get_post", freeze: true, callback: (r) => { if (!r.message) { return; } - let datasets = [], colors = []; + let datasets = [], + colors = []; if (r.message && r.message.twitter) { - colors.push('#1DA1F2'); + colors.push("#1DA1F2"); datasets.push({ - name: 'Twitter', - values: [r.message.twitter.favorite_count, r.message.twitter.retweet_count] + name: "Twitter", + values: [r.message.twitter.favorite_count, r.message.twitter.retweet_count], }); } if (r.message && r.message.linkedin) { - colors.push('#0077b5'); + colors.push("#0077b5"); datasets.push({ - name: 'LinkedIn', - values: [r.message.linkedin.totalShareStatistics.likeCount, r.message.linkedin.totalShareStatistics.shareCount] + name: "LinkedIn", + values: [ + r.message.linkedin.totalShareStatistics.likeCount, + r.message.linkedin.totalShareStatistics.shareCount, + ], }); } if (datasets.length) { frm.dashboard.render_graph({ data: { - labels: ['Likes', 'Retweets/Shares'], - datasets: datasets + labels: ["Likes", "Retweets/Shares"], + datasets: datasets, }, title: __("Post Metrics"), - type: 'bar', + type: "bar", height: 300, - colors: colors + colors: colors, }); } - } + }, }); } }, - refresh: function(frm) { - frm.trigger('text'); + refresh: function (frm) { + frm.trigger("text"); if (frm.doc.docstatus === 1) { - if (!['Posted', 'Deleted'].includes(frm.doc.post_status)) { - frm.trigger('add_post_btn'); + if (!["Posted", "Deleted"].includes(frm.doc.post_status)) { + frm.trigger("add_post_btn"); } - if (frm.doc.post_status !='Deleted') { - frm.add_custom_button(__('Delete Post'), function() { - frappe.confirm(__('Are you sure want to delete the Post from Social Media platforms?'), - function() { + if (frm.doc.post_status != "Deleted") { + frm.add_custom_button(__("Delete Post"), function () { + frappe.confirm( + __("Are you sure want to delete the Post from Social Media platforms?"), + function () { frappe.call({ doc: frm.doc, - method: 'delete_post', + method: "delete_post", freeze: true, callback: () => { frm.reload_doc(); - } + }, }); } ); }); } - if (frm.doc.post_status !='Deleted') { - let html=''; + if (frm.doc.post_status != "Deleted") { + let html = ""; if (frm.doc.twitter) { let color = frm.doc.twitter_post_id ? "green" : "red"; let status = frm.doc.twitter_post_id ? "Posted" : "Not Posted"; html += `
      Twitter : ${status} -
      ` ; +
      `; } if (frm.doc.linkedin) { let color = frm.doc.linkedin_post_id ? "green" : "red"; let status = frm.doc.linkedin_post_id ? "Posted" : "Not Posted"; html += `
      LinkedIn : ${status} -
      ` ; +
      `; } html = `
      ${html}
      `; frm.dashboard.set_headline_alert(html); @@ -124,16 +129,16 @@ frappe.ui.form.on('Social Media Post', { } }, - add_post_btn: function(frm) { - frm.add_custom_button(__('Post Now'), function() { + add_post_btn: function (frm) { + frm.add_custom_button(__("Post Now"), function () { frappe.call({ doc: frm.doc, - method: 'post', + method: "post", freeze: true, - callback: function() { + callback: function () { frm.reload_doc(); - } + }, }); }); - } + }, }); diff --git a/erpnext/crm/doctype/social_media_post/social_media_post_list.js b/erpnext/crm/doctype/social_media_post/social_media_post_list.js index a8c8272ad08f..ab7b44c9eaa0 100644 --- a/erpnext/crm/doctype/social_media_post/social_media_post_list.js +++ b/erpnext/crm/doctype/social_media_post/social_media_post_list.js @@ -1,11 +1,14 @@ -frappe.listview_settings['Social Media Post'] = { +frappe.listview_settings["Social Media Post"] = { add_fields: ["status", "post_status"], - get_indicator: function(doc) { - return [__(doc.post_status), { - "Scheduled": "orange", - "Posted": "green", - "Error": "red", - "Deleted": "red" - }[doc.post_status]]; - } -} + get_indicator: function (doc) { + return [ + __(doc.post_status), + { + Scheduled: "orange", + Posted: "green", + Error: "red", + Deleted: "red", + }[doc.post_status], + ]; + }, +}; diff --git a/erpnext/crm/doctype/twitter_settings/twitter_settings.js b/erpnext/crm/doctype/twitter_settings/twitter_settings.js index c322092d6f3e..a84e01d07c4a 100644 --- a/erpnext/crm/doctype/twitter_settings/twitter_settings.js +++ b/erpnext/crm/doctype/twitter_settings/twitter_settings.js @@ -1,31 +1,38 @@ // Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Twitter Settings', { - onload: function(frm) { - if (frm.doc.session_status == 'Expired' && frm.doc.consumer_key && frm.doc.consumer_secret){ +frappe.ui.form.on("Twitter Settings", { + onload: function (frm) { + if (frm.doc.session_status == "Expired" && frm.doc.consumer_key && frm.doc.consumer_secret) { frappe.confirm( - __('Session not valid, Do you want to login?'), - function(){ + __("Session not valid, Do you want to login?"), + function () { frm.trigger("login"); }, - function(){ + function () { window.close(); } ); } - frm.dashboard.set_headline(__("For more information, {0}.", [`${__('click here')}`])); + frm.dashboard.set_headline( + __("For more information, {0}.", [ + `${__( + "click here" + )}`, + ]) + ); }, - refresh: function(frm) { - let msg, color, flag=false; + refresh: function (frm) { + let msg, + color, + flag = false; if (frm.doc.session_status == "Active") { msg = __("Session Active"); - color = 'green'; + color = "green"; flag = true; - } - else if(frm.doc.consumer_key && frm.doc.consumer_secret) { + } else if (frm.doc.consumer_key && frm.doc.consumer_secret) { msg = __("Session Not Active. Save doc to login."); - color = 'red'; + color = "red"; flag = true; } @@ -39,21 +46,23 @@ frappe.ui.form.on('Twitter Settings', { ); } }, - login: function(frm) { - if (frm.doc.consumer_key && frm.doc.consumer_secret){ + login: function (frm) { + if (frm.doc.consumer_key && frm.doc.consumer_secret) { frappe.dom.freeze(); - frappe.call({ - doc: frm.doc, - method: "get_authorize_url", - callback : function(r) { - window.location.href = r.message; - } - }).fail(function() { - frappe.dom.unfreeze(); - }); + frappe + .call({ + doc: frm.doc, + method: "get_authorize_url", + callback: function (r) { + window.location.href = r.message; + }, + }) + .fail(function () { + frappe.dom.unfreeze(); + }); } }, - after_save: function(frm) { + after_save: function (frm) { frm.trigger("login"); - } + }, }); diff --git a/erpnext/crm/report/campaign_efficiency/campaign_efficiency.js b/erpnext/crm/report/campaign_efficiency/campaign_efficiency.js index f29c2c64e146..d2c52938bde0 100644 --- a/erpnext/crm/report/campaign_efficiency/campaign_efficiency.js +++ b/erpnext/crm/report/campaign_efficiency/campaign_efficiency.js @@ -1,18 +1,18 @@ // Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt frappe.query_reports["Campaign Efficiency"] = { - "filters": [ + filters: [ { - "fieldname": "from_date", - "label": __("From Date"), - "fieldtype": "Date", - "default": frappe.defaults.get_user_default("year_start_date"), + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + default: frappe.defaults.get_user_default("year_start_date"), }, { - "fieldname": "to_date", - "label": __("To Date"), - "fieldtype": "Date", - "default": frappe.defaults.get_user_default("year_end_date"), - } - ] + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + default: frappe.defaults.get_user_default("year_end_date"), + }, + ], }; diff --git a/erpnext/crm/report/first_response_time_for_opportunity/first_response_time_for_opportunity.js b/erpnext/crm/report/first_response_time_for_opportunity/first_response_time_for_opportunity.js index fe5707af2960..b2ebe2914a9d 100644 --- a/erpnext/crm/report/first_response_time_for_opportunity/first_response_time_for_opportunity.js +++ b/erpnext/crm/report/first_response_time_for_opportunity/first_response_time_for_opportunity.js @@ -3,41 +3,43 @@ /* eslint-disable */ frappe.query_reports["First Response Time for Opportunity"] = { - "filters": [ + filters: [ { - "fieldname": "from_date", - "label": __("From Date"), - "fieldtype": "Date", - "reqd": 1, - "default": frappe.datetime.add_days(frappe.datetime.nowdate(), -30) + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + reqd: 1, + default: frappe.datetime.add_days(frappe.datetime.nowdate(), -30), }, { - "fieldname": "to_date", - "label": __("To Date"), - "fieldtype": "Date", - "reqd": 1, - "default": frappe.datetime.nowdate() + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + reqd: 1, + default: frappe.datetime.nowdate(), }, ], get_chart_data: function (_columns, result) { return { data: { - labels: result.map(d => d.creation_date), - datasets: [{ - name: "First Response Time", - values: result.map(d => d.first_response_time) - }] + labels: result.map((d) => d.creation_date), + datasets: [ + { + name: "First Response Time", + values: result.map((d) => d.first_response_time), + }, + ], }, type: "line", tooltipOptions: { - formatTooltipY: d => { + formatTooltipY: (d) => { let duration_options = { hide_days: 0, - hide_seconds: 0 + hide_seconds: 0, }; return frappe.utils.get_formatted_duration(d, duration_options); - } - } - } - } + }, + }, + }; + }, }; diff --git a/erpnext/crm/report/lead_conversion_time/lead_conversion_time.js b/erpnext/crm/report/lead_conversion_time/lead_conversion_time.js index eeb8984513e5..baa34aebd10b 100644 --- a/erpnext/crm/report/lead_conversion_time/lead_conversion_time.js +++ b/erpnext/crm/report/lead_conversion_time/lead_conversion_time.js @@ -3,20 +3,20 @@ /* eslint-disable */ frappe.query_reports["Lead Conversion Time"] = { - "filters": [ + filters: [ { - "fieldname":"from_date", - "label": __("From Date"), - "fieldtype": "Date", - 'reqd': 1, - "default": frappe.datetime.add_days(frappe.datetime.nowdate(), -30) + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + reqd: 1, + default: frappe.datetime.add_days(frappe.datetime.nowdate(), -30), }, { - "fieldname":"to_date", - "label": __("To Date"), - "fieldtype": "Date", - 'reqd': 1, - "default":frappe.datetime.nowdate() + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + reqd: 1, + default: frappe.datetime.nowdate(), }, - ] + ], }; diff --git a/erpnext/crm/report/lead_details/lead_details.js b/erpnext/crm/report/lead_details/lead_details.js index 2f6d24224fb1..f2866e178002 100644 --- a/erpnext/crm/report/lead_details/lead_details.js +++ b/erpnext/crm/report/lead_details/lead_details.js @@ -3,50 +3,50 @@ /* eslint-disable */ frappe.query_reports["Lead Details"] = { - "filters": [ + filters: [ { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_user_default("Company"), - "reqd": 1 + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), + reqd: 1, }, { - "fieldname":"from_date", - "label": __("From Date"), - "fieldtype": "Date", - "default": frappe.datetime.add_months(frappe.datetime.get_today(), -12), - "reqd": 1 + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + default: frappe.datetime.add_months(frappe.datetime.get_today(), -12), + reqd: 1, }, { - "fieldname":"to_date", - "label": __("To Date"), - "fieldtype": "Date", - "default": frappe.datetime.get_today(), - "reqd": 1 + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + default: frappe.datetime.get_today(), + reqd: 1, }, { - "fieldname":"status", - "label": __("Status"), - "fieldtype": "Select", + fieldname: "status", + label: __("Status"), + fieldtype: "Select", options: [ - { "value": "Lead", "label": __("Lead") }, - { "value": "Open", "label": __("Open") }, - { "value": "Replied", "label": __("Replied") }, - { "value": "Opportunity", "label": __("Opportunity") }, - { "value": "Quotation", "label": __("Quotation") }, - { "value": "Lost Quotation", "label": __("Lost Quotation") }, - { "value": "Interested", "label": __("Interested") }, - { "value": "Converted", "label": __("Converted") }, - { "value": "Do Not Contact", "label": __("Do Not Contact") }, + { value: "Lead", label: __("Lead") }, + { value: "Open", label: __("Open") }, + { value: "Replied", label: __("Replied") }, + { value: "Opportunity", label: __("Opportunity") }, + { value: "Quotation", label: __("Quotation") }, + { value: "Lost Quotation", label: __("Lost Quotation") }, + { value: "Interested", label: __("Interested") }, + { value: "Converted", label: __("Converted") }, + { value: "Do Not Contact", label: __("Do Not Contact") }, ], }, { - "fieldname":"territory", - "label": __("Territory"), - "fieldtype": "Link", - "options": "Territory", - } - ] + fieldname: "territory", + label: __("Territory"), + fieldtype: "Link", + options: "Territory", + }, + ], }; diff --git a/erpnext/crm/report/lead_owner_efficiency/lead_owner_efficiency.js b/erpnext/crm/report/lead_owner_efficiency/lead_owner_efficiency.js index bbfd6ac9ff7f..c140567fed5d 100644 --- a/erpnext/crm/report/lead_owner_efficiency/lead_owner_efficiency.js +++ b/erpnext/crm/report/lead_owner_efficiency/lead_owner_efficiency.js @@ -1,17 +1,18 @@ // Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt - frappe.query_reports["Lead Owner Efficiency"] = { - "filters": [ - { - "fieldname": "from_date", - "label": __("From Date"), - "fieldtype": "Date", - "default": frappe.defaults.get_user_default("year_start_date"), - }, - { - "fieldname": "to_date", - "label": __("To Date"), - "fieldtype": "Date", - "default": frappe.defaults.get_user_default("year_end_date"), - } - ]}; +frappe.query_reports["Lead Owner Efficiency"] = { + filters: [ + { + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + default: frappe.defaults.get_user_default("year_start_date"), + }, + { + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + default: frappe.defaults.get_user_default("year_end_date"), + }, + ], +}; diff --git a/erpnext/crm/report/lost_opportunity/lost_opportunity.js b/erpnext/crm/report/lost_opportunity/lost_opportunity.js index 927c54df0728..1e8e13bf24d1 100644 --- a/erpnext/crm/report/lost_opportunity/lost_opportunity.js +++ b/erpnext/crm/report/lost_opportunity/lost_opportunity.js @@ -3,59 +3,59 @@ /* eslint-disable */ frappe.query_reports["Lost Opportunity"] = { - "filters": [ + filters: [ { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_user_default("Company"), - "reqd": 1 + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), + reqd: 1, }, { - "fieldname":"from_date", - "label": __("From Date"), - "fieldtype": "Date", - "default": frappe.datetime.add_months(frappe.datetime.get_today(), -12), - "reqd": 1 + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + default: frappe.datetime.add_months(frappe.datetime.get_today(), -12), + reqd: 1, }, { - "fieldname":"to_date", - "label": __("To Date"), - "fieldtype": "Date", - "default": frappe.datetime.get_today(), - "reqd": 1 + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + default: frappe.datetime.get_today(), + reqd: 1, }, { - "fieldname":"lost_reason", - "label": __("Lost Reason"), - "fieldtype": "Link", - "options": "Opportunity Lost Reason" + fieldname: "lost_reason", + label: __("Lost Reason"), + fieldtype: "Link", + options: "Opportunity Lost Reason", }, { - "fieldname":"territory", - "label": __("Territory"), - "fieldtype": "Link", - "options": "Territory" + fieldname: "territory", + label: __("Territory"), + fieldtype: "Link", + options: "Territory", }, { - "fieldname":"opportunity_from", - "label": __("Opportunity From"), - "fieldtype": "Link", - "options": "DocType", - "get_query": function() { + fieldname: "opportunity_from", + label: __("Opportunity From"), + fieldtype: "Link", + options: "DocType", + get_query: function () { return { - "filters": { - "name": ["in", ["Customer", "Lead"]], - } - } - } + filters: { + name: ["in", ["Customer", "Lead"]], + }, + }; + }, }, { - "fieldname":"party_name", - "label": __("Party"), - "fieldtype": "Dynamic Link", - "options": "opportunity_from" + fieldname: "party_name", + label: __("Party"), + fieldtype: "Dynamic Link", + options: "opportunity_from", }, - ] + ], }; diff --git a/erpnext/crm/report/opportunity_summary_by_sales_stage/opportunity_summary_by_sales_stage.js b/erpnext/crm/report/opportunity_summary_by_sales_stage/opportunity_summary_by_sales_stage.js index 7cd1710a7f20..5c449284ab63 100644 --- a/erpnext/crm/report/opportunity_summary_by_sales_stage/opportunity_summary_by_sales_stage.js +++ b/erpnext/crm/report/opportunity_summary_by_sales_stage/opportunity_summary_by_sales_stage.js @@ -3,26 +3,25 @@ /* eslint-disable */ frappe.query_reports["Opportunity Summary by Sales Stage"] = { - "filters": [ + filters: [ { fieldname: "based_on", label: __("Based On"), fieldtype: "Select", options: "Opportunity Owner\nSource\nOpportunity Type", - default: "Opportunity Owner" + default: "Opportunity Owner", }, { fieldname: "data_based_on", label: __("Data Based On"), fieldtype: "Select", options: "Number\nAmount", - default: "Number" + default: "Number", }, { fieldname: "from_date", label: __("From Date"), fieldtype: "Date", - }, { fieldname: "to_date", @@ -33,14 +32,14 @@ frappe.query_reports["Opportunity Summary by Sales Stage"] = { fieldname: "status", label: __("Status"), fieldtype: "MultiSelectList", - get_data: function() { + get_data: function () { return [ - {value: "Open", description: "Status"}, - {value: "Converted", description: "Status"}, - {value: "Quotation", description: "Status"}, - {value: "Replied", description: "Status"} - ] - } + { value: "Open", description: "Status" }, + { value: "Converted", description: "Status" }, + { value: "Quotation", description: "Status" }, + { value: "Replied", description: "Status" }, + ]; + }, }, { fieldname: "opportunity_source", @@ -59,7 +58,7 @@ frappe.query_reports["Opportunity Summary by Sales Stage"] = { label: __("Company"), fieldtype: "Link", options: "Company", - default: frappe.defaults.get_user_default("Company") - } - ] + default: frappe.defaults.get_user_default("Company"), + }, + ], }; diff --git a/erpnext/crm/report/prospects_engaged_but_not_converted/prospects_engaged_but_not_converted.js b/erpnext/crm/report/prospects_engaged_but_not_converted/prospects_engaged_but_not_converted.js index 6f37719f6399..d62594148238 100644 --- a/erpnext/crm/report/prospects_engaged_but_not_converted/prospects_engaged_but_not_converted.js +++ b/erpnext/crm/report/prospects_engaged_but_not_converted/prospects_engaged_but_not_converted.js @@ -2,24 +2,24 @@ // For license information, please see license.txt frappe.query_reports["Prospects Engaged But Not Converted"] = { - "filters": [ + filters: [ { - "fieldname": "lead", - "label": __("Lead"), - "fieldtype": "Link", - "options": "Lead" + fieldname: "lead", + label: __("Lead"), + fieldtype: "Link", + options: "Lead", }, { - "fieldname": "no_of_interaction", - "label": __("Number of Interaction"), - "fieldtype": "Int", - "default": 1 + fieldname: "no_of_interaction", + label: __("Number of Interaction"), + fieldtype: "Int", + default: 1, }, { - "fieldname": "lead_age", - "label": __("Minimum Lead Age (Days)"), - "fieldtype": "Int", - "default": 60 + fieldname: "lead_age", + label: __("Minimum Lead Age (Days)"), + fieldtype: "Int", + default: 60, }, - ] -} + ], +}; diff --git a/erpnext/crm/report/sales_pipeline_analytics/sales_pipeline_analytics.js b/erpnext/crm/report/sales_pipeline_analytics/sales_pipeline_analytics.js index 1426f4b6fd2a..149a97a907a4 100644 --- a/erpnext/crm/report/sales_pipeline_analytics/sales_pipeline_analytics.js +++ b/erpnext/crm/report/sales_pipeline_analytics/sales_pipeline_analytics.js @@ -3,68 +3,68 @@ /* eslint-disable */ frappe.query_reports["Sales Pipeline Analytics"] = { - "filters": [ + filters: [ { fieldname: "pipeline_by", label: __("Pipeline By"), fieldtype: "Select", options: "Owner\nSales Stage", - default: "Owner" + default: "Owner", }, { fieldname: "from_date", label: __("From Date"), - fieldtype: "Date" + fieldtype: "Date", }, { fieldname: "to_date", label: __("To Date"), - fieldtype: "Date" + fieldtype: "Date", }, { fieldname: "range", label: __("Range"), fieldtype: "Select", options: "Monthly\nQuarterly", - default: "Monthly" + default: "Monthly", }, { fieldname: "assigned_to", label: __("Assigned To"), fieldtype: "Link", - options: "User" + options: "User", }, { fieldname: "status", label: __("Status"), fieldtype: "Select", - options: "Open\nQuotation\nConverted\nReplied" + options: "Open\nQuotation\nConverted\nReplied", }, { fieldname: "based_on", label: __("Based On"), fieldtype: "Select", options: "Number\nAmount", - default: "Number" + default: "Number", }, { fieldname: "company", label: __("Company"), fieldtype: "Link", options: "Company", - default: frappe.defaults.get_user_default("Company") + default: frappe.defaults.get_user_default("Company"), }, { fieldname: "opportunity_source", label: __("Opportunity Source"), fieldtype: "Link", - options: "Lead Source" + options: "Lead Source", }, { fieldname: "opportunity_type", label: __("Opportunity Type"), fieldtype: "Link", - options: "Opportunity Type" + options: "Opportunity Type", }, - ] + ], }; diff --git a/erpnext/e_commerce/doctype/e_commerce_settings/e_commerce_settings.js b/erpnext/e_commerce/doctype/e_commerce_settings/e_commerce_settings.js index c37fa2f6eae4..d533eb82450b 100644 --- a/erpnext/e_commerce/doctype/e_commerce_settings/e_commerce_settings.js +++ b/erpnext/e_commerce/doctype/e_commerce_settings/e_commerce_settings.js @@ -2,57 +2,58 @@ // For license information, please see license.txt frappe.ui.form.on("E Commerce Settings", { - onload: function(frm) { - if(frm.doc.__onload && frm.doc.__onload.quotation_series) { + onload: function (frm) { + if (frm.doc.__onload && frm.doc.__onload.quotation_series) { frm.fields_dict.quotation_series.df.options = frm.doc.__onload.quotation_series; frm.refresh_field("quotation_series"); } - frm.set_query('payment_gateway_account', function() { - return { 'filters': { 'payment_channel': "Email" } }; + frm.set_query("payment_gateway_account", function () { + return { filters: { payment_channel: "Email" } }; }); }, - refresh: function(frm) { + refresh: function (frm) { if (frm.doc.enabled) { - frm.get_field('store_page_docs').$wrapper.removeClass('hide-control').html( - `
      ${__("Follow these steps to create a landing page for your store")}: + frm.get_field("store_page_docs") + .$wrapper.removeClass("hide-control") + .html( + `
      ${__("Follow these steps to create a landing page for your store")}: docs/store-landing-page
      ` - ); + ); } frappe.model.with_doctype("Website Item", () => { - const web_item_meta = frappe.get_meta('Website Item'); + const web_item_meta = frappe.get_meta("Website Item"); - const valid_fields = web_item_meta.fields.filter(df => - ["Link", "Table MultiSelect"].includes(df.fieldtype) && !df.hidden - ).map(df => - ({ label: df.label, value: df.fieldname }) - ); + const valid_fields = web_item_meta.fields + .filter((df) => ["Link", "Table MultiSelect"].includes(df.fieldtype) && !df.hidden) + .map((df) => ({ label: df.label, value: df.fieldname })); frm.get_field("filter_fields").grid.update_docfield_property( - 'fieldname', 'options', valid_fields + "fieldname", + "options", + valid_fields ); }); }, - enabled: function(frm) { + enabled: function (frm) { if (frm.doc.enabled === 1) { - frm.set_value('enable_variants', 1); - } - else { - frm.set_value('company', ''); - frm.set_value('price_list', ''); - frm.set_value('default_customer_group', ''); - frm.set_value('quotation_series', ''); + frm.set_value("enable_variants", 1); + } else { + frm.set_value("company", ""); + frm.set_value("price_list", ""); + frm.set_value("default_customer_group", ""); + frm.set_value("quotation_series", ""); } }, - enable_checkout: function(frm) { + enable_checkout: function (frm) { if (frm.doc.enable_checkout) { erpnext.utils.check_payments_app(); } - } + }, }); diff --git a/erpnext/e_commerce/doctype/item_review/item_review.js b/erpnext/e_commerce/doctype/item_review/item_review.js index a57c370287b4..69fc1cfff4ef 100644 --- a/erpnext/e_commerce/doctype/item_review/item_review.js +++ b/erpnext/e_commerce/doctype/item_review/item_review.js @@ -1,8 +1,7 @@ // Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Item Review', { +frappe.ui.form.on("Item Review", { // refresh: function(frm) { - // } }); diff --git a/erpnext/e_commerce/doctype/website_item/website_item.js b/erpnext/e_commerce/doctype/website_item/website_item.js index b6595cce8a9c..74dd7b8c90f5 100644 --- a/erpnext/e_commerce/doctype/website_item/website_item.js +++ b/erpnext/e_commerce/doctype/website_item/website_item.js @@ -1,37 +1,49 @@ // Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Website Item', { +frappe.ui.form.on("Website Item", { onload: (frm) => { // should never check Private frm.fields_dict["website_image"].df.is_private = 0; }, refresh: (frm) => { - frm.add_custom_button(__("Prices"), function() { - frappe.set_route("List", "Item Price", {"item_code": frm.doc.item_code}); - }, __("View")); + frm.add_custom_button( + __("Prices"), + function () { + frappe.set_route("List", "Item Price", { item_code: frm.doc.item_code }); + }, + __("View") + ); - frm.add_custom_button(__("Stock"), function() { - frappe.route_options = { - "item_code": frm.doc.item_code - }; - frappe.set_route("query-report", "Stock Balance"); - }, __("View")); + frm.add_custom_button( + __("Stock"), + function () { + frappe.route_options = { + item_code: frm.doc.item_code, + }; + frappe.set_route("query-report", "Stock Balance"); + }, + __("View") + ); - frm.add_custom_button(__("E Commerce Settings"), function() { - frappe.set_route("Form", "E Commerce Settings"); - }, __("View")); + frm.add_custom_button( + __("E Commerce Settings"), + function () { + frappe.set_route("Form", "E Commerce Settings"); + }, + __("View") + ); }, copy_from_item_group: (frm) => { return frm.call({ doc: frm.doc, - method: "copy_specification_from_item_group" + method: "copy_specification_from_item_group", }); }, set_meta_tags: (frm) => { frappe.utils.set_meta_tag(frm.doc.route); - } + }, }); diff --git a/erpnext/e_commerce/doctype/website_item/website_item_list.js b/erpnext/e_commerce/doctype/website_item/website_item_list.js index b9dd9214a38f..220746c9845e 100644 --- a/erpnext/e_commerce/doctype/website_item/website_item_list.js +++ b/erpnext/e_commerce/doctype/website_item/website_item_list.js @@ -1,20 +1,20 @@ -frappe.listview_settings['Website Item'] = { +frappe.listview_settings["Website Item"] = { add_fields: ["item_name", "web_item_name", "published", "website_image", "has_variants", "variant_of"], filters: [["published", "=", "1"]], - get_indicator: function(doc) { + get_indicator: function (doc) { if (doc.has_variants && doc.published) { return [__("Template"), "orange", "has_variants,=,Yes|published,=,1"]; } else if (doc.has_variants && !doc.published) { return [__("Template"), "grey", "has_variants,=,Yes|published,=,0"]; - } else if (doc.variant_of && doc.published) { + } else if (doc.variant_of && doc.published) { return [__("Variant"), "blue", "published,=,1|variant_of,=," + doc.variant_of]; - } else if (doc.variant_of && !doc.published) { + } else if (doc.variant_of && !doc.published) { return [__("Variant"), "grey", "published,=,0|variant_of,=," + doc.variant_of]; } else if (doc.published) { return [__("Published"), "green", "published,=,1"]; } else { return [__("Not Published"), "grey", "published,=,0"]; } - } -}; \ No newline at end of file + }, +}; diff --git a/erpnext/e_commerce/doctype/wishlist/wishlist.js b/erpnext/e_commerce/doctype/wishlist/wishlist.js index d96e552ecdb6..54a0a2381b1a 100644 --- a/erpnext/e_commerce/doctype/wishlist/wishlist.js +++ b/erpnext/e_commerce/doctype/wishlist/wishlist.js @@ -1,8 +1,7 @@ // Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Wishlist', { +frappe.ui.form.on("Wishlist", { // refresh: function(frm) { - // } }); diff --git a/erpnext/e_commerce/product_ui/grid.js b/erpnext/e_commerce/product_ui/grid.js index 20a6c30b52bc..1f0d1fbf43a8 100644 --- a/erpnext/e_commerce/product_ui/grid.js +++ b/erpnext/e_commerce/product_ui/grid.js @@ -20,9 +20,9 @@ erpnext.ProductGrid = class { let me = this; let html = ``; - this.items.forEach(item => { + this.items.forEach((item) => { let title = item.web_item_name || item.item_name || item.item_code || ""; - title = title.length > 90 ? title.substr(0, 90) + "..." : title; + title = title.length > 90 ? title.substr(0, 90) + "..." : title; html += `
      `; html += me.get_image_html(item, title); @@ -40,17 +40,17 @@ erpnext.ProductGrid = class { if (image) { return ` `; } else { return ` @@ -73,11 +73,10 @@ erpnext.ProductGrid = class { if (settings.enabled) { body_html += this.get_cart_indicator(item); } - } body_html += `
      `; - body_html += `
      ${ item.item_group || '' }
      `; + body_html += `
      ${item.item_group || ""}
      `; if (item.formatted_price) { body_html += this.get_price_html(item); @@ -92,9 +91,9 @@ erpnext.ProductGrid = class { get_title(item, title) { let title_html = ` - +
      - ${ title || '' } + ${title || ""}
      `; @@ -104,10 +103,10 @@ erpnext.ProductGrid = class { get_wishlist_icon(item) { let icon_class = item.wished ? "wished" : "not-wished"; return ` -
    And ${hidden_logs.length} more others
    ${__("Meta Data")}${__("Unresolve")}${__("Unresolve")}${__("Error Message")}${__("Create")}${__("Create")}
    - + @@ -115,28 +116,30 @@ erpnext.BOMComparisonTool = class BOMComparisonTool {
    ${__('Field')}${__("Field")} ${name1} ${name2}
    `; - } - - let value_changes = change_html(__('Values Changed'), doctype, diff.changed); + }; - let row_changes_by_fieldname = group_items(diff.row_changed, change => change[0]); + let value_changes = change_html(__("Values Changed"), doctype, diff.changed); - let table_changes = Object.keys(row_changes_by_fieldname).map(fieldname => { - let changes = row_changes_by_fieldname[fieldname]; - let df = frappe.meta.get_docfield(doctype, fieldname); + let row_changes_by_fieldname = group_items(diff.row_changed, (change) => change[0]); - let html = changes.map(change => { - let [fieldname,, item_code, changes] = change; + let table_changes = Object.keys(row_changes_by_fieldname) + .map((fieldname) => { + let changes = row_changes_by_fieldname[fieldname]; let df = frappe.meta.get_docfield(doctype, fieldname); - let child_doctype = df.options; - let values_changed = this.get_changed_values(child_doctype, changes); - return values_changed.map((change, i) => { - let [fieldname, value1, value2] = change; - let th = i === 0 - ? `${item_code}` - : ''; - return ` + let html = changes + .map((change) => { + let [fieldname, , item_code, changes] = change; + let df = frappe.meta.get_docfield(doctype, fieldname); + let child_doctype = df.options; + let values_changed = this.get_changed_values(child_doctype, changes); + + return values_changed + .map((change, i) => { + let [fieldname, value1, value2] = change; + let th = + i === 0 ? `${item_code}` : ""; + return ` ${th} ${frappe.meta.get_label(child_doctype, fieldname)} @@ -144,54 +147,58 @@ erpnext.BOMComparisonTool = class BOMComparisonTool { ${value2} `; - }).join(''); - }).join(''); + }) + .join(""); + }) + .join(""); - return ` -

    ${__('Changes in {0}', [df.label])}

    + return ` +

    ${__("Changes in {0}", [df.label])}

    - - + + ${html}
    ${__('Item Code')}${__('Field')}${__("Item Code")}${__("Field")} ${name1} ${name2}
    `; - }).join(''); + }) + .join(""); let get_added_removed_html = (title, grouped_items) => { - return Object.keys(grouped_items).map(fieldname => { - let rows = grouped_items[fieldname]; - let df = frappe.meta.get_docfield(doctype, fieldname); - let fields = frappe.meta.get_docfields(df.options) - .filter(df => df.in_list_view); - - let html = rows.map(row => { - let [, doc] = row; - let cells = fields - .map(df => `${doc[df.fieldname]}`) - .join(''); - return `${cells}`; - }).join(''); - - let header = fields.map(df => `${df.label}`).join(''); - return ` + return Object.keys(grouped_items) + .map((fieldname) => { + let rows = grouped_items[fieldname]; + let df = frappe.meta.get_docfield(doctype, fieldname); + let fields = frappe.meta.get_docfields(df.options).filter((df) => df.in_list_view); + + let html = rows + .map((row) => { + let [, doc] = row; + let cells = fields.map((df) => `${doc[df.fieldname]}`).join(""); + return `${cells}`; + }) + .join(""); + + let header = fields.map((df) => `${df.label}`).join(""); + return `

    ${$.format(title, [df.label])}

    ${header} ${html}
    `; - }).join(''); + }) + .join(""); }; - let added_by_fieldname = group_items(diff.added, change => change[0]); - let removed_by_fieldname = group_items(diff.removed, change => change[0]); + let added_by_fieldname = group_items(diff.added, (change) => change[0]); + let removed_by_fieldname = group_items(diff.removed, (change) => change[0]); - let added_html = get_added_removed_html(__('Rows Added in {0}'), added_by_fieldname); - let removed_html = get_added_removed_html(__('Rows Removed in {0}'), removed_by_fieldname); + let added_html = get_added_removed_html(__("Rows Added in {0}"), added_by_fieldname); + let removed_html = get_added_removed_html(__("Rows Removed in {0}"), removed_by_fieldname); let html = ` ${value_changes} @@ -200,14 +207,14 @@ erpnext.BOMComparisonTool = class BOMComparisonTool { ${removed_html} `; - this.form.get_field('preview').html(html); + this.form.get_field("preview").html(html); } get_changed_values(doctype, changed) { - return changed.filter(change => { + return changed.filter((change) => { let [fieldname, value1, value2] = change; - if (!value1) value1 = ''; - if (!value2) value2 = ''; + if (!value1) value1 = ""; + if (!value2) value2 = ""; if (value1 === value2) return false; let df = frappe.meta.get_docfield(doctype, fieldname); if (!df) return false; diff --git a/erpnext/manufacturing/report/bom_explorer/bom_explorer.js b/erpnext/manufacturing/report/bom_explorer/bom_explorer.js index b94d3f37704d..073b670e8c12 100644 --- a/erpnext/manufacturing/report/bom_explorer/bom_explorer.js +++ b/erpnext/manufacturing/report/bom_explorer/bom_explorer.js @@ -3,13 +3,13 @@ /* eslint-disable */ frappe.query_reports["BOM Explorer"] = { - "filters": [ + filters: [ { fieldname: "bom", label: __("BOM"), fieldtype: "Link", options: "BOM", - reqd: 1 + reqd: 1, }, - ] + ], }; diff --git a/erpnext/manufacturing/report/bom_operations_time/bom_operations_time.js b/erpnext/manufacturing/report/bom_operations_time/bom_operations_time.js index 30974f170c43..ce93208243f3 100644 --- a/erpnext/manufacturing/report/bom_operations_time/bom_operations_time.js +++ b/erpnext/manufacturing/report/bom_operations_time/bom_operations_time.js @@ -3,40 +3,40 @@ /* eslint-disable */ frappe.query_reports["BOM Operations Time"] = { - "filters": [ + filters: [ { - "fieldname": "item_code", - "label": __("Item Code"), - "fieldtype": "Link", - "width": "100", - "options": "Item", - "get_query": () =>{ + fieldname: "item_code", + label: __("Item Code"), + fieldtype: "Link", + width: "100", + options: "Item", + get_query: () => { return { - filters: { "is_stock_item": 1 } - } - } + filters: { is_stock_item: 1 }, + }; + }, }, { - "fieldname": "bom_id", - "label": __("BOM ID"), - "fieldtype": "MultiSelectList", - "width": "100", - "options": "BOM", - "get_data": function(txt) { + fieldname: "bom_id", + label: __("BOM ID"), + fieldtype: "MultiSelectList", + width: "100", + options: "BOM", + get_data: function (txt) { return frappe.db.get_link_options("BOM", txt); }, - "get_query": () =>{ + get_query: () => { return { - filters: { "docstatus": 1, "is_active": 1, "with_operations": 1 } - } - } + filters: { docstatus: 1, is_active: 1, with_operations: 1 }, + }; + }, }, { - "fieldname": "workstation", - "label": __("Workstation"), - "fieldtype": "Link", - "width": "100", - "options": "Workstation" + fieldname: "workstation", + label: __("Workstation"), + fieldtype: "Link", + width: "100", + options: "Workstation", }, - ] + ], }; diff --git a/erpnext/manufacturing/report/bom_stock_calculated/bom_stock_calculated.js b/erpnext/manufacturing/report/bom_stock_calculated/bom_stock_calculated.js index a0fd91e866f2..d6b86595ef4a 100644 --- a/erpnext/manufacturing/report/bom_stock_calculated/bom_stock_calculated.js +++ b/erpnext/manufacturing/report/bom_stock_calculated/bom_stock_calculated.js @@ -3,32 +3,32 @@ /* eslint-disable */ frappe.query_reports["BOM Stock Calculated"] = { - "filters": [ + filters: [ { - "fieldname": "bom", - "label": __("BOM"), - "fieldtype": "Link", - "options": "BOM", - "reqd": 1 + fieldname: "bom", + label: __("BOM"), + fieldtype: "Link", + options: "BOM", + reqd: 1, }, { - "fieldname": "warehouse", - "label": __("Warehouse"), - "fieldtype": "Link", - "options": "Warehouse", + fieldname: "warehouse", + label: __("Warehouse"), + fieldtype: "Link", + options: "Warehouse", }, { - "fieldname": "qty_to_make", - "label": __("Quantity to Make"), - "fieldtype": "Float", - "default": "1.0", - "reqd": 1 + fieldname: "qty_to_make", + label: __("Quantity to Make"), + fieldtype: "Float", + default: "1.0", + reqd: 1, }, { - "fieldname": "show_exploded_view", - "label": __("Show exploded view"), - "fieldtype": "Check", - "default": false, - } - ] -} + fieldname: "show_exploded_view", + label: __("Show exploded view"), + fieldtype: "Check", + default: false, + }, + ], +}; diff --git a/erpnext/manufacturing/report/bom_stock_report/bom_stock_report.js b/erpnext/manufacturing/report/bom_stock_report/bom_stock_report.js index e7f67caf249b..91d73d0101c0 100644 --- a/erpnext/manufacturing/report/bom_stock_report/bom_stock_report.js +++ b/erpnext/manufacturing/report/bom_stock_report/bom_stock_report.js @@ -1,38 +1,41 @@ frappe.query_reports["BOM Stock Report"] = { - "filters": [ + filters: [ { - "fieldname": "bom", - "label": __("BOM"), - "fieldtype": "Link", - "options": "BOM", - "reqd": 1 - }, { - "fieldname": "warehouse", - "label": __("Warehouse"), - "fieldtype": "Link", - "options": "Warehouse", - "reqd": 1 - }, { - "fieldname": "show_exploded_view", - "label": __("Show exploded view"), - "fieldtype": "Check" - }, { - "fieldname": "qty_to_produce", - "label": __("Quantity to Produce"), - "fieldtype": "Int", - "default": "1" - }, + fieldname: "bom", + label: __("BOM"), + fieldtype: "Link", + options: "BOM", + reqd: 1, + }, + { + fieldname: "warehouse", + label: __("Warehouse"), + fieldtype: "Link", + options: "Warehouse", + reqd: 1, + }, + { + fieldname: "show_exploded_view", + label: __("Show exploded view"), + fieldtype: "Check", + }, + { + fieldname: "qty_to_produce", + label: __("Quantity to Produce"), + fieldtype: "Int", + default: "1", + }, ], - "formatter": function(value, row, column, data, default_formatter) { + formatter: function (value, row, column, data, default_formatter) { value = default_formatter(value, row, column, data); if (column.id == "item") { if (data["in_stock_qty"] >= data["required_qty"]) { - value = `${data['item']}`; + value = `${data["item"]}`; } else { - value = `${data['item']}`; + value = `${data["item"]}`; } } - return value - } -} + return value; + }, +}; diff --git a/erpnext/manufacturing/report/bom_variance_report/bom_variance_report.js b/erpnext/manufacturing/report/bom_variance_report/bom_variance_report.js index c6ecaef2fa39..fb3a29538b8f 100644 --- a/erpnext/manufacturing/report/bom_variance_report/bom_variance_report.js +++ b/erpnext/manufacturing/report/bom_variance_report/bom_variance_report.js @@ -3,27 +3,27 @@ /* eslint-disable */ frappe.query_reports["BOM Variance Report"] = { - "filters": [ + filters: [ { - "fieldname":"bom_no", - "label": __("BOM No"), - "fieldtype": "Link", - "options": "BOM" + fieldname: "bom_no", + label: __("BOM No"), + fieldtype: "Link", + options: "BOM", }, { - "fieldname":"work_order", - "label": __("Work Order"), - "fieldtype": "Link", - "options": "Work Order", - "get_query": function() { - var bom_no = frappe.query_report.get_filter_value('bom_no'); - return{ + fieldname: "work_order", + label: __("Work Order"), + fieldtype: "Link", + options: "Work Order", + get_query: function () { + var bom_no = frappe.query_report.get_filter_value("bom_no"); + return { query: "erpnext.manufacturing.report.bom_variance_report.bom_variance_report.get_work_orders", filters: { - 'bom_no': bom_no - } - } - } + bom_no: bom_no, + }, + }; + }, }, - ] -} + ], +}; diff --git a/erpnext/manufacturing/report/cost_of_poor_quality_report/cost_of_poor_quality_report.js b/erpnext/manufacturing/report/cost_of_poor_quality_report/cost_of_poor_quality_report.js index 72eed5e0d7cc..6092b39b6c57 100644 --- a/erpnext/manufacturing/report/cost_of_poor_quality_report/cost_of_poor_quality_report.js +++ b/erpnext/manufacturing/report/cost_of_poor_quality_report/cost_of_poor_quality_report.js @@ -3,24 +3,26 @@ /* eslint-disable */ frappe.query_reports["Cost of Poor Quality Report"] = { - "filters": [ + filters: [ { label: __("Company"), fieldname: "company", fieldtype: "Link", options: "Company", default: frappe.defaults.get_user_default("Company"), - reqd: 1 + reqd: 1, }, { label: __("From Date"), - fieldname:"from_date", + fieldname: "from_date", fieldtype: "Datetime", - default: frappe.datetime.convert_to_system_tz(frappe.datetime.add_months(frappe.datetime.now_datetime(), -1)), + default: frappe.datetime.convert_to_system_tz( + frappe.datetime.add_months(frappe.datetime.now_datetime(), -1) + ), }, { label: __("To Date"), - fieldname:"to_date", + fieldname: "to_date", fieldtype: "Datetime", default: frappe.datetime.now_datetime(), }, @@ -29,45 +31,45 @@ frappe.query_reports["Cost of Poor Quality Report"] = { fieldname: "name", fieldtype: "Link", options: "Job Card", - get_query: function() { + get_query: function () { return { filters: { is_corrective_job_card: 1, - docstatus: 1 - } - } - } + docstatus: 1, + }, + }; + }, }, { label: __("Work Order"), fieldname: "work_order", fieldtype: "Link", - options: "Work Order" + options: "Work Order", }, { label: __("Operation"), fieldname: "operation", fieldtype: "Link", options: "Operation", - get_query: function() { + get_query: function () { return { filters: { - is_corrective_operation: 1 - } - } - } + is_corrective_operation: 1, + }, + }; + }, }, { label: __("Workstation"), fieldname: "workstation", fieldtype: "Link", - options: "Workstation" + options: "Workstation", }, { label: __("Item"), fieldname: "production_item", fieldtype: "Link", - options: "Item" + options: "Item", }, { label: __("Serial No"), @@ -75,14 +77,14 @@ frappe.query_reports["Cost of Poor Quality Report"] = { fieldtype: "Link", options: "Serial No", depends_on: "eval: doc.production_item", - get_query: function() { - var item_code = frappe.query_report.get_filter_value('production_item'); + get_query: function () { + var item_code = frappe.query_report.get_filter_value("production_item"); return { filters: { - item_code: item_code - } - } - } + item_code: item_code, + }, + }; + }, }, { label: __("Batch No"), @@ -90,14 +92,14 @@ frappe.query_reports["Cost of Poor Quality Report"] = { fieldtype: "Link", options: "Batch No", depends_on: "eval: doc.production_item", - get_query: function() { - var item_code = frappe.query_report.get_filter_value('production_item'); + get_query: function () { + var item_code = frappe.query_report.get_filter_value("production_item"); return { filters: { - item: item_code - } - } - } + item: item_code, + }, + }; + }, }, - ] + ], }; diff --git a/erpnext/manufacturing/report/downtime_analysis/downtime_analysis.js b/erpnext/manufacturing/report/downtime_analysis/downtime_analysis.js index f6486743aa3c..22cf59c572ad 100644 --- a/erpnext/manufacturing/report/downtime_analysis/downtime_analysis.js +++ b/erpnext/manufacturing/report/downtime_analysis/downtime_analysis.js @@ -3,17 +3,19 @@ /* eslint-disable */ frappe.query_reports["Downtime Analysis"] = { - "filters": [ + filters: [ { label: __("From Date"), - fieldname:"from_date", + fieldname: "from_date", fieldtype: "Datetime", - default: frappe.datetime.convert_to_system_tz(frappe.datetime.add_months(frappe.datetime.now_datetime(), -1)), - reqd: 1 + default: frappe.datetime.convert_to_system_tz( + frappe.datetime.add_months(frappe.datetime.now_datetime(), -1) + ), + reqd: 1, }, { label: __("To Date"), - fieldname:"to_date", + fieldname: "to_date", fieldtype: "Datetime", default: frappe.datetime.now_datetime(), reqd: 1, @@ -22,7 +24,7 @@ frappe.query_reports["Downtime Analysis"] = { label: __("Machine"), fieldname: "workstation", fieldtype: "Link", - options: "Workstation" - } - ] + options: "Workstation", + }, + ], }; diff --git a/erpnext/manufacturing/report/exponential_smoothing_forecasting/exponential_smoothing_forecasting.js b/erpnext/manufacturing/report/exponential_smoothing_forecasting/exponential_smoothing_forecasting.js index 123a82a3882e..f9e2b6cfcb02 100644 --- a/erpnext/manufacturing/report/exponential_smoothing_forecasting/exponential_smoothing_forecasting.js +++ b/erpnext/manufacturing/report/exponential_smoothing_forecasting/exponential_smoothing_forecasting.js @@ -3,95 +3,95 @@ /* eslint-disable */ frappe.query_reports["Exponential Smoothing Forecasting"] = { - "filters": [ + filters: [ { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "reqd": 1, - "default": frappe.defaults.get_user_default("Company") + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + reqd: 1, + default: frappe.defaults.get_user_default("Company"), }, { - "fieldname":"from_date", - "label": __("From Date"), - "fieldtype": "Date", - "default": frappe.datetime.get_today(), - "reqd": 1 + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + default: frappe.datetime.get_today(), + reqd: 1, }, { - "fieldname":"to_date", - "label": __("To Date"), - "fieldtype": "Date", - "default": frappe.datetime.add_months(frappe.datetime.get_today(), 12), - "reqd": 1 + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + default: frappe.datetime.add_months(frappe.datetime.get_today(), 12), + reqd: 1, }, { - "fieldname":"based_on_document", - "label": __("Based On Document"), - "fieldtype": "Select", - "options": ["Sales Order", "Delivery Note", "Quotation"], - "default": "Sales Order", - "reqd": 1 + fieldname: "based_on_document", + label: __("Based On Document"), + fieldtype: "Select", + options: ["Sales Order", "Delivery Note", "Quotation"], + default: "Sales Order", + reqd: 1, }, { - "fieldname":"based_on_field", - "label": __("Based On"), - "fieldtype": "Select", - "options": ["Qty", "Amount"], - "default": "Qty", - "reqd": 1 + fieldname: "based_on_field", + label: __("Based On"), + fieldtype: "Select", + options: ["Qty", "Amount"], + default: "Qty", + reqd: 1, }, { - "fieldname":"no_of_years", - "label": __("Based On Data ( in years )"), - "fieldtype": "Select", - "options": [3, 6, 9], - "default": 3, - "reqd": 1 + fieldname: "no_of_years", + label: __("Based On Data ( in years )"), + fieldtype: "Select", + options: [3, 6, 9], + default: 3, + reqd: 1, }, { - "fieldname": "periodicity", - "label": __("Periodicity"), - "fieldtype": "Select", - "options": [ - { "value": "Monthly", "label": __("Monthly") }, - { "value": "Quarterly", "label": __("Quarterly") }, - { "value": "Half-Yearly", "label": __("Half-Yearly") }, - { "value": "Yearly", "label": __("Yearly") } + fieldname: "periodicity", + label: __("Periodicity"), + fieldtype: "Select", + options: [ + { value: "Monthly", label: __("Monthly") }, + { value: "Quarterly", label: __("Quarterly") }, + { value: "Half-Yearly", label: __("Half-Yearly") }, + { value: "Yearly", label: __("Yearly") }, ], - "default": "Yearly", - "reqd": 1 + default: "Yearly", + reqd: 1, }, { - "fieldname":"smoothing_constant", - "label": __("Smoothing Constant"), - "fieldtype": "Select", - "options": [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0], - "reqd": 1, - "default": 0.3 + fieldname: "smoothing_constant", + label: __("Smoothing Constant"), + fieldtype: "Select", + options: [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0], + reqd: 1, + default: 0.3, }, { - "fieldname":"item_code", - "label": __("Item Code"), - "fieldtype": "Link", - "options": "Item" + fieldname: "item_code", + label: __("Item Code"), + fieldtype: "Link", + options: "Item", }, { - "fieldname":"warehouse", - "label": __("Warehouse"), - "fieldtype": "Link", - "options": "Warehouse", + fieldname: "warehouse", + label: __("Warehouse"), + fieldtype: "Link", + options: "Warehouse", get_query: () => { - var company = frappe.query_report.get_filter_value('company'); + var company = frappe.query_report.get_filter_value("company"); if (company) { return { filters: { - 'company': company - } + company: company, + }, }; } - } - } - ] + }, + }, + ], }; diff --git a/erpnext/manufacturing/report/job_card_summary/job_card_summary.js b/erpnext/manufacturing/report/job_card_summary/job_card_summary.js index a874f2248204..0d6a52f4b8ec 100644 --- a/erpnext/manufacturing/report/job_card_summary/job_card_summary.js +++ b/erpnext/manufacturing/report/job_card_summary/job_card_summary.js @@ -3,14 +3,14 @@ /* eslint-disable */ frappe.query_reports["Job Card Summary"] = { - "filters": [ + filters: [ { label: __("Company"), fieldname: "company", fieldtype: "Link", options: "Company", default: frappe.defaults.get_user_default("Company"), - reqd: 1 + reqd: 1, }, { fieldname: "fiscal_year", @@ -19,30 +19,30 @@ frappe.query_reports["Job Card Summary"] = { options: "Fiscal Year", default: erpnext.utils.get_fiscal_year(frappe.datetime.get_today()), reqd: 1, - on_change: function(query_report) { + on_change: function (query_report) { var fiscal_year = query_report.get_values().fiscal_year; if (!fiscal_year) { return; } - frappe.model.with_doc("Fiscal Year", fiscal_year, function(r) { + frappe.model.with_doc("Fiscal Year", fiscal_year, function (r) { var fy = frappe.model.get_doc("Fiscal Year", fiscal_year); frappe.query_report.set_filter_value({ from_date: fy.year_start_date, - to_date: fy.year_end_date + to_date: fy.year_end_date, }); }); - } + }, }, { label: __("From Posting Date"), - fieldname:"from_date", + fieldname: "from_date", fieldtype: "Date", default: frappe.defaults.get_user_default("year_start_date"), - reqd: 1 + reqd: 1, }, { label: __("To Posting Date"), - fieldname:"to_date", + fieldname: "to_date", fieldtype: "Date", default: frappe.defaults.get_user_default("year_end_date"), reqd: 1, @@ -51,35 +51,35 @@ frappe.query_reports["Job Card Summary"] = { label: __("Status"), fieldname: "status", fieldtype: "Select", - options: ["", "Open", "Work In Progress", "Completed", "On Hold"] + options: ["", "Open", "Work In Progress", "Completed", "On Hold"], }, { label: __("Work Orders"), fieldname: "work_order", fieldtype: "MultiSelectList", - get_data: function(txt) { - return frappe.db.get_link_options('Work Order', txt); - } + get_data: function (txt) { + return frappe.db.get_link_options("Work Order", txt); + }, }, { label: __("Production Item"), fieldname: "production_item", fieldtype: "MultiSelectList", - get_data: function(txt) { - return frappe.db.get_link_options('Item', txt); - } + get_data: function (txt) { + return frappe.db.get_link_options("Item", txt); + }, }, { label: __("Workstation"), fieldname: "workstation", fieldtype: "Link", - options: "Workstation" + options: "Workstation", }, { label: __("Operation"), fieldname: "operation", fieldtype: "Link", - options: "Operation" - } - ] + options: "Operation", + }, + ], }; diff --git a/erpnext/manufacturing/report/process_loss_report/process_loss_report.js b/erpnext/manufacturing/report/process_loss_report/process_loss_report.js index b0c2b94a2549..ab6f64dc5c27 100644 --- a/erpnext/manufacturing/report/process_loss_report/process_loss_report.js +++ b/erpnext/manufacturing/report/process_loss_report/process_loss_report.js @@ -4,41 +4,41 @@ frappe.query_reports["Process Loss Report"] = { filters: [ - { - label: __("Company"), - fieldname: "company", - fieldtype: "Link", - options: "Company", - mandatory: true, - default: frappe.defaults.get_user_default("Company"), - }, { - label: __("Item"), - fieldname: "item", - fieldtype: "Link", - options: "Item", - mandatory: false, + label: __("Company"), + fieldname: "company", + fieldtype: "Link", + options: "Company", + mandatory: true, + default: frappe.defaults.get_user_default("Company"), }, { - label: __("Work Order"), - fieldname: "work_order", - fieldtype: "Link", - options: "Work Order", - mandatory: false, + label: __("Item"), + fieldname: "item", + fieldtype: "Link", + options: "Item", + mandatory: false, }, - { - label: __("From Date"), - fieldname: "from_date", - fieldtype: "Date", - mandatory: true, - default: frappe.datetime.year_start(), - }, - { - label: __("To Date"), - fieldname: "to_date", - fieldtype: "Date", - mandatory: true, - default: frappe.datetime.get_today(), - }, - ] + { + label: __("Work Order"), + fieldname: "work_order", + fieldtype: "Link", + options: "Work Order", + mandatory: false, + }, + { + label: __("From Date"), + fieldname: "from_date", + fieldtype: "Date", + mandatory: true, + default: frappe.datetime.year_start(), + }, + { + label: __("To Date"), + fieldname: "to_date", + fieldtype: "Date", + mandatory: true, + default: frappe.datetime.get_today(), + }, + ], }; diff --git a/erpnext/manufacturing/report/production_analytics/production_analytics.js b/erpnext/manufacturing/report/production_analytics/production_analytics.js index 99f9b1260a20..6f2c38295e92 100644 --- a/erpnext/manufacturing/report/production_analytics/production_analytics.js +++ b/erpnext/manufacturing/report/production_analytics/production_analytics.js @@ -3,41 +3,41 @@ /* eslint-disable */ frappe.query_reports["Production Analytics"] = { - "filters": [ + filters: [ { fieldname: "company", label: __("Company"), fieldtype: "Link", options: "Company", default: frappe.defaults.get_user_default("Company"), - reqd: 1 + reqd: 1, }, { fieldname: "from_date", label: __("From Date"), fieldtype: "Date", default: frappe.defaults.get_user_default("year_start_date"), - reqd: 1 + reqd: 1, }, { - fieldname:"to_date", + fieldname: "to_date", label: __("To Date"), fieldtype: "Date", default: frappe.defaults.get_user_default("year_end_date"), - reqd: 1 + reqd: 1, }, { fieldname: "range", label: __("Range"), fieldtype: "Select", options: [ - { "value": "Weekly", "label": __("Weekly") }, - { "value": "Monthly", "label": __("Monthly") }, - { "value": "Quarterly", "label": __("Quarterly") }, - { "value": "Yearly", "label": __("Yearly") } + { value: "Weekly", label: __("Weekly") }, + { value: "Monthly", label: __("Monthly") }, + { value: "Quarterly", label: __("Quarterly") }, + { value: "Yearly", label: __("Yearly") }, ], default: "Monthly", - reqd: 1 - } - ] -} + reqd: 1, + }, + ], +}; diff --git a/erpnext/manufacturing/report/production_plan_summary/production_plan_summary.js b/erpnext/manufacturing/report/production_plan_summary/production_plan_summary.js index a4d7fae45604..567e8ebc6c39 100644 --- a/erpnext/manufacturing/report/production_plan_summary/production_plan_summary.js +++ b/erpnext/manufacturing/report/production_plan_summary/production_plan_summary.js @@ -3,28 +3,28 @@ /* eslint-disable */ frappe.query_reports["Production Plan Summary"] = { - "filters": [ + filters: [ { fieldname: "production_plan", label: __("Production Plan"), fieldtype: "Link", options: "Production Plan", reqd: 1, - get_query: function() { + get_query: function () { return { filters: { - "docstatus": 1 - } + docstatus: 1, + }, }; - } - } + }, + }, ], - "formatter": function(value, row, column, data, default_formatter) { + formatter: function (value, row, column, data, default_formatter) { value = default_formatter(value, row, column, data); if (column.fieldname == "item_code") { - var color = data.pending_qty > 0 ? 'red': 'green'; - value = `${data['item_code']}`; + var color = data.pending_qty > 0 ? "red" : "green"; + value = `${data["item_code"]}`; } return value; diff --git a/erpnext/manufacturing/report/production_planning_report/production_planning_report.js b/erpnext/manufacturing/report/production_planning_report/production_planning_report.js index 675b8a110082..bde90504e677 100644 --- a/erpnext/manufacturing/report/production_planning_report/production_planning_report.js +++ b/erpnext/manufacturing/report/production_planning_report/production_planning_report.js @@ -3,106 +3,110 @@ /* eslint-disable */ frappe.query_reports["Production Planning Report"] = { - "filters": [ + filters: [ { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "reqd": 1, - "default": frappe.defaults.get_user_default("Company") + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + reqd: 1, + default: frappe.defaults.get_user_default("Company"), }, { - "fieldname":"based_on", - "label": __("Based On"), - "fieldtype": "Select", - "options": ["Sales Order", "Material Request", "Work Order"], - "default": "Sales Order", - "reqd": 1, - on_change: function() { + fieldname: "based_on", + label: __("Based On"), + fieldtype: "Select", + options: ["Sales Order", "Material Request", "Work Order"], + default: "Sales Order", + reqd: 1, + on_change: function () { let filters = frappe.query_report.filters; - let based_on = frappe.query_report.get_filter_value('based_on'); + let based_on = frappe.query_report.get_filter_value("based_on"); let options = { "Sales Order": ["Delivery Date", "Total Amount"], "Material Request": ["Required Date"], - "Work Order": ["Planned Start Date"] - } + "Work Order": ["Planned Start Date"], + }; - filters.forEach(d => { + filters.forEach((d) => { if (d.fieldname == "order_by") { d.df.options = options[based_on]; - d.set_input(d.df.options) + d.set_input(d.df.options); } }); frappe.query_report.refresh(); - } + }, }, { - "fieldname":"docnames", - "label": __("Document Name"), - "fieldtype": "MultiSelectList", - "options": "Sales Order", - "get_data": function(txt) { + fieldname: "docnames", + label: __("Document Name"), + fieldtype: "MultiSelectList", + options: "Sales Order", + get_data: function (txt) { if (!frappe.query_report.filters) return; - let based_on = frappe.query_report.get_filter_value('based_on'); + let based_on = frappe.query_report.get_filter_value("based_on"); if (!based_on) return; return frappe.db.get_link_options(based_on, txt); }, - "get_query": function() { - var company = frappe.query_report.get_filter_value('company'); + get_query: function () { + var company = frappe.query_report.get_filter_value("company"); return { filters: { - "docstatus": 1, - "company": company - } + docstatus: 1, + company: company, + }, }; - } + }, }, { - "fieldname":"raw_material_warehouse", - "label": __("Raw Material Warehouse"), - "fieldtype": "Link", - "options": "Warehouse", - "depends_on": "eval: doc.based_on != 'Work Order'", - "get_query": function() { - var company = frappe.query_report.get_filter_value('company'); + fieldname: "raw_material_warehouse", + label: __("Raw Material Warehouse"), + fieldtype: "Link", + options: "Warehouse", + depends_on: "eval: doc.based_on != 'Work Order'", + get_query: function () { + var company = frappe.query_report.get_filter_value("company"); return { filters: { - "company": company - } + company: company, + }, }; - } + }, }, { - "fieldname":"order_by", - "label": __("Order By"), - "fieldtype": "Select", - "options": ["Delivery Date", "Total Amount"], - "default": "Delivery Date" + fieldname: "order_by", + label: __("Order By"), + fieldtype: "Select", + options: ["Delivery Date", "Total Amount"], + default: "Delivery Date", }, { - "fieldname":"include_subassembly_raw_materials", - "label": __("Include Sub-assembly Raw Materials"), - "fieldtype": "Check", - "depends_on": "eval: doc.based_on != 'Work Order'", - "default": 0 + fieldname: "include_subassembly_raw_materials", + label: __("Include Sub-assembly Raw Materials"), + fieldtype: "Check", + depends_on: "eval: doc.based_on != 'Work Order'", + default: 0, }, ], - "formatter": function(value, row, column, data, default_formatter) { + formatter: function (value, row, column, data, default_formatter) { value = default_formatter(value, row, column, data); - if (column.fieldname == "production_item_name" && data && data.qty_to_manufacture > data.available_qty ) { + if ( + column.fieldname == "production_item_name" && + data && + data.qty_to_manufacture > data.available_qty + ) { value = `
    ${value}
    `; } - if (column.fieldname == "production_item" && !data.name ) { + if (column.fieldname == "production_item" && !data.name) { value = ""; } - if (column.fieldname == "raw_material_name" && data && data.required_qty > data.allotted_qty ) { + if (column.fieldname == "raw_material_name" && data && data.required_qty > data.allotted_qty) { value = `
    ${value}
    `; } diff --git a/erpnext/manufacturing/report/quality_inspection_summary/quality_inspection_summary.js b/erpnext/manufacturing/report/quality_inspection_summary/quality_inspection_summary.js index d4587aa6619f..1e90955ebb1c 100644 --- a/erpnext/manufacturing/report/quality_inspection_summary/quality_inspection_summary.js +++ b/erpnext/manufacturing/report/quality_inspection_summary/quality_inspection_summary.js @@ -3,17 +3,17 @@ /* eslint-disable */ frappe.query_reports["Quality Inspection Summary"] = { - "filters": [ + filters: [ { label: __("From Date"), - fieldname:"from_date", + fieldname: "from_date", fieldtype: "Date", default: frappe.datetime.add_months(frappe.datetime.get_today(), -12), - reqd: 1 + reqd: 1, }, { label: __("To Date"), - fieldname:"to_date", + fieldname: "to_date", fieldtype: "Date", default: frappe.datetime.get_today(), reqd: 1, @@ -22,19 +22,19 @@ frappe.query_reports["Quality Inspection Summary"] = { label: __("Status"), fieldname: "status", fieldtype: "Select", - options: ["", "Accepted", "Rejected"] + options: ["", "Accepted", "Rejected"], }, { label: __("Item Code"), fieldname: "item_code", fieldtype: "Link", - options: "Item" + options: "Item", }, { label: __("Inspected By"), fieldname: "inspected_by", fieldtype: "Link", - options: "User" - } - ] + options: "User", + }, + ], }; diff --git a/erpnext/manufacturing/report/work_order_consumed_materials/work_order_consumed_materials.js b/erpnext/manufacturing/report/work_order_consumed_materials/work_order_consumed_materials.js index 2fb4ec679132..51654b90fa97 100644 --- a/erpnext/manufacturing/report/work_order_consumed_materials/work_order_consumed_materials.js +++ b/erpnext/manufacturing/report/work_order_consumed_materials/work_order_consumed_materials.js @@ -3,65 +3,65 @@ /* eslint-disable */ frappe.query_reports["Work Order Consumed Materials"] = { - "filters": [ + filters: [ { label: __("Company"), fieldname: "company", fieldtype: "Link", options: "Company", default: frappe.defaults.get_user_default("Company"), - reqd: 1 + reqd: 1, }, { label: __("From Date"), - fieldname:"from_date", + fieldname: "from_date", fieldtype: "Date", default: frappe.datetime.add_months(frappe.datetime.get_today(), -1), - reqd: 1 + reqd: 1, }, { - fieldname:"to_date", + fieldname: "to_date", label: __("To Date"), fieldtype: "Date", default: frappe.datetime.get_today(), - reqd: 1 + reqd: 1, }, { label: __("Work Order"), fieldname: "name", fieldtype: "Link", options: "Work Order", - get_query: function() { + get_query: function () { return { filters: { - status: ["in", ["In Process", "Completed", "Stopped"]] - } - } - } + status: ["in", ["In Process", "Completed", "Stopped"]], + }, + }; + }, }, { label: __("Production Item"), fieldname: "production_item", fieldtype: "Link", depends_on: "eval: !doc.name", - options: "Item" + options: "Item", }, { label: __("Status"), fieldname: "status", fieldtype: "Select", - options: ["", "In Process", "Completed", "Stopped"] + options: ["", "In Process", "Completed", "Stopped"], }, { label: __("Excess Materials Consumed"), fieldname: "show_extra_consumed_materials", - fieldtype: "Check" - } + fieldtype: "Check", + }, ], - "formatter": function(value, row, column, data, default_formatter) { + formatter: function (value, row, column, data, default_formatter) { value = default_formatter(value, row, column, data); - if (column.fieldname == "raw_material_name" && data && data.extra_consumed_qty > 0 ) { + if (column.fieldname == "raw_material_name" && data && data.extra_consumed_qty > 0) { value = `
    ${value}
    `; } diff --git a/erpnext/manufacturing/report/work_order_stock_report/work_order_stock_report.js b/erpnext/manufacturing/report/work_order_stock_report/work_order_stock_report.js index dbb7c2341018..ec8651ddf7d3 100644 --- a/erpnext/manufacturing/report/work_order_stock_report/work_order_stock_report.js +++ b/erpnext/manufacturing/report/work_order_stock_report/work_order_stock_report.js @@ -3,12 +3,12 @@ /* eslint-disable */ frappe.query_reports["Work Order Stock Report"] = { - "filters": [ + filters: [ { - "fieldname": "warehouse", - "label": __("Warehouse"), - "fieldtype": "Link", - "options": "Warehouse" - } - ] -} + fieldname: "warehouse", + label: __("Warehouse"), + fieldtype: "Link", + options: "Warehouse", + }, + ], +}; diff --git a/erpnext/manufacturing/report/work_order_summary/work_order_summary.js b/erpnext/manufacturing/report/work_order_summary/work_order_summary.js index 67bd24dd805e..67e6e706c59c 100644 --- a/erpnext/manufacturing/report/work_order_summary/work_order_summary.js +++ b/erpnext/manufacturing/report/work_order_summary/work_order_summary.js @@ -3,32 +3,32 @@ /* eslint-disable */ frappe.query_reports["Work Order Summary"] = { - "filters": [ + filters: [ { label: __("Company"), fieldname: "company", fieldtype: "Link", options: "Company", default: frappe.defaults.get_user_default("Company"), - reqd: 1 + reqd: 1, }, { label: __("Based On"), - fieldname:"based_on", + fieldname: "based_on", fieldtype: "Select", options: "Creation Date\nPlanned Date\nActual Date", - default: "Creation Date" + default: "Creation Date", }, { label: __("From Posting Date"), - fieldname:"from_date", + fieldname: "from_date", fieldtype: "Date", default: frappe.datetime.add_months(frappe.datetime.get_today(), -3), - reqd: 1 + reqd: 1, }, { label: __("To Posting Date"), - fieldname:"to_date", + fieldname: "to_date", fieldtype: "Date", default: frappe.datetime.get_today(), reqd: 1, @@ -37,36 +37,36 @@ frappe.query_reports["Work Order Summary"] = { label: __("Status"), fieldname: "status", fieldtype: "Select", - options: ["", "Not Started", "In Process", "Completed", "Stopped", "Closed"] + options: ["", "Not Started", "In Process", "Completed", "Stopped", "Closed"], }, { label: __("Sales Orders"), fieldname: "sales_order", fieldtype: "MultiSelectList", - get_data: function(txt) { - return frappe.db.get_link_options('Sales Order', txt); - } + get_data: function (txt) { + return frappe.db.get_link_options("Sales Order", txt); + }, }, { label: __("Production Item"), fieldname: "production_item", fieldtype: "MultiSelectList", - get_data: function(txt) { - return frappe.db.get_link_options('Item', txt); - } + get_data: function (txt) { + return frappe.db.get_link_options("Item", txt); + }, }, { label: __("Age"), - fieldname:"age", + fieldname: "age", fieldtype: "Int", - default: "0" + default: "0", }, { label: __("Charts Based On"), - fieldname:"charts_based_on", + fieldname: "charts_based_on", fieldtype: "Select", options: ["Status", "Age", "Quantity"], - default: "Status" + default: "Status", }, - ] + ], }; diff --git a/erpnext/portal/doctype/homepage/homepage.js b/erpnext/portal/doctype/homepage/homepage.js index 59f808a3158d..e0d7af001c0c 100644 --- a/erpnext/portal/doctype/homepage/homepage.js +++ b/erpnext/portal/doctype/homepage/homepage.js @@ -1,30 +1,30 @@ // Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Homepage', { - setup: function(frm) { - frm.fields_dict["products"].grid.get_field("item").get_query = function() { +frappe.ui.form.on("Homepage", { + setup: function (frm) { + frm.fields_dict["products"].grid.get_field("item").get_query = function () { return { - filters: {'published': 1} - } - } + filters: { published: 1 }, + }; + }; }, - refresh: function(frm) { - frm.add_custom_button(__('Set Meta Tags'), () => { - frappe.utils.set_meta_tag('home'); + refresh: function (frm) { + frm.add_custom_button(__("Set Meta Tags"), () => { + frappe.utils.set_meta_tag("home"); }); - frm.add_custom_button(__('Customize Homepage Sections'), () => { - frappe.set_route('List', 'Homepage Section', 'List'); + frm.add_custom_button(__("Customize Homepage Sections"), () => { + frappe.set_route("List", "Homepage Section", "List"); }); }, }); -frappe.ui.form.on('Homepage Featured Product', { - view: function(frm, cdt, cdn) { - var child= locals[cdt][cdn]; +frappe.ui.form.on("Homepage Featured Product", { + view: function (frm, cdt, cdn) { + var child = locals[cdt][cdn]; if (child.item_code && child.route) { - window.open('/' + child.route, '_blank'); + window.open("/" + child.route, "_blank"); } - } + }, }); diff --git a/erpnext/portal/doctype/homepage_section/homepage_section.js b/erpnext/portal/doctype/homepage_section/homepage_section.js index 68859eb10b63..270b73aafdf4 100644 --- a/erpnext/portal/doctype/homepage_section/homepage_section.js +++ b/erpnext/portal/doctype/homepage_section/homepage_section.js @@ -1,6 +1,4 @@ // Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Homepage Section', { - -}); +frappe.ui.form.on("Homepage Section", {}); diff --git a/erpnext/projects/doctype/activity_cost/activity_cost.js b/erpnext/projects/doctype/activity_cost/activity_cost.js index 2d22caad8e2a..d47b574265f6 100644 --- a/erpnext/projects/doctype/activity_cost/activity_cost.js +++ b/erpnext/projects/doctype/activity_cost/activity_cost.js @@ -1 +1 @@ -cur_frm.add_fetch('employee', 'employee_name', 'employee_name'); +cur_frm.add_fetch("employee", "employee_name", "employee_name"); diff --git a/erpnext/projects/doctype/activity_type/activity_type.js b/erpnext/projects/doctype/activity_type/activity_type.js index f1ba882812e4..b620cdd6c64e 100644 --- a/erpnext/projects/doctype/activity_type/activity_type.js +++ b/erpnext/projects/doctype/activity_type/activity_type.js @@ -1,12 +1,15 @@ frappe.ui.form.on("Activity Type", { - onload: function(frm) { - frm.set_currency_labels(["billing_rate", "costing_rate"], frappe.defaults.get_global_default('currency')); + onload: function (frm) { + frm.set_currency_labels( + ["billing_rate", "costing_rate"], + frappe.defaults.get_global_default("currency") + ); }, - refresh: function(frm) { - frm.add_custom_button(__("Activity Cost per Employee"), function() { - frappe.route_options = {"activity_type": frm.doc.name}; + refresh: function (frm) { + frm.add_custom_button(__("Activity Cost per Employee"), function () { + frappe.route_options = { activity_type: frm.doc.name }; frappe.set_route("List", "Activity Cost"); }); - } + }, }); diff --git a/erpnext/projects/doctype/project/project.js b/erpnext/projects/doctype/project/project.js index 0cdd9c10e7f7..3ea8189feeca 100644 --- a/erpnext/projects/doctype/project/project.js +++ b/erpnext/projects/doctype/project/project.js @@ -3,16 +3,16 @@ frappe.ui.form.on("Project", { setup(frm) { frm.make_methods = { - 'Timesheet': () => { + Timesheet: () => { open_form(frm, "Timesheet", "Timesheet Detail", "time_logs"); }, - 'Purchase Order': () => { + "Purchase Order": () => { open_form(frm, "Purchase Order", "Purchase Order Item", "items"); }, - 'Purchase Receipt': () => { + "Purchase Receipt": () => { open_form(frm, "Purchase Receipt", "Purchase Receipt Item", "items"); }, - 'Purchase Invoice': () => { + "Purchase Invoice": () => { open_form(frm, "Purchase Invoice", "Purchase Invoice Item", "items"); }, }; @@ -22,31 +22,31 @@ frappe.ui.form.on("Project", { so.get_route_options_for_new_doc = () => { if (frm.is_new()) return; return { - "customer": frm.doc.customer, - "project_name": frm.doc.name + customer: frm.doc.customer, + project_name: frm.doc.name, }; }; - frm.set_query('customer', 'erpnext.controllers.queries.customer_query'); + frm.set_query("customer", "erpnext.controllers.queries.customer_query"); frm.set_query("user", "users", function () { return { - query: "erpnext.projects.doctype.project.project.get_users_for_project" + query: "erpnext.projects.doctype.project.project.get_users_for_project", }; }); frm.set_query("department", function (doc) { return { filters: { - "company": doc.company, - } + company: doc.company, + }, }; }); // sales order - frm.set_query('sales_order', function () { + frm.set_query("sales_order", function () { var filters = { - 'project': ["in", frm.doc.__islocal ? [""] : [frm.doc.name, ""]] + project: ["in", frm.doc.__islocal ? [""] : [frm.doc.name, ""]], }; if (frm.doc.customer) { @@ -54,7 +54,7 @@ frappe.ui.form.on("Project", { } return { - filters: filters + filters: filters, }; }); }, @@ -65,108 +65,133 @@ frappe.ui.form.on("Project", { } else { frm.add_web_link("/projects?project=" + encodeURIComponent(frm.doc.name)); - frm.trigger('show_dashboard'); + frm.trigger("show_dashboard"); } frm.trigger("set_custom_buttons"); }, - set_custom_buttons: function(frm) { + set_custom_buttons: function (frm) { if (!frm.is_new()) { - frm.add_custom_button(__('Duplicate Project with Tasks'), () => { - frm.events.create_duplicate(frm); - }, __("Actions")); + frm.add_custom_button( + __("Duplicate Project with Tasks"), + () => { + frm.events.create_duplicate(frm); + }, + __("Actions") + ); - frm.add_custom_button(__('Update Total Purchase Cost'), () => { - frm.events.update_total_purchase_cost(frm); - }, __("Actions")); + frm.add_custom_button( + __("Update Total Purchase Cost"), + () => { + frm.events.update_total_purchase_cost(frm); + }, + __("Actions") + ); frm.trigger("set_project_status_button"); - if (frappe.model.can_read("Task")) { - frm.add_custom_button(__("Gantt Chart"), function () { - frappe.route_options = { - "project": frm.doc.name - }; - frappe.set_route("List", "Task", "Gantt"); - }, __("View")); - - frm.add_custom_button(__("Kanban Board"), () => { - frappe.call('erpnext.projects.doctype.project.project.create_kanban_board_if_not_exists', { - project: frm.doc.name - }).then(() => { - frappe.set_route('List', 'Task', 'Kanban', frm.doc.project_name); - }); - }, __("View")); + frm.add_custom_button( + __("Gantt Chart"), + function () { + frappe.route_options = { + project: frm.doc.name, + }; + frappe.set_route("List", "Task", "Gantt"); + }, + __("View") + ); + + frm.add_custom_button( + __("Kanban Board"), + () => { + frappe + .call( + "erpnext.projects.doctype.project.project.create_kanban_board_if_not_exists", + { + project: frm.doc.name, + } + ) + .then(() => { + frappe.set_route("List", "Task", "Kanban", frm.doc.project_name); + }); + }, + __("View") + ); } } - - }, - update_total_purchase_cost: function(frm) { + update_total_purchase_cost: function (frm) { frappe.call({ method: "erpnext.projects.doctype.project.project.recalculate_project_total_purchase_cost", - args: {project: frm.doc.name}, + args: { project: frm.doc.name }, freeze: true, - freeze_message: __('Recalculating Purchase Cost against this Project...'), - callback: function(r) { + freeze_message: __("Recalculating Purchase Cost against this Project..."), + callback: function (r) { if (r && !r.exc) { - frappe.msgprint(__('Total Purchase Cost has been updated')); + frappe.msgprint(__("Total Purchase Cost has been updated")); frm.refresh(); } - } - + }, }); }, - set_project_status_button: function(frm) { - frm.add_custom_button(__('Set Project Status'), () => { - let d = new frappe.ui.Dialog({ - "title": __("Set Project Status"), - "fields": [ - { - "fieldname": "status", - "fieldtype": "Select", - "label": "Status", - "reqd": 1, - "options": "Completed\nCancelled", + set_project_status_button: function (frm) { + frm.add_custom_button( + __("Set Project Status"), + () => { + let d = new frappe.ui.Dialog({ + title: __("Set Project Status"), + fields: [ + { + fieldname: "status", + fieldtype: "Select", + label: "Status", + reqd: 1, + options: "Completed\nCancelled", + }, + ], + primary_action: function () { + frm.events.set_status(frm, d.get_values().status); + d.hide(); }, - ], - primary_action: function() { - frm.events.set_status(frm, d.get_values().status); - d.hide(); - }, - primary_action_label: __("Set Project Status") - }).show(); - }, __("Actions")); + primary_action_label: __("Set Project Status"), + }).show(); + }, + __("Actions") + ); }, - create_duplicate: function(frm) { - return new Promise(resolve => { - frappe.prompt('Project Name', (data) => { - frappe.xcall('erpnext.projects.doctype.project.project.create_duplicate_project', - { + create_duplicate: function (frm) { + return new Promise((resolve) => { + frappe.prompt("Project Name", (data) => { + frappe + .xcall("erpnext.projects.doctype.project.project.create_duplicate_project", { prev_doc: frm.doc, - project_name: data.value - }).then(() => { - frappe.set_route('Form', "Project", data.value); - frappe.show_alert(__("Duplicate project has been created")); - }); + project_name: data.value, + }) + .then(() => { + frappe.set_route("Form", "Project", data.value); + frappe.show_alert(__("Duplicate project has been created")); + }); resolve(); }); }); }, - set_status: function(frm, status) { - frappe.confirm(__('Set Project and all Tasks to status {0}?', [status.bold()]), () => { - frappe.xcall('erpnext.projects.doctype.project.project.set_project_status', - {project: frm.doc.name, status: status}).then(() => { - frm.reload_doc(); - }); + set_status: function (frm, status) { + frappe.confirm(__("Set Project and all Tasks to status {0}?", [status.bold()]), () => { + frappe + .xcall("erpnext.projects.doctype.project.project.set_project_status", { + project: frm.doc.name, + status: status, + }) + .then(() => { + frm.reload_doc(); + }); }); }, - }); function open_form(frm, doctype, child_doctype, parentfield) { @@ -184,5 +209,4 @@ function open_form(frm, doctype, child_doctype, parentfield) { frappe.ui.form.make_quick_entry(doctype, null, null, new_doc); }); - } diff --git a/erpnext/projects/doctype/project/project_list.js b/erpnext/projects/doctype/project/project_list.js index 5ad4bb7f93b5..1503b1ee5d3f 100644 --- a/erpnext/projects/doctype/project/project_list.js +++ b/erpnext/projects/doctype/project/project_list.js @@ -1,11 +1,11 @@ -frappe.listview_settings['Project'] = { +frappe.listview_settings["Project"] = { add_fields: ["status", "priority", "is_active", "percent_complete", "expected_end_date", "project_name"], - filters:[["status","=", "Open"]], - get_indicator: function(doc) { - if(doc.status=="Open" && doc.percent_complete) { + filters: [["status", "=", "Open"]], + get_indicator: function (doc) { + if (doc.status == "Open" && doc.percent_complete) { return [__("{0}%", [cint(doc.percent_complete)]), "orange", "percent_complete,>,0|status,=,Open"]; } else { return [__(doc.status), frappe.utils.guess_colour(doc.status), "status,=," + doc.status]; } - } + }, }; diff --git a/erpnext/projects/doctype/project/project_timesheet.js b/erpnext/projects/doctype/project/project_timesheet.js index 32df04ff98bc..bc6de3134da5 100644 --- a/erpnext/projects/doctype/project/project_timesheet.js +++ b/erpnext/projects/doctype/project/project_timesheet.js @@ -1,53 +1,63 @@ - -QUnit.test("test project", function(assert) { +QUnit.test("test project", function (assert) { assert.expect(6); let done = assert.async(); - var task_title = ["Documentation","Implementation","Testing"]; + var task_title = ["Documentation", "Implementation", "Testing"]; // To create a timesheet with different tasks and costs - let timesheet = (title,start_time,end_time,bill_rate,cost_rate) => { + let timesheet = (title, start_time, end_time, bill_rate, cost_rate) => { return frappe.run_serially([ - () => frappe.db.get_value('Task', {'subject': title}, 'name'), + () => frappe.db.get_value("Task", { subject: title }, "name"), (task) => { // Creating timesheet for a project - return frappe.tests.make('Timesheet', [ - {time_logs:[ - [ - {activity_type: 'Communication'}, - {from_time: start_time}, - {to_time: end_time}, - {hours: 2}, - {project: 'Test App'}, - {task: task.name}, - {billable: '1'}, - {billing_rate: bill_rate}, - {costing_rate: cost_rate} - ] - ]} + return frappe.tests.make("Timesheet", [ + { + time_logs: [ + [ + { activity_type: "Communication" }, + { from_time: start_time }, + { to_time: end_time }, + { hours: 2 }, + { project: "Test App" }, + { task: task.name }, + { billable: "1" }, + { billing_rate: bill_rate }, + { costing_rate: cost_rate }, + ], + ], + }, ]); }, // To check if a correct billable and costing amount is calculated for every task () => { - if(title=== 'Documentation') - { - assert.ok(cur_frm.get_field('total_billable_amount').get_value()==20, - 'Billable amount for Documentation task is correctly calculated'); - assert.ok(cur_frm.get_field('total_costing_amount').get_value()==16, - 'Costing amount for Documentation task is correctly calculated'); + if (title === "Documentation") { + assert.ok( + cur_frm.get_field("total_billable_amount").get_value() == 20, + "Billable amount for Documentation task is correctly calculated" + ); + assert.ok( + cur_frm.get_field("total_costing_amount").get_value() == 16, + "Costing amount for Documentation task is correctly calculated" + ); } - if(title=== 'Implementation') - { - assert.ok(cur_frm.get_field('total_billable_amount').get_value()==40, - 'Billable amount for Implementation task is correctly calculated'); - assert.ok(cur_frm.get_field('total_costing_amount').get_value()==32, - 'Costing amount for Implementation task is correctly calculated'); + if (title === "Implementation") { + assert.ok( + cur_frm.get_field("total_billable_amount").get_value() == 40, + "Billable amount for Implementation task is correctly calculated" + ); + assert.ok( + cur_frm.get_field("total_costing_amount").get_value() == 32, + "Costing amount for Implementation task is correctly calculated" + ); } - if(title=== 'Testing') - { - assert.ok(cur_frm.get_field('total_billable_amount').get_value()==60, - 'Billable amount for Testing task correctly calculated'); - assert.ok(cur_frm.get_field('total_costing_amount').get_value()==50, - 'Costing amount for Testing task is correctly calculated'); + if (title === "Testing") { + assert.ok( + cur_frm.get_field("total_billable_amount").get_value() == 60, + "Billable amount for Testing task correctly calculated" + ); + assert.ok( + cur_frm.get_field("total_costing_amount").get_value() == 50, + "Costing amount for Testing task is correctly calculated" + ); } }, ]); @@ -55,37 +65,39 @@ QUnit.test("test project", function(assert) { frappe.run_serially([ () => { // Creating project with task - return frappe.tests.make('Project', [ - { project_name: 'Test App'}, - { expected_start_date: '2017-07-22'}, - { expected_end_date: '2017-09-22'}, - { estimated_costing: '10,000.00'}, - { tasks:[ - [ - {title: 'Documentation'}, - {start_date: '2017-07-24'}, - {end_date: '2017-07-31'}, - {description: 'To make a proper documentation defining requirements etc'} - ], - [ - {title: 'Implementation'}, - {start_date: '2017-08-01'}, - {end_date: '2017-08-01'}, - {description: 'Writing algorithms and to code the functionalities'} + return frappe.tests.make("Project", [ + { project_name: "Test App" }, + { expected_start_date: "2017-07-22" }, + { expected_end_date: "2017-09-22" }, + { estimated_costing: "10,000.00" }, + { + tasks: [ + [ + { title: "Documentation" }, + { start_date: "2017-07-24" }, + { end_date: "2017-07-31" }, + { description: "To make a proper documentation defining requirements etc" }, + ], + [ + { title: "Implementation" }, + { start_date: "2017-08-01" }, + { end_date: "2017-08-01" }, + { description: "Writing algorithms and to code the functionalities" }, + ], + [ + { title: "Testing" }, + { start_date: "2017-08-01" }, + { end_date: "2017-08-15" }, + { description: "To make the test cases and test the functionalities" }, + ], ], - [ - {title: 'Testing'}, - {start_date: '2017-08-01'}, - {end_date: '2017-08-15'}, - {description: 'To make the test cases and test the functionalities'} - ] - ]} + }, ]); }, // Creating Timesheet with different tasks - () => timesheet(task_title[0],'2017-07-24 13:00:00','2017-07-24 13:00:00',10,8), - () => timesheet(task_title[1],'2017-07-25 13:00:00','2017-07-25 15:00:00',20,16), - () => timesheet(task_title[2],'2017-07-26 13:00:00','2017-07-26 15:00:00',30,25), - () => done() + () => timesheet(task_title[0], "2017-07-24 13:00:00", "2017-07-24 13:00:00", 10, 8), + () => timesheet(task_title[1], "2017-07-25 13:00:00", "2017-07-25 15:00:00", 20, 16), + () => timesheet(task_title[2], "2017-07-26 13:00:00", "2017-07-26 15:00:00", 30, 25), + () => done(), ]); }); diff --git a/erpnext/projects/doctype/project_template/project_template.js b/erpnext/projects/doctype/project_template/project_template.js index 3d3c15c6e056..a2d008af0270 100644 --- a/erpnext/projects/doctype/project_template/project_template.js +++ b/erpnext/projects/doctype/project_template/project_template.js @@ -1,7 +1,7 @@ // Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Project Template', { +frappe.ui.form.on("Project Template", { // refresh: function(frm) { // } @@ -9,19 +9,19 @@ frappe.ui.form.on('Project Template', { frm.set_query("task", "tasks", function () { return { filters: { - "is_template": 1 - } + is_template: 1, + }, }; }); - } + }, }); -frappe.ui.form.on('Project Template Task', { +frappe.ui.form.on("Project Template Task", { task: function (frm, cdt, cdn) { var row = locals[cdt][cdn]; frappe.db.get_value("Task", row.task, "subject", (value) => { row.subject = value.subject; refresh_field("tasks"); }); - } + }, }); diff --git a/erpnext/projects/doctype/project_type/project_type.js b/erpnext/projects/doctype/project_type/project_type.js index e3dda5eccc5d..8506c787ece3 100644 --- a/erpnext/projects/doctype/project_type/project_type.js +++ b/erpnext/projects/doctype/project_type/project_type.js @@ -1,6 +1,4 @@ // Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Project Type', { - -}); +frappe.ui.form.on("Project Type", {}); diff --git a/erpnext/projects/doctype/project_update/project_update.js b/erpnext/projects/doctype/project_update/project_update.js index 990c1afd9ab8..4e3f0fa97d27 100644 --- a/erpnext/projects/doctype/project_update/project_update.js +++ b/erpnext/projects/doctype/project_update/project_update.js @@ -1,10 +1,8 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Project Update', { - refresh: function() { - - }, +frappe.ui.form.on("Project Update", { + refresh: function () {}, onload: function (frm) { frm.set_value("naming_series", "UPDATE-.project.-.YY.MM.DD.-.####"); @@ -13,5 +11,5 @@ frappe.ui.form.on('Project Update', { validate: function (frm) { frm.set_value("time", frappe.datetime.now_time()); frm.set_value("date", frappe.datetime.nowdate()); - } + }, }); diff --git a/erpnext/projects/doctype/projects_settings/projects_settings.js b/erpnext/projects/doctype/projects_settings/projects_settings.js index 9902b8349209..08f50a6d989f 100644 --- a/erpnext/projects/doctype/projects_settings/projects_settings.js +++ b/erpnext/projects/doctype/projects_settings/projects_settings.js @@ -1,8 +1,6 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Projects Settings', { - refresh: function(frm) { - - } +frappe.ui.form.on("Projects Settings", { + refresh: function (frm) {}, }); diff --git a/erpnext/projects/doctype/task/task.js b/erpnext/projects/doctype/task/task.js index 3cd92ee719db..c56c998a5184 100644 --- a/erpnext/projects/doctype/task/task.js +++ b/erpnext/projects/doctype/task/task.js @@ -6,33 +6,34 @@ frappe.provide("erpnext.projects"); frappe.ui.form.on("Task", { setup: function (frm) { frm.make_methods = { - 'Timesheet': () => frappe.model.open_mapped_doc({ - method: 'erpnext.projects.doctype.task.task.make_timesheet', - frm: frm - }) - } + Timesheet: () => + frappe.model.open_mapped_doc({ + method: "erpnext.projects.doctype.task.task.make_timesheet", + frm: frm, + }), + }; }, onload: function (frm) { frm.set_query("task", "depends_on", function () { let filters = { - name: ["!=", frm.doc.name] + name: ["!=", frm.doc.name], }; if (frm.doc.project) filters["project"] = frm.doc.project; return { - filters: filters + filters: filters, }; - }) + }); frm.set_query("parent_task", function () { let filters = { - "is_group": 1, - "name": ["!=", frm.doc.name] + is_group: 1, + name: ["!=", frm.doc.name], }; if (frm.doc.project) filters["project"] = frm.doc.project; return { - filters: filters - } + filters: filters, + }; }); }, @@ -40,22 +41,22 @@ frappe.ui.form.on("Task", { frappe.call({ method: "erpnext.projects.doctype.task.task.check_if_child_exists", args: { - name: frm.doc.name + name: frm.doc.name, }, callback: function (r) { if (r.message.length > 0) { - let message = __('Cannot convert Task to non-group because the following child Tasks exist: {0}.', + let message = __( + "Cannot convert Task to non-group because the following child Tasks exist: {0}.", [r.message.join(", ")] ); frappe.msgprint(message); frm.reload_doc(); } - } - }) + }, + }); }, validate: function (frm) { - frm.doc.project && frappe.model.remove_from_locals("Project", - frm.doc.project); - } + frm.doc.project && frappe.model.remove_from_locals("Project", frm.doc.project); + }, }); diff --git a/erpnext/projects/doctype/task/task_calendar.js b/erpnext/projects/doctype/task/task_calendar.js index 49dbb76a1a57..768eb15b1571 100644 --- a/erpnext/projects/doctype/task/task_calendar.js +++ b/erpnext/projects/doctype/task/task_calendar.js @@ -3,21 +3,21 @@ frappe.views.calendar["Task"] = { field_map: { - "start": "exp_start_date", - "end": "exp_end_date", - "id": "name", - "title": "subject", - "allDay": "allDay", - "progress": "progress" + start: "exp_start_date", + end: "exp_end_date", + id: "name", + title: "subject", + allDay: "allDay", + progress: "progress", }, gantt: true, filters: [ { - "fieldtype": "Link", - "fieldname": "project", - "options": "Project", - "label": __("Project") - } + fieldtype: "Link", + fieldname: "project", + options: "Project", + label: __("Project"), + }, ], - get_events_method: "frappe.desk.calendar.get_events" -} + get_events_method: "frappe.desk.calendar.get_events", +}; diff --git a/erpnext/projects/doctype/task/task_list.js b/erpnext/projects/doctype/task/task_list.js index 5ab8bae2e1d6..17b0ed2c7fa0 100644 --- a/erpnext/projects/doctype/task/task_list.js +++ b/erpnext/projects/doctype/task/task_list.js @@ -1,28 +1,36 @@ -frappe.listview_settings['Task'] = { - add_fields: ["project", "status", "priority", "exp_start_date", - "exp_end_date", "subject", "progress", "depends_on_tasks"], +frappe.listview_settings["Task"] = { + add_fields: [ + "project", + "status", + "priority", + "exp_start_date", + "exp_end_date", + "subject", + "progress", + "depends_on_tasks", + ], filters: [["status", "=", "Open"]], - onload: function(listview) { + onload: function (listview) { var method = "erpnext.projects.doctype.task.task.set_multiple_status"; - listview.page.add_menu_item(__("Set as Open"), function() { - listview.call_for_selected_items(method, {"status": "Open"}); + listview.page.add_menu_item(__("Set as Open"), function () { + listview.call_for_selected_items(method, { status: "Open" }); }); - listview.page.add_menu_item(__("Set as Completed"), function() { - listview.call_for_selected_items(method, {"status": "Completed"}); + listview.page.add_menu_item(__("Set as Completed"), function () { + listview.call_for_selected_items(method, { status: "Completed" }); }); }, - get_indicator: function(doc) { + get_indicator: function (doc) { var colors = { - "Open": "orange", - "Overdue": "red", + Open: "orange", + Overdue: "red", "Pending Review": "orange", - "Working": "orange", - "Completed": "green", - "Cancelled": "dark grey", - "Template": "blue" - } + Working: "orange", + Completed: "green", + Cancelled: "dark grey", + Template: "blue", + }; return [__(doc.status), colors[doc.status], "status,=," + doc.status]; }, gantt_custom_popup_html: function (ganttobj, task) { diff --git a/erpnext/projects/doctype/task/task_tree.js b/erpnext/projects/doctype/task/task_tree.js index 9ebfcdd180c5..fba1b309260c 100644 --- a/erpnext/projects/doctype/task/task_tree.js +++ b/erpnext/projects/doctype/task/task_tree.js @@ -1,84 +1,88 @@ frappe.provide("frappe.treeview_settings"); -frappe.treeview_settings['Task'] = { +frappe.treeview_settings["Task"] = { get_tree_nodes: "erpnext.projects.doctype.task.task.get_children", add_tree_node: "erpnext.projects.doctype.task.task.add_node", filters: [ { fieldname: "project", - fieldtype:"Link", + fieldtype: "Link", options: "Project", label: __("Project"), }, { fieldname: "task", - fieldtype:"Link", + fieldtype: "Link", options: "Task", label: __("Task"), - get_query: function() { - var me = frappe.treeview_settings['Task']; + get_query: function () { + var me = frappe.treeview_settings["Task"]; var project = me.page.fields_dict.project.get_value(); - var args = [["Task", 'is_group', '=', 1]]; - if(project){ - args.push(["Task", 'project', "=", project]); + var args = [["Task", "is_group", "=", 1]]; + if (project) { + args.push(["Task", "project", "=", project]); } return { - filters: args + filters: args, }; - } - } + }, + }, ], breadcrumb: "Projects", get_tree_root: false, root_label: "All Tasks", ignore_fields: ["parent_task"], - onload: function(me) { - frappe.treeview_settings['Task'].page = {}; - $.extend(frappe.treeview_settings['Task'].page, me.page); + onload: function (me) { + frappe.treeview_settings["Task"].page = {}; + $.extend(frappe.treeview_settings["Task"].page, me.page); me.make_tree(); }, toolbar: [ { - label:__("Add Multiple"), - condition: function(node) { + label: __("Add Multiple"), + condition: function (node) { return node.expandable; }, - click: function(node) { + click: function (node) { this.data = []; const dialog = new frappe.ui.Dialog({ title: __("Add Multiple Tasks"), fields: [ { - fieldname: "multiple_tasks", fieldtype: "Table", - in_place_edit: true, data: this.data, + fieldname: "multiple_tasks", + fieldtype: "Table", + in_place_edit: true, + data: this.data, get_data: () => { return this.data; }, - fields: [{ - fieldtype:'Data', - fieldname:"subject", - in_list_view: 1, - reqd: 1, - label: __("Subject") - }] + fields: [ + { + fieldtype: "Data", + fieldname: "subject", + in_list_view: 1, + reqd: 1, + label: __("Subject"), + }, + ], }, ], - primary_action: function() { + primary_action: function () { dialog.hide(); return frappe.call({ method: "erpnext.projects.doctype.task.task.add_multiple_tasks", args: { data: dialog.get_values()["multiple_tasks"], - parent: node.data.value + parent: node.data.value, }, - callback: function() { } + callback: function () {}, }); }, - primary_action_label: __('Create') + primary_action_label: __("Create"), }); dialog.show(); - } - } + }, + }, ], - extend_toolbar: true + extend_toolbar: true, }; diff --git a/erpnext/projects/doctype/task_type/task_type.js b/erpnext/projects/doctype/task_type/task_type.js index c1be5da4f648..9c6176dbf550 100644 --- a/erpnext/projects/doctype/task_type/task_type.js +++ b/erpnext/projects/doctype/task_type/task_type.js @@ -1,8 +1,7 @@ // Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Task Type', { +frappe.ui.form.on("Task Type", { // refresh: function(frm) { - // } }); diff --git a/erpnext/projects/doctype/timesheet/timesheet.js b/erpnext/projects/doctype/timesheet/timesheet.js index d1d07a79d678..0d03d6085d96 100644 --- a/erpnext/projects/doctype/timesheet/timesheet.js +++ b/erpnext/projects/doctype/timesheet/timesheet.js @@ -2,39 +2,39 @@ // License: GNU General Public License v3. See license.txt frappe.ui.form.on("Timesheet", { - setup: function(frm) { + setup: function (frm) { frappe.require("/assets/erpnext/js/projects/timer.js"); - frm.ignore_doctypes_on_cancel_all = ['Sales Invoice']; + frm.ignore_doctypes_on_cancel_all = ["Sales Invoice"]; - frm.fields_dict.employee.get_query = function() { + frm.fields_dict.employee.get_query = function () { return { - filters:{ - 'status': 'Active' - } + filters: { + status: "Active", + }, }; }; - frm.fields_dict['time_logs'].grid.get_field('task').get_query = function(frm, cdt, cdn) { + frm.fields_dict["time_logs"].grid.get_field("task").get_query = function (frm, cdt, cdn) { var child = locals[cdt][cdn]; - return{ + return { filters: { - 'project': child.project, - 'status': ["!=", "Cancelled"] - } + project: child.project, + status: ["!=", "Cancelled"], + }, }; }; - frm.fields_dict['time_logs'].grid.get_field('project').get_query = function() { - return{ + frm.fields_dict["time_logs"].grid.get_field("project").get_query = function () { + return { filters: { - 'company': frm.doc.company - } + company: frm.doc.company, + }, }; }; }, - onload: function(frm) { + onload: function (frm) { if (frm.doc.__islocal && frm.doc.time_logs) { calculate_time_and_amount(frm); } @@ -44,33 +44,32 @@ frappe.ui.form.on("Timesheet", { } }, - refresh: function(frm) { + refresh: function (frm) { if (frm.doc.docstatus == 1) { if ( - (frm.doc.per_billed < 100) - && (frm.doc.total_billable_hours) - && (frm.doc.total_billable_hours > frm.doc.total_billed_hours) + frm.doc.per_billed < 100 && + frm.doc.total_billable_hours && + frm.doc.total_billable_hours > frm.doc.total_billed_hours ) { - frm.add_custom_button(__("Create Sales Invoice"), function() { + frm.add_custom_button(__("Create Sales Invoice"), function () { frm.trigger("make_invoice"); }); } } if (frm.doc.docstatus < 1) { - - let button = 'Start Timer'; - $.each(frm.doc.time_logs || [], function(i, row) { - if ((row.from_time <= frappe.datetime.now_datetime()) && !row.completed) { - button = 'Resume Timer'; + let button = "Start Timer"; + $.each(frm.doc.time_logs || [], function (i, row) { + if (row.from_time <= frappe.datetime.now_datetime() && !row.completed) { + button = "Resume Timer"; } }); - frm.add_custom_button(__(button), function() { + frm.add_custom_button(__(button), function () { var flag = true; - $.each(frm.doc.time_logs || [], function(i, row) { + $.each(frm.doc.time_logs || [], function (i, row) { // Fetch the row for which from_time is not present - if (flag && row.activity_type && !row.from_time){ + if (flag && row.activity_type && !row.from_time) { erpnext.timesheet.timer(frm, row); row.from_time = frappe.datetime.now_datetime(); frm.refresh_fields("time_logs"); @@ -79,7 +78,10 @@ frappe.ui.form.on("Timesheet", { } // Fetch the row for timer where activity is not completed and from_time is before now_time if (flag && row.from_time <= frappe.datetime.now_datetime() && !row.completed) { - let timestamp = moment(frappe.datetime.now_datetime()).diff(moment(row.from_time),"seconds"); + let timestamp = moment(frappe.datetime.now_datetime()).diff( + moment(row.from_time), + "seconds" + ); erpnext.timesheet.timer(frm, row, timestamp); flag = false; } @@ -90,143 +92,168 @@ frappe.ui.form.on("Timesheet", { } }).addClass("btn-primary"); } - if(frm.doc.per_billed > 0) { + if (frm.doc.per_billed > 0) { frm.fields_dict["time_logs"].grid.toggle_enable("billing_hours", false); frm.fields_dict["time_logs"].grid.toggle_enable("is_billable", false); } let filters = { - "status": "Open" + status: "Open", }; if (frm.doc.customer) { filters["customer"] = frm.doc.customer; } - frm.set_query('parent_project', function(doc) { + frm.set_query("parent_project", function (doc) { return { - filters: filters + filters: filters, }; }); - frm.trigger('setup_filters'); - frm.trigger('set_dynamic_field_label'); + frm.trigger("setup_filters"); + frm.trigger("set_dynamic_field_label"); }, - customer: function(frm) { - frm.set_query('project', 'time_logs', function(doc) { + customer: function (frm) { + frm.set_query("project", "time_logs", function (doc) { return { filters: { - "customer": doc.customer - } + customer: doc.customer, + }, }; }); frm.refresh(); }, - currency: function(frm) { - let base_currency = frappe.defaults.get_global_default('currency'); - if (frm.doc.currency && (base_currency != frm.doc.currency)) { + currency: function (frm) { + let base_currency = frappe.defaults.get_global_default("currency"); + if (frm.doc.currency && base_currency != frm.doc.currency) { frappe.call({ method: "erpnext.setup.utils.get_exchange_rate", args: { from_currency: frm.doc.currency, - to_currency: base_currency + to_currency: base_currency, }, - callback: function(r) { + callback: function (r) { if (r.message) { - frm.set_value('exchange_rate', flt(r.message)); - frm.set_df_property("exchange_rate", "description", "1 " + frm.doc.currency + " = [?] " + base_currency); + frm.set_value("exchange_rate", flt(r.message)); + frm.set_df_property( + "exchange_rate", + "description", + "1 " + frm.doc.currency + " = [?] " + base_currency + ); } - } + }, }); } - frm.trigger('set_dynamic_field_label'); + frm.trigger("set_dynamic_field_label"); }, - exchange_rate: function(frm) { - $.each(frm.doc.time_logs, function(i, d) { + exchange_rate: function (frm) { + $.each(frm.doc.time_logs, function (i, d) { calculate_billing_costing_amount(frm, d.doctype, d.name); }); calculate_time_and_amount(frm); }, - set_dynamic_field_label: function(frm) { - let base_currency = frappe.defaults.get_global_default('currency'); - frm.set_currency_labels(["base_total_costing_amount", "base_total_billable_amount", "base_total_billed_amount"], base_currency); - frm.set_currency_labels(["total_costing_amount", "total_billable_amount", "total_billed_amount"], frm.doc.currency); - - frm.toggle_display(["base_total_costing_amount", "base_total_billable_amount", "base_total_billed_amount"], - frm.doc.currency != base_currency); + set_dynamic_field_label: function (frm) { + let base_currency = frappe.defaults.get_global_default("currency"); + frm.set_currency_labels( + ["base_total_costing_amount", "base_total_billable_amount", "base_total_billed_amount"], + base_currency + ); + frm.set_currency_labels( + ["total_costing_amount", "total_billable_amount", "total_billed_amount"], + frm.doc.currency + ); + + frm.toggle_display( + ["base_total_costing_amount", "base_total_billable_amount", "base_total_billed_amount"], + frm.doc.currency != base_currency + ); if (frm.doc.time_logs.length > 0) { - frm.set_currency_labels(["base_billing_rate", "base_billing_amount", "base_costing_rate", "base_costing_amount"], base_currency, "time_logs"); - frm.set_currency_labels(["billing_rate", "billing_amount", "costing_rate", "costing_amount"], frm.doc.currency, "time_logs"); + frm.set_currency_labels( + ["base_billing_rate", "base_billing_amount", "base_costing_rate", "base_costing_amount"], + base_currency, + "time_logs" + ); + frm.set_currency_labels( + ["billing_rate", "billing_amount", "costing_rate", "costing_amount"], + frm.doc.currency, + "time_logs" + ); let time_logs_grid = frm.fields_dict.time_logs.grid; - $.each(["base_billing_rate", "base_billing_amount", "base_costing_rate", "base_costing_amount"], function(i, d) { - if (frappe.meta.get_docfield(time_logs_grid.doctype, d)) - time_logs_grid.set_column_disp(d, frm.doc.currency != base_currency); - }); + $.each( + ["base_billing_rate", "base_billing_amount", "base_costing_rate", "base_costing_amount"], + function (i, d) { + if (frappe.meta.get_docfield(time_logs_grid.doctype, d)) + time_logs_grid.set_column_disp(d, frm.doc.currency != base_currency); + } + ); } frm.refresh_fields(); }, - make_invoice: function(frm) { - let fields = [{ - "fieldtype": "Link", - "label": __("Item Code"), - "fieldname": "item_code", - "options": "Item" - }]; + make_invoice: function (frm) { + let fields = [ + { + fieldtype: "Link", + label: __("Item Code"), + fieldname: "item_code", + options: "Item", + }, + ]; if (!frm.doc.customer) { fields.push({ - "fieldtype": "Link", - "label": __("Customer"), - "fieldname": "customer", - "options": "Customer", - "default": frm.doc.customer + fieldtype: "Link", + label: __("Customer"), + fieldname: "customer", + options: "Customer", + default: frm.doc.customer, }); } let dialog = new frappe.ui.Dialog({ title: __("Create Sales Invoice"), - fields: fields + fields: fields, }); - dialog.set_primary_action(__('Create Sales Invoice'), () => { + dialog.set_primary_action(__("Create Sales Invoice"), () => { var args = dialog.get_values(); - if(!args) return; + if (!args) return; dialog.hide(); return frappe.call({ type: "GET", method: "erpnext.projects.doctype.timesheet.timesheet.make_sales_invoice", args: { - "source_name": frm.doc.name, - "item_code": args.item_code, - "customer": frm.doc.customer || args.customer, - "currency": frm.doc.currency + source_name: frm.doc.name, + item_code: args.item_code, + customer: frm.doc.customer || args.customer, + currency: frm.doc.currency, }, freeze: true, - callback: function(r) { - if(!r.exc) { + callback: function (r) { + if (!r.exc) { frappe.model.sync(r.message); frappe.set_route("Form", r.message.doctype, r.message.name); } - } + }, }); }); dialog.show(); }, - parent_project: function(frm) { + parent_project: function (frm) { set_project_in_timelog(frm); - } + }, }); frappe.ui.form.on("Timesheet Detail", { - time_logs_remove: function(frm) { + time_logs_remove: function (frm) { calculate_time_and_amount(frm); }, @@ -239,47 +266,47 @@ frappe.ui.form.on("Timesheet Detail", { } }, - from_time: function(frm, cdt, cdn) { + from_time: function (frm, cdt, cdn) { calculate_end_time(frm, cdt, cdn); }, - to_time: function(frm, cdt, cdn) { + to_time: function (frm, cdt, cdn) { var child = locals[cdt][cdn]; - if(frm._setting_hours) return; + if (frm._setting_hours) return; var hours = moment(child.to_time).diff(moment(child.from_time), "seconds") / 3600; frappe.model.set_value(cdt, cdn, "hours", hours); }, - time_logs_add: function(frm, cdt, cdn) { - if(frm.doc.parent_project) { - frappe.model.set_value(cdt, cdn, 'project', frm.doc.parent_project); + time_logs_add: function (frm, cdt, cdn) { + if (frm.doc.parent_project) { + frappe.model.set_value(cdt, cdn, "project", frm.doc.parent_project); } }, - hours: function(frm, cdt, cdn) { + hours: function (frm, cdt, cdn) { calculate_end_time(frm, cdt, cdn); calculate_billing_costing_amount(frm, cdt, cdn); calculate_time_and_amount(frm); }, - billing_hours: function(frm, cdt, cdn) { + billing_hours: function (frm, cdt, cdn) { calculate_billing_costing_amount(frm, cdt, cdn); calculate_time_and_amount(frm); }, - billing_rate: function(frm, cdt, cdn) { + billing_rate: function (frm, cdt, cdn) { calculate_billing_costing_amount(frm, cdt, cdn); calculate_time_and_amount(frm); }, - costing_rate: function(frm, cdt, cdn) { + costing_rate: function (frm, cdt, cdn) { calculate_billing_costing_amount(frm, cdt, cdn); calculate_time_and_amount(frm); }, - is_billable: function(frm, cdt, cdn) { + is_billable: function (frm, cdt, cdn) { update_billing_hours(frm, cdt, cdn); update_time_rates(frm, cdt, cdn); calculate_billing_costing_amount(frm, cdt, cdn); @@ -294,7 +321,7 @@ frappe.ui.form.on("Timesheet Detail", { args: { employee: frm.doc.employee, activity_type: frm.selected_doc.activity_type, - currency: frm.doc.currency + currency: frm.doc.currency, }, callback: function (r) { if (r.message) { @@ -302,72 +329,71 @@ frappe.ui.form.on("Timesheet Detail", { frappe.model.set_value(cdt, cdn, "costing_rate", r.message["costing_rate"]); calculate_billing_costing_amount(frm, cdt, cdn); } - } + }, }); - } + }, }); -var calculate_end_time = function(frm, cdt, cdn) { +var calculate_end_time = function (frm, cdt, cdn) { let child = locals[cdt][cdn]; - if(!child.from_time) { + if (!child.from_time) { // if from_time value is not available then set the current datetime frappe.model.set_value(cdt, cdn, "from_time", frappe.datetime.get_datetime_as_string()); } let d = moment(child.from_time); - if(child.hours) { + if (child.hours) { d.add(child.hours, "hours"); frm._setting_hours = true; - frappe.model.set_value(cdt, cdn, "to_time", - d.format(frappe.defaultDatetimeFormat)).then(() => { + frappe.model.set_value(cdt, cdn, "to_time", d.format(frappe.defaultDatetimeFormat)).then(() => { frm._setting_hours = false; }); } }; -var update_billing_hours = function(frm, cdt, cdn) { +var update_billing_hours = function (frm, cdt, cdn) { let child = frappe.get_doc(cdt, cdn); if (!child.is_billable) { - frappe.model.set_value(cdt, cdn, 'billing_hours', 0.0); + frappe.model.set_value(cdt, cdn, "billing_hours", 0.0); } else { // bill all hours by default frappe.model.set_value(cdt, cdn, "billing_hours", child.hours); } }; -var update_time_rates = function(frm, cdt, cdn) { +var update_time_rates = function (frm, cdt, cdn) { let child = frappe.get_doc(cdt, cdn); if (!child.is_billable) { - frappe.model.set_value(cdt, cdn, 'billing_rate', 0.0); + frappe.model.set_value(cdt, cdn, "billing_rate", 0.0); } }; -var calculate_billing_costing_amount = function(frm, cdt, cdn) { +var calculate_billing_costing_amount = function (frm, cdt, cdn) { let row = frappe.get_doc(cdt, cdn); let billing_amount = 0.0; let base_billing_amount = 0.0; let exchange_rate = flt(frm.doc.exchange_rate); - frappe.model.set_value(cdt, cdn, 'base_billing_rate', flt(row.billing_rate) * exchange_rate); - frappe.model.set_value(cdt, cdn, 'base_costing_rate', flt(row.costing_rate) * exchange_rate); + frappe.model.set_value(cdt, cdn, "base_billing_rate", flt(row.billing_rate) * exchange_rate); + frappe.model.set_value(cdt, cdn, "base_costing_rate", flt(row.costing_rate) * exchange_rate); if (row.billing_hours && row.is_billable) { base_billing_amount = flt(row.billing_hours) * flt(row.base_billing_rate); billing_amount = flt(row.billing_hours) * flt(row.billing_rate); } - frappe.model.set_value(cdt, cdn, 'base_billing_amount', base_billing_amount); - frappe.model.set_value(cdt, cdn, 'base_costing_amount', flt(row.base_costing_rate) * flt(row.hours)); - frappe.model.set_value(cdt, cdn, 'billing_amount', billing_amount); - frappe.model.set_value(cdt, cdn, 'costing_amount', flt(row.costing_rate) * flt(row.hours)); + frappe.model.set_value(cdt, cdn, "base_billing_amount", base_billing_amount); + frappe.model.set_value(cdt, cdn, "base_costing_amount", flt(row.base_costing_rate) * flt(row.hours)); + frappe.model.set_value(cdt, cdn, "billing_amount", billing_amount); + frappe.model.set_value(cdt, cdn, "costing_amount", flt(row.costing_rate) * flt(row.hours)); }; -var calculate_time_and_amount = function(frm) { +var calculate_time_and_amount = function (frm) { let tl = frm.doc.time_logs || []; let total_working_hr = 0; let total_billing_hr = 0; let total_billable_amount = 0; let total_costing_amount = 0; - for(var i=0; i { + const fields = ["name", "company"]; + frappe.db.get_value("Employee", options, fields).then(({ message }) => { if (message) { // there is an employee with the currently logged in user_id frm.set_value("employee", message.name); @@ -399,8 +425,8 @@ const set_employee_and_company = function(frm) { }; function set_project_in_timelog(frm) { - if(frm.doc.parent_project) { - $.each(frm.doc.time_logs || [], function(i, item) { + if (frm.doc.parent_project) { + $.each(frm.doc.time_logs || [], function (i, item) { frappe.model.set_value(item.doctype, item.name, "project", frm.doc.parent_project); }); } diff --git a/erpnext/projects/doctype/timesheet/timesheet_calendar.js b/erpnext/projects/doctype/timesheet/timesheet_calendar.js index 80967ede1ce3..27992a107cbd 100644 --- a/erpnext/projects/doctype/timesheet/timesheet_calendar.js +++ b/erpnext/projects/doctype/timesheet/timesheet_calendar.js @@ -1,32 +1,32 @@ frappe.views.calendar["Timesheet"] = { field_map: { - "start": "start_date", - "end": "end_date", - "name": "parent", - "id": "name", - "allDay": "allDay", - "child_name": "name", - "title": "title" + start: "start_date", + end: "end_date", + name: "parent", + id: "name", + allDay: "allDay", + child_name: "name", + title: "title", }, style_map: { - "0": "info", - "1": "standard", - "2": "danger" + 0: "info", + 1: "standard", + 2: "danger", }, gantt: true, filters: [ { - "fieldtype": "Link", - "fieldname": "project", - "options": "Project", - "label": __("Project") + fieldtype: "Link", + fieldname: "project", + options: "Project", + label: __("Project"), }, { - "fieldtype": "Link", - "fieldname": "employee", - "options": "Employee", - "label": __("Employee") - } + fieldtype: "Link", + fieldname: "employee", + options: "Employee", + label: __("Employee"), + }, ], - get_events_method: "erpnext.projects.doctype.timesheet.timesheet.get_events" -} + get_events_method: "erpnext.projects.doctype.timesheet.timesheet.get_events", +}; diff --git a/erpnext/projects/doctype/timesheet/timesheet_list.js b/erpnext/projects/doctype/timesheet/timesheet_list.js index b59fdc96fe80..0de568ce5896 100644 --- a/erpnext/projects/doctype/timesheet/timesheet_list.js +++ b/erpnext/projects/doctype/timesheet/timesheet_list.js @@ -1,16 +1,16 @@ -frappe.listview_settings['Timesheet'] = { +frappe.listview_settings["Timesheet"] = { add_fields: ["status", "total_hours", "start_date", "end_date"], - get_indicator: function(doc) { - if (doc.status== "Billed") { - return [__("Billed"), "green", "status,=," + "Billed"] + get_indicator: function (doc) { + if (doc.status == "Billed") { + return [__("Billed"), "green", "status,=," + "Billed"]; } - if (doc.status== "Payslip") { - return [__("Payslip"), "green", "status,=," + "Payslip"] + if (doc.status == "Payslip") { + return [__("Payslip"), "green", "status,=," + "Payslip"]; } - if (doc.status== "Completed") { - return [__("Completed"), "green", "status,=," + "Completed"] + if (doc.status == "Completed") { + return [__("Completed"), "green", "status,=," + "Completed"]; } - } + }, }; diff --git a/erpnext/projects/report/daily_timesheet_summary/daily_timesheet_summary.js b/erpnext/projects/report/daily_timesheet_summary/daily_timesheet_summary.js index 93cb9402fa82..60525a1ae411 100644 --- a/erpnext/projects/report/daily_timesheet_summary/daily_timesheet_summary.js +++ b/erpnext/projects/report/daily_timesheet_summary/daily_timesheet_summary.js @@ -2,18 +2,18 @@ // For license information, please see license.txt frappe.query_reports["Daily Timesheet Summary"] = { - "filters": [ + filters: [ { - "fieldname":"from_date", - "label": __("From Date"), - "fieldtype": "Date", - "default": frappe.datetime.get_today() + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + default: frappe.datetime.get_today(), }, { - "fieldname":"to_date", - "label": __("To Date"), - "fieldtype": "Date", - "default": frappe.datetime.get_today() + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + default: frappe.datetime.get_today(), }, - ] -} + ], +}; diff --git a/erpnext/projects/report/delayed_tasks_summary/delayed_tasks_summary.js b/erpnext/projects/report/delayed_tasks_summary/delayed_tasks_summary.js index 5aa44c0a8c9e..983eb448cb58 100644 --- a/erpnext/projects/report/delayed_tasks_summary/delayed_tasks_summary.js +++ b/erpnext/projects/report/delayed_tasks_summary/delayed_tasks_summary.js @@ -3,31 +3,31 @@ /* eslint-disable */ frappe.query_reports["Delayed Tasks Summary"] = { - "filters": [ + filters: [ { - "fieldname": "from_date", - "label": __("From Date"), - "fieldtype": "Date" + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", }, { - "fieldname": "to_date", - "label": __("To Date"), - "fieldtype": "Date" + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", }, { - "fieldname": "priority", - "label": __("Priority"), - "fieldtype": "Select", - "options": ["", "Low", "Medium", "High", "Urgent"] + fieldname: "priority", + label: __("Priority"), + fieldtype: "Select", + options: ["", "Low", "Medium", "High", "Urgent"], }, { - "fieldname": "status", - "label": __("Status"), - "fieldtype": "Select", - "options": ["", "Open", "Working","Pending Review","Overdue","Completed"] + fieldname: "status", + label: __("Status"), + fieldtype: "Select", + options: ["", "Open", "Working", "Pending Review", "Overdue", "Completed"], }, ], - "formatter": function(value, row, column, data, default_formatter) { + formatter: function (value, row, column, data, default_formatter) { value = default_formatter(value, row, column, data); if (column.id == "delay") { if (data["delay"] > 0) { @@ -36,6 +36,6 @@ frappe.query_reports["Delayed Tasks Summary"] = { value = `

    ${value}

    `; } } - return value - } + return value; + }, }; diff --git a/erpnext/projects/report/employee_billing_summary/employee_billing_summary.js b/erpnext/projects/report/employee_billing_summary/employee_billing_summary.js index 9c904c57872a..4bdbf659a5c3 100644 --- a/erpnext/projects/report/employee_billing_summary/employee_billing_summary.js +++ b/erpnext/projects/report/employee_billing_summary/employee_billing_summary.js @@ -3,32 +3,32 @@ /* eslint-disable */ frappe.query_reports["Employee Billing Summary"] = { - "filters": [ + filters: [ { fieldname: "employee", label: __("Employee"), fieldtype: "Link", options: "Employee", - reqd: 1 + reqd: 1, }, { - fieldname:"from_date", + fieldname: "from_date", label: __("From Date"), fieldtype: "Date", default: frappe.datetime.add_months(frappe.datetime.month_start(), -1), - reqd: 1 + reqd: 1, }, { - fieldname:"to_date", + fieldname: "to_date", label: __("To Date"), fieldtype: "Date", default: frappe.datetime.add_days(frappe.datetime.month_start(), -1), - reqd: 1 + reqd: 1, }, { - fieldname:"include_draft_timesheets", + fieldname: "include_draft_timesheets", label: __("Include Timesheets in Draft Status"), fieldtype: "Check", }, - ] -} + ], +}; diff --git a/erpnext/projects/report/project_billing_summary/project_billing_summary.js b/erpnext/projects/report/project_billing_summary/project_billing_summary.js index 6a6f3677e3fb..86c54e519a5f 100644 --- a/erpnext/projects/report/project_billing_summary/project_billing_summary.js +++ b/erpnext/projects/report/project_billing_summary/project_billing_summary.js @@ -3,32 +3,32 @@ /* eslint-disable */ frappe.query_reports["Project Billing Summary"] = { - "filters": [ + filters: [ { fieldname: "project", label: __("Project"), fieldtype: "Link", options: "Project", - reqd: 1 + reqd: 1, }, { - fieldname:"from_date", + fieldname: "from_date", label: __("From Date"), fieldtype: "Date", default: frappe.datetime.add_months(frappe.datetime.month_start(), -1), - reqd: 1 + reqd: 1, }, { - fieldname:"to_date", + fieldname: "to_date", label: __("To Date"), fieldtype: "Date", - default: frappe.datetime.add_days(frappe.datetime.month_start(),-1), - reqd: 1 + default: frappe.datetime.add_days(frappe.datetime.month_start(), -1), + reqd: 1, }, { - fieldname:"include_draft_timesheets", + fieldname: "include_draft_timesheets", label: __("Include Timesheets in Draft Status"), fieldtype: "Check", }, - ] -} + ], +}; diff --git a/erpnext/projects/report/project_summary/project_summary.js b/erpnext/projects/report/project_summary/project_summary.js index 414b7b206a1e..b5bf4bedd1b5 100644 --- a/erpnext/projects/report/project_summary/project_summary.js +++ b/erpnext/projects/report/project_summary/project_summary.js @@ -3,40 +3,40 @@ /* eslint-disable */ frappe.query_reports["Project Summary"] = { - "filters": [ + filters: [ { - "fieldname": "company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_user_default("Company"), - "reqd": 1 + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), + reqd: 1, }, { - "fieldname": "is_active", - "label": __("Is Active"), - "fieldtype": "Select", - "options": "\nYes\nNo", - "default": "Yes", + fieldname: "is_active", + label: __("Is Active"), + fieldtype: "Select", + options: "\nYes\nNo", + default: "Yes", }, { - "fieldname": "status", - "label": __("Status"), - "fieldtype": "Select", - "options": "\nOpen\nCompleted\nCancelled", - "default": "Open" + fieldname: "status", + label: __("Status"), + fieldtype: "Select", + options: "\nOpen\nCompleted\nCancelled", + default: "Open", }, { - "fieldname": "project_type", - "label": __("Project Type"), - "fieldtype": "Link", - "options": "Project Type" + fieldname: "project_type", + label: __("Project Type"), + fieldtype: "Link", + options: "Project Type", }, { - "fieldname": "priority", - "label": __("Priority"), - "fieldtype": "Select", - "options": "\nLow\nMedium\nHigh" - } - ] + fieldname: "priority", + label: __("Priority"), + fieldtype: "Select", + options: "\nLow\nMedium\nHigh", + }, + ], }; diff --git a/erpnext/projects/report/project_wise_stock_tracking/project_wise_stock_tracking.js b/erpnext/projects/report/project_wise_stock_tracking/project_wise_stock_tracking.js index ccca26439d08..dcadcc0852e0 100644 --- a/erpnext/projects/report/project_wise_stock_tracking/project_wise_stock_tracking.js +++ b/erpnext/projects/report/project_wise_stock_tracking/project_wise_stock_tracking.js @@ -2,7 +2,5 @@ // For license information, please see license.txt frappe.query_reports["Project wise Stock Tracking"] = { - "filters": [ - - ] -} + filters: [], +}; diff --git a/erpnext/projects/web_form/tasks/tasks.js b/erpnext/projects/web_form/tasks/tasks.js index ffc5e984253b..8f56ebb353de 100644 --- a/erpnext/projects/web_form/tasks/tasks.js +++ b/erpnext/projects/web_form/tasks/tasks.js @@ -1,3 +1,3 @@ -frappe.ready(function() { +frappe.ready(function () { // bind events here -}) +}); diff --git a/erpnext/public/js/account_tree_grid.js b/erpnext/public/js/account_tree_grid.js index 413a5ee97193..6b4cdf1177a3 100644 --- a/erpnext/public/js/account_tree_grid.js +++ b/erpnext/public/js/account_tree_grid.js @@ -18,53 +18,96 @@ erpnext.AccountTreeGrid = class AccountTreeGrid extends frappe.views.TreeGridRep constructor(wrapper, title) { super({ title: title, - parent: $(wrapper).find('.layout-main'), + parent: $(wrapper).find(".layout-main"), page: wrapper.page, doctypes: ["Company", "Fiscal Year", "Account", "GL Entry", "Cost Center"], tree_grid: { show: true, parent_field: "parent_account", - formatter: function(item) { - return repl("\ - %(value)s", { + %(value)s", + { value: item.name, - }); - } + } + ); + }, }, }); this.filters = [ - {fieldtype: "Select", label: __("Company"), link:"Company", fieldname: "company", + { + fieldtype: "Select", + label: __("Company"), + link: "Company", + fieldname: "company", default_value: __("Select Company..."), - filter: function(val, item, opts, me) { + filter: function (val, item, opts, me) { if (item.company == val || val == opts.default_value) { return me.apply_zero_filter(val, item, opts, me); } return false; - }}, - {fieldtype: "Select", label: "Fiscal Year", link:"Fiscal Year", fieldname: "fiscal_year", - default_value: __("Select Fiscal Year...")}, - {fieldtype: "Date", label: __("From Date"), fieldname: "from_date"}, - {fieldtype: "Label", label: __("To")}, - {fieldtype: "Date", label: __("To Date"), fieldname: "to_date"} - ] + }, + }, + { + fieldtype: "Select", + label: "Fiscal Year", + link: "Fiscal Year", + fieldname: "fiscal_year", + default_value: __("Select Fiscal Year..."), + }, + { fieldtype: "Date", label: __("From Date"), fieldname: "from_date" }, + { fieldtype: "Label", label: __("To") }, + { fieldtype: "Date", label: __("To Date"), fieldname: "to_date" }, + ]; } setup_columns() { this.columns = [ - {id: "name", name: __("Account"), field: "name", width: 300, cssClass: "cell-title"}, - {id: "opening_dr", name: __("Opening (Dr)"), field: "opening_dr", width: 100, - formatter: this.currency_formatter}, - {id: "opening_cr", name: __("Opening (Cr)"), field: "opening_cr", width: 100, - formatter: this.currency_formatter}, - {id: "debit", name: __("Debit"), field: "debit", width: 100, - formatter: this.currency_formatter}, - {id: "credit", name: __("Credit"), field: "credit", width: 100, - formatter: this.currency_formatter}, - {id: "closing_dr", name: __("Closing (Dr)"), field: "closing_dr", width: 100, - formatter: this.currency_formatter}, - {id: "closing_cr", name: __("Closing (Cr)"), field: "closing_cr", width: 100, - formatter: this.currency_formatter} + { id: "name", name: __("Account"), field: "name", width: 300, cssClass: "cell-title" }, + { + id: "opening_dr", + name: __("Opening (Dr)"), + field: "opening_dr", + width: 100, + formatter: this.currency_formatter, + }, + { + id: "opening_cr", + name: __("Opening (Cr)"), + field: "opening_cr", + width: 100, + formatter: this.currency_formatter, + }, + { + id: "debit", + name: __("Debit"), + field: "debit", + width: 100, + formatter: this.currency_formatter, + }, + { + id: "credit", + name: __("Credit"), + field: "credit", + width: 100, + formatter: this.currency_formatter, + }, + { + id: "closing_dr", + name: __("Closing (Dr)"), + field: "closing_dr", + width: 100, + formatter: this.currency_formatter, + }, + { + id: "closing_cr", + name: __("Closing (Cr)"), + field: "closing_cr", + width: 100, + formatter: this.currency_formatter, + }, ]; } @@ -72,33 +115,33 @@ erpnext.AccountTreeGrid = class AccountTreeGrid extends frappe.views.TreeGridRep super.setup_filters(); var me = this; // default filters - this.filter_inputs.fiscal_year.change(function() { + this.filter_inputs.fiscal_year.change(function () { var fy = $(this).val(); - $.each(frappe.report_dump.data["Fiscal Year"], function(i, v) { - if (v.name==fy) { + $.each(frappe.report_dump.data["Fiscal Year"], function (i, v) { + if (v.name == fy) { me.filter_inputs.from_date.val(frappe.datetime.str_to_user(v.year_start_date)); me.filter_inputs.to_date.val(frappe.datetime.str_to_user(v.year_end_date)); } }); me.refresh(); }); - me.show_zero_check() - if(me.ignore_closing_entry) me.ignore_closing_entry(); + me.show_zero_check(); + if (me.ignore_closing_entry) me.ignore_closing_entry(); } prepare_data() { var me = this; - if(!this.primary_data) { + if (!this.primary_data) { // make accounts list me.data = []; me.parent_map = {}; me.item_by_name = {}; - $.each(frappe.report_dump.data["Account"], function(i, v) { + $.each(frappe.report_dump.data["Account"], function (i, v) { var d = copy_dict(v); me.data.push(d); me.item_by_name[d.name] = d; - if(d.parent_account) { + if (d.parent_account) { me.parent_map[d.name] = d.parent_account; } }); @@ -107,20 +150,19 @@ erpnext.AccountTreeGrid = class AccountTreeGrid extends frappe.views.TreeGridRep } me.data = [].concat(me.primary_data); - $.each(me.data, function(i, d) { + $.each(me.data, function (i, d) { me.init_account(d); }); this.set_indent(); this.prepare_balances(); - } init_account(d) { this.reset_item_values(d); } prepare_balances() { - var gl = frappe.report_dump.data['GL Entry']; + var gl = frappe.report_dump.data["GL Entry"]; var me = this; this.opening_date = frappe.datetime.user_to_obj(this.filter_inputs.from_date.val()); @@ -128,12 +170,11 @@ erpnext.AccountTreeGrid = class AccountTreeGrid extends frappe.views.TreeGridRep this.set_fiscal_year(); if (!this.fiscal_year) return; - $.each(this.data, function(i, v) { - v.opening_dr = v.opening_cr = v.debit - = v.credit = v.closing_dr = v.closing_cr = 0; + $.each(this.data, function (i, v) { + v.opening_dr = v.opening_cr = v.debit = v.credit = v.closing_dr = v.closing_cr = 0; }); - $.each(gl, function(i, v) { + $.each(gl, function (i, v) { var posting_date = frappe.datetime.str_to_obj(v.posting_date); var account = me.item_by_name[v.account]; me.update_balances(account, posting_date, v); @@ -144,13 +185,15 @@ erpnext.AccountTreeGrid = class AccountTreeGrid extends frappe.views.TreeGridRep update_balances(account, posting_date, v) { // opening if (posting_date < this.opening_date || v.is_opening === "Yes") { - if (account.report_type === "Profit and Loss" && - posting_date <= frappe.datetime.str_to_obj(this.fiscal_year[1])) { + if ( + account.report_type === "Profit and Loss" && + posting_date <= frappe.datetime.str_to_obj(this.fiscal_year[1]) + ) { // balance of previous fiscal_year should // not be part of opening of pl account balance } else { - var opening_bal = flt(account.opening_dr) - flt(account.opening_cr) + - flt(v.debit) - flt(v.credit); + var opening_bal = + flt(account.opening_dr) - flt(account.opening_cr) + flt(v.debit) - flt(v.credit); this.set_debit_or_credit(account, "opening", opening_bal); } } else if (this.opening_date <= posting_date && posting_date <= this.closing_date) { @@ -159,43 +202,47 @@ erpnext.AccountTreeGrid = class AccountTreeGrid extends frappe.views.TreeGridRep account.credit += flt(v.credit); } // closing - var closing_bal = flt(account.opening_dr) - flt(account.opening_cr) + - flt(account.debit) - flt(account.credit); + var closing_bal = + flt(account.opening_dr) - flt(account.opening_cr) + flt(account.debit) - flt(account.credit); this.set_debit_or_credit(account, "closing", closing_bal); } set_debit_or_credit(account, field, balance) { - if(balance > 0) { - account[field+"_dr"] = balance; - account[field+"_cr"] = 0; + if (balance > 0) { + account[field + "_dr"] = balance; + account[field + "_cr"] = 0; } else { - account[field+"_cr"] = Math.abs(balance); - account[field+"_dr"] = 0; + account[field + "_cr"] = Math.abs(balance); + account[field + "_dr"] = 0; } } update_groups() { // update groups - var me= this; - $.each(this.data, function(i, account) { + var me = this; + $.each(this.data, function (i, account) { // update groups - if((account.is_group == 0) || (account.rgt - account.lft == 1)) { + if (account.is_group == 0 || account.rgt - account.lft == 1) { var parent = me.parent_map[account.name]; - while(parent) { + while (parent) { var parent_account = me.item_by_name[parent]; - $.each(me.columns, function(c, col) { + $.each(me.columns, function (c, col) { if (col.formatter == me.currency_formatter) { - if(col.field=="opening_dr") { - var bal = flt(parent_account.opening_dr) - + if (col.field == "opening_dr") { + var bal = + flt(parent_account.opening_dr) - flt(parent_account.opening_cr) + - flt(account.opening_dr) - flt(account.opening_cr); + flt(account.opening_dr) - + flt(account.opening_cr); me.set_debit_or_credit(parent_account, "opening", bal); - } else if(col.field=="closing_dr") { - var bal = flt(parent_account.closing_dr) - + } else if (col.field == "closing_dr") { + var bal = + flt(parent_account.closing_dr) - flt(parent_account.closing_cr) + - flt(account.closing_dr) - flt(account.closing_cr); + flt(account.closing_dr) - + flt(account.closing_cr); me.set_debit_or_credit(parent_account, "closing", bal); - } else if(in_list(["debit", "credit"], col.field)) { - parent_account[col.field] = flt(parent_account[col.field]) + - flt(account[col.field]); + } else if (in_list(["debit", "credit"], col.field)) { + parent_account[col.field] = + flt(parent_account[col.field]) + flt(account[col.field]); } } }); @@ -213,9 +260,11 @@ erpnext.AccountTreeGrid = class AccountTreeGrid extends frappe.views.TreeGridRep this.fiscal_year = null; var me = this; - $.each(frappe.report_dump.data["Fiscal Year"], function(i, v) { - if (me.opening_date >= frappe.datetime.str_to_obj(v.year_start_date) && - me.closing_date <= frappe.datetime.str_to_obj(v.year_end_date)) { + $.each(frappe.report_dump.data["Fiscal Year"], function (i, v) { + if ( + me.opening_date >= frappe.datetime.str_to_obj(v.year_start_date) && + me.closing_date <= frappe.datetime.str_to_obj(v.year_end_date) + ) { me.fiscal_year = v; } }); @@ -231,7 +280,7 @@ erpnext.AccountTreeGrid = class AccountTreeGrid extends frappe.views.TreeGridRep account: account, company: this.company, from_date: this.from_date, - to_date: this.to_date + to_date: this.to_date, }; frappe.set_route("query-report", "General Ledger"); } diff --git a/erpnext/public/js/address.js b/erpnext/public/js/address.js index 57f7163bbb28..606e0b119fd3 100644 --- a/erpnext/public/js/address.js +++ b/erpnext/public/js/address.js @@ -2,24 +2,23 @@ // For license information, please see license.txt frappe.ui.form.on("Address", { - is_your_company_address: function(frm) { - frm.clear_table('links'); - if(frm.doc.is_your_company_address) { - frm.add_child('links', { - link_doctype: 'Company', - link_name: frappe.defaults.get_user_default('Company') + is_your_company_address: function (frm) { + frm.clear_table("links"); + if (frm.doc.is_your_company_address) { + frm.add_child("links", { + link_doctype: "Company", + link_name: frappe.defaults.get_user_default("Company"), }); - frm.set_query('link_doctype', 'links', () => { + frm.set_query("link_doctype", "links", () => { return { filters: { - name: 'Company' - } + name: "Company", + }, }; }); - frm.refresh_field('links'); + frm.refresh_field("links"); + } else { + frm.trigger("refresh"); } - else { - frm.trigger('refresh'); - } - } + }, }); diff --git a/erpnext/public/js/agriculture/ternary_plot.js b/erpnext/public/js/agriculture/ternary_plot.js index b06a1fd7c8cf..4fc1c4fc3f14 100644 --- a/erpnext/public/js/agriculture/ternary_plot.js +++ b/erpnext/public/js/agriculture/ternary_plot.js @@ -1,10 +1,10 @@ -frappe.provide('agriculture'); +frappe.provide("agriculture"); agriculture.TernaryPlot = class TernaryPlot { constructor(opts) { Object.assign(this, opts); - frappe.require('assets/frappe/js/lib/snap.svg-min.js', () => { + frappe.require("assets/frappe/js/lib/snap.svg-min.js", () => { this.make_svg(); this.init_snap(); this.init_config(); @@ -29,124 +29,170 @@ agriculture.TernaryPlot = class TernaryPlot { triangle_side: 300, spacing: 50, strokeWidth: 1, - stroke: frappe.ui.color.get('black') + stroke: frappe.ui.color.get("black"), }; this.config.scaling_factor = this.config.triangle_side / 100; let { triangle_side: t, spacing: s, scaling_factor: p } = this.config; this.coords = { sand: { - points: [ - s + t * Snap.cos(60), s, - s, s + t * Snap.cos(30), - s + t, s + t * Snap.cos(30) - ], - color: frappe.ui.color.get('peach') + points: [s + t * Snap.cos(60), s, s, s + t * Snap.cos(30), s + t, s + t * Snap.cos(30)], + color: frappe.ui.color.get("peach"), }, loamy_sand: { points: [ - s + 15 * p * Snap.cos(60), s + (100 - 15) * p * Snap.cos(30), - s + 10 * p * Snap.cos(60), s + (100 - 10) * p * Snap.cos(30), - s + (100 - 85) * p, s + t * Snap.cos(30), - s + (100 - 70) * p, s + t * Snap.cos(30) + s + 15 * p * Snap.cos(60), + s + (100 - 15) * p * Snap.cos(30), + s + 10 * p * Snap.cos(60), + s + (100 - 10) * p * Snap.cos(30), + s + (100 - 85) * p, + s + t * Snap.cos(30), + s + (100 - 70) * p, + s + t * Snap.cos(30), ], - color: frappe.ui.color.get('pink') + color: frappe.ui.color.get("pink"), }, sandy_loam: { points: [ - s + 20 * p * Snap.cos(60) + 27.5 * p, s + (100 - 20) * p * Snap.cos(30), - s + 20 * p * Snap.cos(60), s + (100 - 20) * p * Snap.cos(30), - s + 15 * p * Snap.cos(60), s + (100 - 15) * p * Snap.cos(30), - s + (100 - 75) * p, s + t * Snap.cos(30), - s + (100 - 50) * p, s + t * Snap.cos(30), - s + (100 - 50) * p + 7.5 * p * Snap.cos(60), s + t * Snap.cos(30) - 7.5 * p * Snap.cos(30), - s + (100 - 50) * p + 7.5 * p * Snap.cos(60) - 10 * p, s + t * Snap.cos(30) - 7.5 * p * Snap.cos(30) + s + 20 * p * Snap.cos(60) + 27.5 * p, + s + (100 - 20) * p * Snap.cos(30), + s + 20 * p * Snap.cos(60), + s + (100 - 20) * p * Snap.cos(30), + s + 15 * p * Snap.cos(60), + s + (100 - 15) * p * Snap.cos(30), + s + (100 - 75) * p, + s + t * Snap.cos(30), + s + (100 - 50) * p, + s + t * Snap.cos(30), + s + (100 - 50) * p + 7.5 * p * Snap.cos(60), + s + t * Snap.cos(30) - 7.5 * p * Snap.cos(30), + s + (100 - 50) * p + 7.5 * p * Snap.cos(60) - 10 * p, + s + t * Snap.cos(30) - 7.5 * p * Snap.cos(30), ], - color: frappe.ui.color.get('pink', 'light') + color: frappe.ui.color.get("pink", "light"), }, loam: { points: [ - s + (100 - 50) * p + 27.5 * p * Snap.cos(60), s + t * Snap.cos(30) - 27.5 * p * Snap.cos(30), - s + (100 - 50) * p + 27.5 * p * Snap.cos(60) - 22.5 * p, s + t * Snap.cos(30) - 27.5 * p * Snap.cos(30), - s + 20 * p * Snap.cos(60) + 27.5 * p, s + (100 - 20) * p * Snap.cos(30), - s + (100 - 50) * p + 7.5 * p * Snap.cos(60) - 10 * p, s + t * Snap.cos(30) - 7.5 * p * Snap.cos(30), - s + (100 - 50) * p + 7.5 * p * Snap.cos(60), s + t * Snap.cos(30) - 7.5 * p * Snap.cos(30) + s + (100 - 50) * p + 27.5 * p * Snap.cos(60), + s + t * Snap.cos(30) - 27.5 * p * Snap.cos(30), + s + (100 - 50) * p + 27.5 * p * Snap.cos(60) - 22.5 * p, + s + t * Snap.cos(30) - 27.5 * p * Snap.cos(30), + s + 20 * p * Snap.cos(60) + 27.5 * p, + s + (100 - 20) * p * Snap.cos(30), + s + (100 - 50) * p + 7.5 * p * Snap.cos(60) - 10 * p, + s + t * Snap.cos(30) - 7.5 * p * Snap.cos(30), + s + (100 - 50) * p + 7.5 * p * Snap.cos(60), + s + t * Snap.cos(30) - 7.5 * p * Snap.cos(30), ], - color: frappe.ui.color.get('brown') + color: frappe.ui.color.get("brown"), }, silt_loam: { points: [ - s + t - 27.5 * p * Snap.cos(60), s + 72.5 * p * Snap.cos(30), - s + (100 - 50) * p + 27.5 * p * Snap.cos(60), s + t * Snap.cos(30) - 27.5 * p * Snap.cos(30), - s + (100 - 50) * p, s + t * Snap.cos(30), - s + (100 - 20) * p, s + t * Snap.cos(30), - s + (100 - 20) * p + 12.5 * p * Snap.cos(60), s + 90 * p * Snap.cos(30), - s + t - 12.5 * p * Snap.cos(60), s + (100 - 12.5) * p * Snap.cos(30) + s + t - 27.5 * p * Snap.cos(60), + s + 72.5 * p * Snap.cos(30), + s + (100 - 50) * p + 27.5 * p * Snap.cos(60), + s + t * Snap.cos(30) - 27.5 * p * Snap.cos(30), + s + (100 - 50) * p, + s + t * Snap.cos(30), + s + (100 - 20) * p, + s + t * Snap.cos(30), + s + (100 - 20) * p + 12.5 * p * Snap.cos(60), + s + 90 * p * Snap.cos(30), + s + t - 12.5 * p * Snap.cos(60), + s + (100 - 12.5) * p * Snap.cos(30), ], - color: frappe.ui.color.get('green', 'dark') + color: frappe.ui.color.get("green", "dark"), }, silt: { points: [ - s + t - 12.5 * p * Snap.cos(60), s + (100 - 12.5) * p * Snap.cos(30), - s + (100 - 20) * p + 12.5 * p * Snap.cos(60), s + 90 * p * Snap.cos(30), - s + (100 - 20) * p, s + t * Snap.cos(30), - s + t, s + t * Snap.cos(30) + s + t - 12.5 * p * Snap.cos(60), + s + (100 - 12.5) * p * Snap.cos(30), + s + (100 - 20) * p + 12.5 * p * Snap.cos(60), + s + 90 * p * Snap.cos(30), + s + (100 - 20) * p, + s + t * Snap.cos(30), + s + t, + s + t * Snap.cos(30), ], - color: frappe.ui.color.get('green') + color: frappe.ui.color.get("green"), }, silty_clay_loam: { points: [ - s + t - 40 * p * Snap.cos(60), s + 60 * p * Snap.cos(30), - s + t - 40 * p * Snap.cos(60) - 20 * p, s + 60 * p * Snap.cos(30), - s + t - 27.5 * p * Snap.cos(60) - 20 * p, s + 72.5 * p * Snap.cos(30), - s + t - 27.5 * p * Snap.cos(60), s + 72.5 * p * Snap.cos(30) + s + t - 40 * p * Snap.cos(60), + s + 60 * p * Snap.cos(30), + s + t - 40 * p * Snap.cos(60) - 20 * p, + s + 60 * p * Snap.cos(30), + s + t - 27.5 * p * Snap.cos(60) - 20 * p, + s + 72.5 * p * Snap.cos(30), + s + t - 27.5 * p * Snap.cos(60), + s + 72.5 * p * Snap.cos(30), ], - color: frappe.ui.color.get('cyan', 'dark') + color: frappe.ui.color.get("cyan", "dark"), }, silty_clay: { points: [ - s + t - 60 * p * Snap.cos(60), s + 40 * p * Snap.cos(30), - s + t - 40 * p * Snap.cos(60) - 20 * p, s + 60 * p * Snap.cos(30), - s + t - 40 * p * Snap.cos(60), s + 60 * p * Snap.cos(30) + s + t - 60 * p * Snap.cos(60), + s + 40 * p * Snap.cos(30), + s + t - 40 * p * Snap.cos(60) - 20 * p, + s + 60 * p * Snap.cos(30), + s + t - 40 * p * Snap.cos(60), + s + 60 * p * Snap.cos(30), ], - color: frappe.ui.color.get('cyan') + color: frappe.ui.color.get("cyan"), }, clay_loam: { points: [ - s + t - 40 * p * Snap.cos(60) - 20 * p, s + 60 * p * Snap.cos(30), - s + t - 40 * p * Snap.cos(60) - 45 * p, s + 60 * p * Snap.cos(30), - s + t - 27.5 * p * Snap.cos(60) - 45 * p, s + 72.5 * p * Snap.cos(30), - s + t - 27.5 * p * Snap.cos(60) - 20 * p, s + 72.5 * p * Snap.cos(30) + s + t - 40 * p * Snap.cos(60) - 20 * p, + s + 60 * p * Snap.cos(30), + s + t - 40 * p * Snap.cos(60) - 45 * p, + s + 60 * p * Snap.cos(30), + s + t - 27.5 * p * Snap.cos(60) - 45 * p, + s + 72.5 * p * Snap.cos(30), + s + t - 27.5 * p * Snap.cos(60) - 20 * p, + s + 72.5 * p * Snap.cos(30), ], - color: frappe.ui.color.get('green', 'light') + color: frappe.ui.color.get("green", "light"), }, sandy_clay_loam: { points: [ - s + 35 * p * Snap.cos(60) + 20 * p, s + (100 - 35) * p * Snap.cos(30), - s + 35 * p * Snap.cos(60), s + (100 - 35) * p * Snap.cos(30), - s + 20 * p * Snap.cos(60), s + (100 - 20) * p * Snap.cos(30), - s + 20 * p * Snap.cos(60) + 27.5 * p, s + (100 - 20) * p * Snap.cos(30), - s + t - 27.5 * p * Snap.cos(60) - 45 * p, s + 72.5 * p * Snap.cos(30) + s + 35 * p * Snap.cos(60) + 20 * p, + s + (100 - 35) * p * Snap.cos(30), + s + 35 * p * Snap.cos(60), + s + (100 - 35) * p * Snap.cos(30), + s + 20 * p * Snap.cos(60), + s + (100 - 20) * p * Snap.cos(30), + s + 20 * p * Snap.cos(60) + 27.5 * p, + s + (100 - 20) * p * Snap.cos(30), + s + t - 27.5 * p * Snap.cos(60) - 45 * p, + s + 72.5 * p * Snap.cos(30), ], - color: frappe.ui.color.get('pink', 'dark') + color: frappe.ui.color.get("pink", "dark"), }, sandy_clay: { points: [ - s + 55 * p * Snap.cos(60), s + (100 - 55) * p * Snap.cos(30), - s + 35 * p * Snap.cos(60), s + (100 - 35) * p * Snap.cos(30), - s + 35 * p * Snap.cos(60) + 20 * p, s + (100 - 35) * p * Snap.cos(30) + s + 55 * p * Snap.cos(60), + s + (100 - 55) * p * Snap.cos(30), + s + 35 * p * Snap.cos(60), + s + (100 - 35) * p * Snap.cos(30), + s + 35 * p * Snap.cos(60) + 20 * p, + s + (100 - 35) * p * Snap.cos(30), ], - color: frappe.ui.color.get('red') + color: frappe.ui.color.get("red"), }, clay: { points: [ - s + t * Snap.cos(60), s, - s + 55 * p * Snap.cos(60), s + (100 - 55) * p * Snap.cos(30), - s + t - 40 * p * Snap.cos(60) - 45 * p, s + 60 * p * Snap.cos(30), - s + t - 40 * p * Snap.cos(60) - 20 * p, s + 60 * p * Snap.cos(30), - s + t - 60 * p * Snap.cos(60), s + 40 * p * Snap.cos(30) + s + t * Snap.cos(60), + s, + s + 55 * p * Snap.cos(60), + s + (100 - 55) * p * Snap.cos(30), + s + t - 40 * p * Snap.cos(60) - 45 * p, + s + 60 * p * Snap.cos(30), + s + t - 40 * p * Snap.cos(60) - 20 * p, + s + 60 * p * Snap.cos(30), + s + t - 60 * p * Snap.cos(60), + s + 40 * p * Snap.cos(30), ], - color: frappe.ui.color.get('yellow') + color: frappe.ui.color.get("yellow"), }, }; } @@ -164,7 +210,7 @@ agriculture.TernaryPlot = class TernaryPlot { this.paper.polygon(this.get_coords(soil_type)).attr({ fill: this.get_color(soil_type), stroke: this.config.stroke, - strokeWidth: this.config.strokeWidth + strokeWidth: this.config.strokeWidth, }); } } @@ -172,18 +218,18 @@ agriculture.TernaryPlot = class TernaryPlot { make_plot_marking() { let { triangle_side: t, spacing: s, scaling_factor: p } = this.config; - let clay = this.paper.text(t * Snap.cos(60) / 2, s + t * Snap.cos(30) / 2, __("Clay")).attr({ - fill: frappe.ui.color.get('black') + let clay = this.paper.text((t * Snap.cos(60)) / 2, s + (t * Snap.cos(30)) / 2, __("Clay")).attr({ + fill: frappe.ui.color.get("black"), }); clay.transform("r300"); - let silt = this.paper.text(t, s + t * Snap.cos(30) / 2, __("Silt")).attr({ - fill: frappe.ui.color.get('black') + let silt = this.paper.text(t, s + (t * Snap.cos(30)) / 2, __("Silt")).attr({ + fill: frappe.ui.color.get("black"), }); silt.transform("r60"); let sand = this.paper.text(35 + t * Snap.cos(60), 90 + t * Snap.cos(30), __("Sand")).attr({ - fill: frappe.ui.color.get('black') + fill: frappe.ui.color.get("black"), }); sand.transform("r0"); } @@ -194,25 +240,25 @@ agriculture.TernaryPlot = class TernaryPlot { let offset = 0; let exec_once = true; for (let soil_type in this.coords) { - if (index > 6 && exec_once){ + if (index > 6 && exec_once) { offset = 300; index = 1; exec_once = false; } - let rect = this.paper.rect(0+offset, 0+index*20, 100, 19, 5, 5).attr({ + let rect = this.paper.rect(0 + offset, 0 + index * 20, 100, 19, 5, 5).attr({ fill: this.get_color(soil_type), - stroke: frappe.ui.color.get('black') + stroke: frappe.ui.color.get("black"), }); - let text = this.paper.text(5+offset, 16+index*20, soil_type).attr({ - fill: frappe.ui.color.get('black'), - 'font-size': 12 + let text = this.paper.text(5 + offset, 16 + index * 20, soil_type).attr({ + fill: frappe.ui.color.get("black"), + "font-size": 12, }); index++; } } - mark_blip({clay, sand, silt} = this) { - if (clay + sand + silt != 0){ + mark_blip({ clay, sand, silt } = this) { + if (clay + sand + silt != 0) { let { triangle_side: t, spacing: s, scaling_factor: p } = this.config; let x_blip = s + clay * p * Snap.cos(60) + silt * p; @@ -220,13 +266,12 @@ agriculture.TernaryPlot = class TernaryPlot { this.blip = this.paper.circle(x_blip, y_blip, 4).attr({ fill: frappe.ui.color.get("orange"), stroke: frappe.ui.color.get("orange"), - strokeWidth: 2 + strokeWidth: 2, }); } } remove_blip() { - if (typeof this.blip !== 'undefined') - this.blip.remove(); + if (typeof this.blip !== "undefined") this.blip.remove(); } }; diff --git a/erpnext/public/js/bank_reconciliation_tool/data_table_manager.js b/erpnext/public/js/bank_reconciliation_tool/data_table_manager.js index 0cda93880fa5..a88d00c5d353 100644 --- a/erpnext/public/js/bank_reconciliation_tool/data_table_manager.js +++ b/erpnext/public/js/bank_reconciliation_tool/data_table_manager.js @@ -18,12 +18,11 @@ erpnext.accounts.bank_reconciliation.DataTableManager = class DataTableManager { make_dt() { var me = this; frappe.call({ - method: - "erpnext.accounts.doctype.bank_reconciliation_tool.bank_reconciliation_tool.get_bank_transactions", + method: "erpnext.accounts.doctype.bank_reconciliation_tool.bank_reconciliation_tool.get_bank_transactions", args: { bank_account: this.bank_account, from_date: this.bank_statement_from_date, - to_date: this.bank_statement_to_date + to_date: this.bank_statement_to_date, }, callback: function (response) { me.format_data(response.message); @@ -62,18 +61,14 @@ erpnext.accounts.bank_reconciliation.DataTableManager = class DataTableManager { editable: false, width: 100, format: (value) => - "" + - format_currency(value, this.currency) + - "", + "" + format_currency(value, this.currency) + "", }, { name: __("Withdrawal"), editable: false, width: 100, format: (value) => - "" + - format_currency(value, this.currency) + - "", + "" + format_currency(value, this.currency) + "", }, { name: __("Unallocated Amount"), @@ -139,14 +134,8 @@ erpnext.accounts.bank_reconciliation.DataTableManager = class DataTableManager { checkboxColumn: false, inlineFilters: true, }; - this.datatable = new frappe.DataTable( - this.$reconciliation_tool_dt.get(0), - datatable_options - ); - $(`.${this.datatable.style.scopeClass} .dt-scrollable`).css( - "max-height", - "calc(100vh - 400px)" - ); + this.datatable = new frappe.DataTable(this.$reconciliation_tool_dt.get(0), datatable_options); + $(`.${this.datatable.style.scopeClass} .dt-scrollable`).css("max-height", "calc(100vh - 400px)"); if (this.transactions.length > 0) { this.$reconciliation_tool_dt.show(); @@ -159,27 +148,18 @@ erpnext.accounts.bank_reconciliation.DataTableManager = class DataTableManager { set_listeners() { var me = this; - $(`.${this.datatable.style.scopeClass} .dt-scrollable`).on( - "click", - `.btn`, - function () { - me.dialog_manager.show_dialog( - $(this).attr("data-name"), - (bank_transaction) => me.update_dt_cards(bank_transaction) - ); - return true; - } - ); + $(`.${this.datatable.style.scopeClass} .dt-scrollable`).on("click", `.btn`, function () { + me.dialog_manager.show_dialog($(this).attr("data-name"), (bank_transaction) => + me.update_dt_cards(bank_transaction) + ); + return true; + }); } update_dt_cards(bank_transaction) { - const transaction_index = this.transaction_dt_map[ - bank_transaction.name - ]; + const transaction_index = this.transaction_dt_map[bank_transaction.name]; if (bank_transaction.unallocated_amount > 0) { - this.transactions[transaction_index] = this.format_row( - bank_transaction - ); + this.transactions[transaction_index] = this.format_row(bank_transaction); } else { this.transactions.splice(transaction_index, 1); for (const [k, v] of Object.entries(this.transaction_dt_map)) { @@ -195,14 +175,9 @@ erpnext.accounts.bank_reconciliation.DataTableManager = class DataTableManager { // this.make_dt(); this.get_cleared_balance().then(() => { - this.cards_manager.$cards[1].set_value( - format_currency(this.cleared_balance), - this.currency - ); + this.cards_manager.$cards[1].set_value(format_currency(this.cleared_balance), this.currency); this.cards_manager.$cards[2].set_value( - format_currency( - this.bank_statement_closing_balance - this.cleared_balance - ), + format_currency(this.bank_statement_closing_balance - this.cleared_balance), this.currency ); this.cards_manager.$cards[2].set_value_color( @@ -216,14 +191,12 @@ erpnext.accounts.bank_reconciliation.DataTableManager = class DataTableManager { get_cleared_balance() { if (this.bank_account && this.bank_statement_to_date) { return frappe.call({ - method: - "erpnext.accounts.doctype.bank_reconciliation_tool.bank_reconciliation_tool.get_account_balance", + method: "erpnext.accounts.doctype.bank_reconciliation_tool.bank_reconciliation_tool.get_account_balance", args: { bank_account: this.bank_account, till_date: this.bank_statement_to_date, }, - callback: (response) => - (this.cleared_balance = response.message), + callback: (response) => (this.cleared_balance = response.message), }); } } diff --git a/erpnext/public/js/bank_reconciliation_tool/dialog_manager.js b/erpnext/public/js/bank_reconciliation_tool/dialog_manager.js index ddc105305816..5cab0efa0e1c 100644 --- a/erpnext/public/js/bank_reconciliation_tool/dialog_manager.js +++ b/erpnext/public/js/bank_reconciliation_tool/dialog_manager.js @@ -1,7 +1,15 @@ frappe.provide("erpnext.accounts.bank_reconciliation"); erpnext.accounts.bank_reconciliation.DialogManager = class DialogManager { - constructor(company, bank_account, bank_statement_from_date, bank_statement_to_date, filter_by_reference_date, from_reference_date, to_reference_date) { + constructor( + company, + bank_account, + bank_statement_from_date, + bank_statement_to_date, + filter_by_reference_date, + from_reference_date, + to_reference_date + ) { this.bank_account = bank_account; this.company = company; this.make_dialog(); @@ -61,22 +69,20 @@ erpnext.accounts.bank_reconciliation.DialogManager = class DialogManager { get_linked_vouchers(document_types) { frappe.call({ - method: - "erpnext.accounts.doctype.bank_reconciliation_tool.bank_reconciliation_tool.get_linked_payments", + method: "erpnext.accounts.doctype.bank_reconciliation_tool.bank_reconciliation_tool.get_linked_payments", args: { bank_transaction_name: this.bank_transaction_name, document_types: document_types, from_date: this.bank_statement_from_date, to_date: this.bank_statement_to_date, filter_by_reference_date: this.filter_by_reference_date, - from_reference_date:this.from_reference_date, - to_reference_date:this.to_reference_date + from_reference_date: this.from_reference_date, + to_reference_date: this.to_reference_date, }, callback: (result) => { const data = result.message; - if (data && data.length > 0) { const proposals_wrapper = this.dialog.fields_dict.payment_proposals.$wrapper; proposals_wrapper.show(); @@ -99,7 +105,6 @@ erpnext.accounts.bank_reconciliation.DialogManager = class DialogManager { const proposals_wrapper = this.dialog.fields_dict.payment_proposals.$wrapper; proposals_wrapper.hide(); this.dialog.fields_dict.no_matching_vouchers.$wrapper.show(); - } this.dialog.show(); }, @@ -118,7 +123,7 @@ erpnext.accounts.bank_reconciliation.DialogManager = class DialogManager { editable: false, width: 1, format: (value, row) => { - return frappe.form.formatters.Link(value, {options: row[2].content}); + return frappe.form.formatters.Link(value, { options: row[2].content }); }, }, { @@ -153,10 +158,7 @@ erpnext.accounts.bank_reconciliation.DialogManager = class DialogManager { checkboxColumn: true, inlineFilters: true, }; - this.datatable = new frappe.DataTable( - proposals_wrapper.get(0), - datatable_options - ); + this.datatable = new frappe.DataTable(proposals_wrapper.get(0), datatable_options); } else { this.datatable.refresh(this.data, this.columns); this.datatable.rowmanager.checkMap = []; @@ -218,10 +220,9 @@ erpnext.accounts.bank_reconciliation.DialogManager = class DialogManager { title: __("Reconcile the Bank Transaction"), fields: fields, size: "large", - primary_action: (values) => - this.reconciliation_dialog_primary_action(values), + primary_action: (values) => this.reconciliation_dialog_primary_action(values), }); - } + }, }); } @@ -256,7 +257,9 @@ erpnext.accounts.bank_reconciliation.DialogManager = class DialogManager { { fieldtype: "HTML", fieldname: "no_matching_vouchers", - options: __("
    {0}
    ", [__("No Matching Vouchers Found")]) + options: __('
    {0}
    ', [ + __("No Matching Vouchers Found"), + ]), }, { fieldtype: "Section Break", @@ -300,8 +303,7 @@ erpnext.accounts.bank_reconciliation.DialogManager = class DialogManager { click: () => { this.edit_in_full_page(); }, - depends_on: - "eval:doc.action=='Create Voucher'", + depends_on: "eval:doc.action=='Create Voucher'", }, { fieldname: "column_break_7", @@ -314,8 +316,7 @@ erpnext.accounts.bank_reconciliation.DialogManager = class DialogManager { label: "Journal Entry Type", options: "Journal Entry\nInter Company Journal Entry\nBank Entry\nCash Entry\nCredit Card Entry\nDebit Note\nCredit Note\nContra Entry\nExcise Entry\nWrite Off Entry\nOpening Entry\nDepreciation Entry\nExchange Rate Revaluation\nDeferred Revenue\nDeferred Expense", - depends_on: - "eval:doc.action=='Create Voucher' && doc.document_type=='Journal Entry'", + depends_on: "eval:doc.action=='Create Voucher' && doc.document_type=='Journal Entry'", mandatory_depends_on: "eval:doc.action=='Create Voucher' && doc.document_type=='Journal Entry'", }, @@ -324,8 +325,7 @@ erpnext.accounts.bank_reconciliation.DialogManager = class DialogManager { fieldtype: "Link", label: "Account", options: "Account", - depends_on: - "eval:doc.action=='Create Voucher' && doc.document_type=='Journal Entry'", + depends_on: "eval:doc.action=='Create Voucher' && doc.document_type=='Journal Entry'", mandatory_depends_on: "eval:doc.action=='Create Voucher' && doc.document_type=='Journal Entry'", get_query: () => { @@ -343,14 +343,11 @@ erpnext.accounts.bank_reconciliation.DialogManager = class DialogManager { label: "Party Type", options: "DocType", mandatory_depends_on: - "eval:doc.action=='Create Voucher' && doc.document_type=='Payment Entry'", + "eval:doc.action=='Create Voucher' && doc.document_type=='Payment Entry'", get_query: function () { return { filters: { - name: [ - "in", - Object.keys(frappe.boot.party_account_types), - ], + name: ["in", Object.keys(frappe.boot.party_account_types)], }, }; }, @@ -368,16 +365,14 @@ erpnext.accounts.bank_reconciliation.DialogManager = class DialogManager { fieldtype: "Link", label: "Project", options: "Project", - depends_on: - "eval:doc.action=='Create Voucher' && doc.document_type=='Payment Entry'", + depends_on: "eval:doc.action=='Create Voucher' && doc.document_type=='Payment Entry'", }, { fieldname: "cost_center", fieldtype: "Link", label: "Cost Center", options: "Cost Center", - depends_on: - "eval:doc.action=='Create Voucher' && doc.document_type=='Payment Entry'", + depends_on: "eval:doc.action=='Create Voucher' && doc.document_type=='Payment Entry'", }, { fieldtype: "Section Break", @@ -436,7 +431,7 @@ erpnext.accounts.bank_reconciliation.DialogManager = class DialogManager { options: "Currency", read_only: 1, hidden: 1, - } + }, ]; } @@ -458,18 +453,11 @@ erpnext.accounts.bank_reconciliation.DialogManager = class DialogManager { reconciliation_dialog_primary_action(values) { if (values.action == "Match Against Voucher") this.match(values); - if ( - values.action == "Create Voucher" && - values.document_type == "Payment Entry" - ) + if (values.action == "Create Voucher" && values.document_type == "Payment Entry") this.add_payment_entry(values); - if ( - values.action == "Create Voucher" && - values.document_type == "Journal Entry" - ) + if (values.action == "Create Voucher" && values.document_type == "Journal Entry") this.add_journal_entry(values); - else if (values.action == "Update Bank Transaction") - this.update_transaction(values); + else if (values.action == "Update Bank Transaction") this.update_transaction(values); } match() { @@ -487,8 +475,7 @@ erpnext.accounts.bank_reconciliation.DialogManager = class DialogManager { }); }); frappe.call({ - method: - "erpnext.accounts.doctype.bank_reconciliation_tool.bank_reconciliation_tool.reconcile_vouchers", + method: "erpnext.accounts.doctype.bank_reconciliation_tool.bank_reconciliation_tool.reconcile_vouchers", args: { bank_transaction_name: this.bank_transaction.name, vouchers: vouchers, @@ -504,8 +491,7 @@ erpnext.accounts.bank_reconciliation.DialogManager = class DialogManager { add_payment_entry(values) { frappe.call({ - method: - "erpnext.accounts.doctype.bank_reconciliation_tool.bank_reconciliation_tool.create_payment_entry_bts", + method: "erpnext.accounts.doctype.bank_reconciliation_tool.bank_reconciliation_tool.create_payment_entry_bts", args: { bank_transaction_name: this.bank_transaction.name, reference_number: values.reference_number, @@ -518,7 +504,9 @@ erpnext.accounts.bank_reconciliation.DialogManager = class DialogManager { cost_center: values.cost_center, }, callback: (response) => { - const alert_string = __("Bank Transaction {0} added as Payment Entry", [this.bank_transaction.name]); + const alert_string = __("Bank Transaction {0} added as Payment Entry", [ + this.bank_transaction.name, + ]); frappe.show_alert(alert_string); this.update_dt_cards(response.message); this.dialog.hide(); @@ -528,8 +516,7 @@ erpnext.accounts.bank_reconciliation.DialogManager = class DialogManager { add_journal_entry(values) { frappe.call({ - method: - "erpnext.accounts.doctype.bank_reconciliation_tool.bank_reconciliation_tool.create_journal_entry_bts", + method: "erpnext.accounts.doctype.bank_reconciliation_tool.bank_reconciliation_tool.create_journal_entry_bts", args: { bank_transaction_name: this.bank_transaction.name, reference_number: values.reference_number, @@ -542,7 +529,9 @@ erpnext.accounts.bank_reconciliation.DialogManager = class DialogManager { second_account: values.second_account, }, callback: (response) => { - const alert_string = __("Bank Transaction {0} added as Journal Entry", [this.bank_transaction.name]); + const alert_string = __("Bank Transaction {0} added as Journal Entry", [ + this.bank_transaction.name, + ]); frappe.show_alert(alert_string); this.update_dt_cards(response.message); this.dialog.hide(); @@ -552,8 +541,7 @@ erpnext.accounts.bank_reconciliation.DialogManager = class DialogManager { update_transaction(values) { frappe.call({ - method: - "erpnext.accounts.doctype.bank_reconciliation_tool.bank_reconciliation_tool.update_bank_transaction", + method: "erpnext.accounts.doctype.bank_reconciliation_tool.bank_reconciliation_tool.update_bank_transaction", args: { bank_transaction_name: this.bank_transaction.name, reference_number: values.reference_number, @@ -573,8 +561,7 @@ erpnext.accounts.bank_reconciliation.DialogManager = class DialogManager { const values = this.dialog.get_values(true); if (values.document_type == "Payment Entry") { frappe.call({ - method: - "erpnext.accounts.doctype.bank_reconciliation_tool.bank_reconciliation_tool.create_payment_entry_bts", + method: "erpnext.accounts.doctype.bank_reconciliation_tool.bank_reconciliation_tool.create_payment_entry_bts", args: { bank_transaction_name: this.bank_transaction.name, reference_number: values.reference_number, @@ -585,7 +572,7 @@ erpnext.accounts.bank_reconciliation.DialogManager = class DialogManager { mode_of_payment: values.mode_of_payment, project: values.project, cost_center: values.cost_center, - allow_edit: true + allow_edit: true, }, callback: (r) => { const doc = frappe.model.sync(r.message); @@ -594,8 +581,7 @@ erpnext.accounts.bank_reconciliation.DialogManager = class DialogManager { }); } else { frappe.call({ - method: - "erpnext.accounts.doctype.bank_reconciliation_tool.bank_reconciliation_tool.create_journal_entry_bts", + method: "erpnext.accounts.doctype.bank_reconciliation_tool.bank_reconciliation_tool.create_journal_entry_bts", args: { bank_transaction_name: this.bank_transaction.name, reference_number: values.reference_number, @@ -606,7 +592,7 @@ erpnext.accounts.bank_reconciliation.DialogManager = class DialogManager { mode_of_payment: values.mode_of_payment, entry_type: values.journal_entry_type, second_account: values.second_account, - allow_edit: true + allow_edit: true, }, callback: (r) => { var doc = frappe.model.sync(r.message); @@ -615,5 +601,4 @@ erpnext.accounts.bank_reconciliation.DialogManager = class DialogManager { }); } } - }; diff --git a/erpnext/public/js/bank_reconciliation_tool/number_card.js b/erpnext/public/js/bank_reconciliation_tool/number_card.js index 7e1b2690a806..d39884c381ef 100644 --- a/erpnext/public/js/bank_reconciliation_tool/number_card.js +++ b/erpnext/public/js/bank_reconciliation_tool/number_card.js @@ -26,8 +26,7 @@ erpnext.accounts.bank_reconciliation.NumberCardManager = class NumberCardManager currency: this.currency, }, { - value: - this.bank_statement_closing_balance - this.cleared_balance, + value: this.bank_statement_closing_balance - this.cleared_balance, label: __("Difference"), datatype: "Currency", currency: this.currency, @@ -41,11 +40,9 @@ erpnext.accounts.bank_reconciliation.NumberCardManager = class NumberCardManager number_card.$card.appendTo(this.$summary); }); this.$cards[2].set_value_color( - this.bank_statement_closing_balance - this.cleared_balance == 0 - ? "text-success" - : "text-danger" + this.bank_statement_closing_balance - this.cleared_balance == 0 ? "text-success" : "text-danger" ); - this.$summary.css({"border-bottom": "0px", "margin-left": "0px", "margin-right": "0px"}); + this.$summary.css({ "border-bottom": "0px", "margin-left": "0px", "margin-right": "0px" }); this.$summary.show(); } }; @@ -60,16 +57,10 @@ erpnext.accounts.NumberCard = class NumberCard { } set_value_color(color) { - this.$card - .find("div") - .removeClass("text-danger text-success") - .addClass(`${color}`); + this.$card.find("div").removeClass("text-danger text-success").addClass(`${color}`); } set_indicator(color) { - this.$card - .find("span") - .removeClass("indicator red green") - .addClass(`indicator ${color}`); + this.$card.find("span").removeClass("indicator red green").addClass(`indicator ${color}`); } }; diff --git a/erpnext/public/js/bulk_transaction_processing.js b/erpnext/public/js/bulk_transaction_processing.js index 101f50c64aaf..f360bf5cd2c7 100644 --- a/erpnext/public/js/bulk_transaction_processing.js +++ b/erpnext/public/js/bulk_transaction_processing.js @@ -1,30 +1,33 @@ frappe.provide("erpnext.bulk_transaction_processing"); $.extend(erpnext.bulk_transaction_processing, { - create: function(listview, from_doctype, to_doctype) { + create: function (listview, from_doctype, to_doctype) { let checked_items = listview.get_checked_items(); const doc_name = []; - checked_items.forEach((Item)=> { + checked_items.forEach((Item) => { if (Item.docstatus == 0) { doc_name.push(Item.name); } }); let count_of_rows = checked_items.length; - frappe.confirm(__("Create {0} {1} ?", [count_of_rows, to_doctype]), ()=>{ + frappe.confirm(__("Create {0} {1} ?", [count_of_rows, to_doctype]), () => { if (doc_name.length == 0) { - frappe.call({ - method: "erpnext.utilities.bulk_transaction.transaction_processing", - args: {data: checked_items, from_doctype: from_doctype, to_doctype: to_doctype} - }).then(()=> { - - }); + frappe + .call({ + method: "erpnext.utilities.bulk_transaction.transaction_processing", + args: { data: checked_items, from_doctype: from_doctype, to_doctype: to_doctype }, + }) + .then(() => {}); if (count_of_rows > 10) { - frappe.show_alert("Starting a background job to create {0} {1}", [count_of_rows, to_doctype]); + frappe.show_alert("Starting a background job to create {0} {1}", [ + count_of_rows, + to_doctype, + ]); } } else { frappe.msgprint(__("Selected document must be in submitted state")); } }); - } -}); \ No newline at end of file + }, +}); diff --git a/erpnext/public/js/call_popup/call_popup.js b/erpnext/public/js/call_popup/call_popup.js index 2dbe999e05b9..7155c799ddb3 100644 --- a/erpnext/public/js/call_popup/call_popup.js +++ b/erpnext/public/js/call_popup/call_popup.js @@ -7,17 +7,17 @@ class CallPopup { } make() { - frappe.utils.play_sound('incoming-call'); + frappe.utils.play_sound("incoming-call"); this.dialog = new frappe.ui.Dialog({ - 'static': true, - 'minimizable': true + static: true, + minimizable: true, }); this.dialog.get_close_btn().show(); this.setup_dialog(); this.set_call_status(); frappe.utils.bind_actions_with_object(this.dialog.$body, this); - this.dialog.$wrapper.addClass('call-popup'); - this.dialog.get_close_btn().unbind('click').click(this.close_modal.bind(this)); + this.dialog.$wrapper.addClass("call-popup"); + this.dialog.get_close_btn().unbind("click").click(this.close_modal.bind(this)); this.dialog.show(); } @@ -26,28 +26,28 @@ class CallPopup { this.dialog.$body.empty().append(this.caller_info); } - set_indicator(color, blink=false) { - let classes = `indicator ${color} ${blink ? 'blink': ''}`; - this.dialog.header.find('.indicator').attr('class', classes); + set_indicator(color, blink = false) { + let classes = `indicator ${color} ${blink ? "blink" : ""}`; + this.dialog.header.find(".indicator").attr("class", classes); } set_call_status(call_status) { - let title = ''; + let title = ""; call_status = call_status || this.call_log.status; - if (['Ringing'].includes(call_status) || !call_status) { - title = __('Incoming call from {0}', [this.get_caller_name() || this.caller_number]); - this.set_indicator('blue', true); - } else if (call_status === 'In Progress') { - title = __('Call Connected'); - this.set_indicator('green'); - } else if (['No Answer', 'Missed'].includes(call_status)) { - this.set_indicator('yellow'); - title = __('Call Missed'); - } else if (['Completed', 'Busy', 'Failed'].includes(call_status)) { - this.set_indicator('red'); - title = __('Call Ended'); + if (["Ringing"].includes(call_status) || !call_status) { + title = __("Incoming call from {0}", [this.get_caller_name() || this.caller_number]); + this.set_indicator("blue", true); + } else if (call_status === "In Progress") { + title = __("Call Connected"); + this.set_indicator("green"); + } else if (["No Answer", "Missed"].includes(call_status)) { + this.set_indicator("yellow"); + title = __("Call Missed"); + } else if (["Completed", "Busy", "Failed"].includes(call_status)) { + this.set_indicator("red"); + title = __("Call Ended"); } else { - this.set_indicator('blue'); + this.set_indicator("blue"); title = call_status; } this.dialog.set_title(title); @@ -55,7 +55,7 @@ class CallPopup { update_call_log(call_log, missed) { this.call_log = call_log; - this.set_call_status(missed ? 'Missed': null); + this.set_call_status(missed ? "Missed" : null); } close_modal() { @@ -64,10 +64,10 @@ class CallPopup { } call_ended(call_log, missed) { - frappe.utils.play_sound('call-disconnect'); + frappe.utils.play_sound("call-disconnect"); this.update_call_log(call_log, missed); setTimeout(() => { - if (!this.dialog.get_value('call_summary')) { + if (!this.dialog.get_value("call_summary")) { this.close_modal(); } }, 60000); @@ -81,16 +81,16 @@ class CallPopup { get_contact_link() { let log = this.call_log; - let contact_link = log.links.find(d => d.link_doctype === 'Contact'); + let contact_link = log.links.find((d) => d.link_doctype === "Contact"); return contact_link || {}; } setup_listener() { - frappe.realtime.on(`call_${this.call_log.id}_ended`, call_log => { + frappe.realtime.on(`call_${this.call_log.id}_ended`, (call_log) => { this.call_ended(call_log); }); - frappe.realtime.on(`call_${this.call_log.id}_missed`, call_log => { + frappe.realtime.on(`call_${this.call_log.id}_missed`, (call_log) => { this.call_ended(call_log, true); }); } @@ -103,84 +103,102 @@ class CallPopup { setup_call_details() { this.caller_info = $(`
    `); this.call_details = new frappe.ui.FieldGroup({ - fields: [{ - 'fieldname': 'name', - 'label': 'Name', - 'default': this.get_caller_name() || __('Unknown Caller'), - 'fieldtype': 'Data', - 'read_only': 1 - }, { - 'fieldtype': 'Button', - 'label': __('Open Contact'), - 'click': () => frappe.set_route('Form', 'Contact', this.get_contact_link().link_name), - 'depends_on': () => this.get_caller_name() - }, { - 'fieldtype': 'Button', - 'label': __('Create New Contact'), - 'click': this.create_new_contact.bind(this), - 'depends_on': () => !this.get_caller_name() - }, { - 'fieldtype': 'Button', - 'label': __('Create New Customer'), - 'click': this.create_new_customer.bind(this), - 'depends_on': () => !this.get_caller_name() - }, { - 'fieldtype': 'Button', - 'label': __('Create New Lead'), - 'click': () => frappe.new_doc('Lead', { 'mobile_no': this.caller_number }), - 'depends_on': () => !this.get_caller_name() - }, { - 'fieldtype': 'Column Break', - }, { - 'fieldname': 'number', - 'label': 'Phone Number', - 'fieldtype': 'Data', - 'default': this.caller_number, - 'read_only': 1 - }, { - 'fieldtype': 'Section Break', - 'hide_border': 1, - }, { - 'fieldname': 'call_type', - 'label': 'Call Type', - 'fieldtype': 'Link', - 'options': 'Telephony Call Type', - }, { - 'fieldtype': 'Section Break', - 'hide_border': 1, - }, { - 'fieldtype': 'Small Text', - 'label': __('Call Summary'), - 'fieldname': 'call_summary', - }, { - 'fieldtype': 'Button', - 'label': __('Save'), - 'click': () => { - const call_summary = this.call_details.get_value('call_summary'); - const call_type = this.call_details.get_value('call_type'); - if (!call_summary) return; - frappe.xcall('erpnext.telephony.doctype.call_log.call_log.add_call_summary_and_call_type', { - 'call_log': this.call_log.name, - 'summary': call_summary, - 'call_type': call_type, - }).then(() => { - this.close_modal(); - frappe.show_alert({ - message: ` - ${__('Call Summary Saved')} + fields: [ + { + fieldname: "name", + label: "Name", + default: this.get_caller_name() || __("Unknown Caller"), + fieldtype: "Data", + read_only: 1, + }, + { + fieldtype: "Button", + label: __("Open Contact"), + click: () => frappe.set_route("Form", "Contact", this.get_contact_link().link_name), + depends_on: () => this.get_caller_name(), + }, + { + fieldtype: "Button", + label: __("Create New Contact"), + click: this.create_new_contact.bind(this), + depends_on: () => !this.get_caller_name(), + }, + { + fieldtype: "Button", + label: __("Create New Customer"), + click: this.create_new_customer.bind(this), + depends_on: () => !this.get_caller_name(), + }, + { + fieldtype: "Button", + label: __("Create New Lead"), + click: () => frappe.new_doc("Lead", { mobile_no: this.caller_number }), + depends_on: () => !this.get_caller_name(), + }, + { + fieldtype: "Column Break", + }, + { + fieldname: "number", + label: "Phone Number", + fieldtype: "Data", + default: this.caller_number, + read_only: 1, + }, + { + fieldtype: "Section Break", + hide_border: 1, + }, + { + fieldname: "call_type", + label: "Call Type", + fieldtype: "Link", + options: "Telephony Call Type", + }, + { + fieldtype: "Section Break", + hide_border: 1, + }, + { + fieldtype: "Small Text", + label: __("Call Summary"), + fieldname: "call_summary", + }, + { + fieldtype: "Button", + label: __("Save"), + click: () => { + const call_summary = this.call_details.get_value("call_summary"); + const call_type = this.call_details.get_value("call_type"); + if (!call_summary) return; + frappe + .xcall( + "erpnext.telephony.doctype.call_log.call_log.add_call_summary_and_call_type", + { + call_log: this.call_log.name, + summary: call_summary, + call_type: call_type, + } + ) + .then(() => { + this.close_modal(); + frappe.show_alert({ + message: ` + ${__("Call Summary Saved")}
    - ${__('View call log')} + ${__("View call log")} `, - indicator: 'green' - }); - }); - } - }], - body: this.caller_info + indicator: "green", + }); + }); + }, + }, + ], + body: this.caller_info, }); this.call_details.make(); } @@ -191,23 +209,23 @@ class CallPopup { create_new_customer() { // to avoid quick entry form - const new_customer = frappe.model.get_new_doc('Customer'); + const new_customer = frappe.model.get_new_doc("Customer"); new_customer.mobile_no = this.caller_number; - frappe.set_route('Form', new_customer.doctype, new_customer.name); + frappe.set_route("Form", new_customer.doctype, new_customer.name); } create_new_contact() { // TODO: fix new_doc, it should accept child table values - const new_contact = frappe.model.get_new_doc('Contact'); - const phone_no = frappe.model.add_child(new_contact, 'Contact Phone', 'phone_nos'); + const new_contact = frappe.model.get_new_doc("Contact"); + const phone_no = frappe.model.add_child(new_contact, "Contact Phone", "phone_nos"); phone_no.phone = this.caller_number; phone_no.is_primary_mobile_no = 1; - frappe.set_route('Form', new_contact.doctype, new_contact.name); + frappe.set_route("Form", new_contact.doctype, new_contact.name); } } -$(document).on('app_ready', function () { - frappe.realtime.on('show_call_popup', call_log => { +$(document).on("app_ready", function () { + frappe.realtime.on("show_call_popup", (call_log) => { let call_popup = erpnext.call_popup; if (call_popup && call_log.name === call_popup.call_log.name) { call_popup.update_call_log(call_log); diff --git a/erpnext/public/js/communication.js b/erpnext/public/js/communication.js index f205d8896587..d9187f8b6788 100644 --- a/erpnext/public/js/communication.js +++ b/erpnext/public/js/communication.js @@ -1,33 +1,45 @@ frappe.ui.form.on("Communication", { refresh: (frm) => { // setup custom Make button only if Communication is Email - if(frm.doc.communication_medium == "Email" && frm.doc.sent_or_received == "Received") { + if (frm.doc.communication_medium == "Email" && frm.doc.sent_or_received == "Received") { frm.events.setup_custom_buttons(frm); } }, setup_custom_buttons: (frm) => { let confirm_msg = "Are you sure you want to create {0} from this email?"; - if(frm.doc.reference_doctype !== "Issue") { - frm.add_custom_button(__("Issue"), () => { - frappe.confirm(__(confirm_msg, [__("Issue")]), () => { - frm.trigger('make_issue_from_communication'); - }) - }, __("Create")); + if (frm.doc.reference_doctype !== "Issue") { + frm.add_custom_button( + __("Issue"), + () => { + frappe.confirm(__(confirm_msg, [__("Issue")]), () => { + frm.trigger("make_issue_from_communication"); + }); + }, + __("Create") + ); } - if(!in_list(["Lead", "Opportunity"], frm.doc.reference_doctype)) { - frm.add_custom_button(__("Lead"), () => { - frappe.confirm(__(confirm_msg, [__("Lead")]), () => { - frm.trigger('make_lead_from_communication'); - }) - }, __('Create')); + if (!in_list(["Lead", "Opportunity"], frm.doc.reference_doctype)) { + frm.add_custom_button( + __("Lead"), + () => { + frappe.confirm(__(confirm_msg, [__("Lead")]), () => { + frm.trigger("make_lead_from_communication"); + }); + }, + __("Create") + ); - frm.add_custom_button(__("Opportunity"), () => { - frappe.confirm(__(confirm_msg, [__("Opportunity")]), () => { - frm.trigger('make_opportunity_from_communication'); - }) - }, __('Create')); + frm.add_custom_button( + __("Opportunity"), + () => { + frappe.confirm(__(confirm_msg, [__("Opportunity")]), () => { + frm.trigger("make_opportunity_from_communication"); + }); + }, + __("Create") + ); } }, @@ -35,63 +47,69 @@ frappe.ui.form.on("Communication", { return frappe.call({ method: "erpnext.crm.doctype.lead.lead.make_lead_from_communication", args: { - communication: frm.doc.name + communication: frm.doc.name, }, freeze: true, callback: (r) => { - if(r.message) { - frm.reload_doc() + if (r.message) { + frm.reload_doc(); } - } - }) + }, + }); }, make_issue_from_communication: (frm) => { return frappe.call({ method: "erpnext.support.doctype.issue.issue.make_issue_from_communication", args: { - communication: frm.doc.name + communication: frm.doc.name, }, freeze: true, callback: (r) => { - if(r.message) { - frm.reload_doc() + if (r.message) { + frm.reload_doc(); } - } - }) + }, + }); }, make_opportunity_from_communication: (frm) => { - const fields = [{ - fieldtype: 'Link', - label: __('Select a Company'), - fieldname: 'company', - options: 'Company', - reqd: 1, - default: frappe.defaults.get_user_default("Company") - }]; + const fields = [ + { + fieldtype: "Link", + label: __("Select a Company"), + fieldname: "company", + options: "Company", + reqd: 1, + default: frappe.defaults.get_user_default("Company"), + }, + ]; - frappe.prompt(fields, data => { - frappe.call({ - method: "erpnext.crm.doctype.opportunity.opportunity.make_opportunity_from_communication", - args: { - communication: frm.doc.name, - company: data.company - }, - freeze: true, - callback: (r) => { - if(r.message) { - frm.reload_doc(); - frappe.show_alert({ - message: __("Opportunity {0} created", - ['' + r.message + '']), - indicator: 'green' - }); - } - } - }); - }, - 'Create an Opportunity', - 'Create'); - } + frappe.prompt( + fields, + (data) => { + frappe.call({ + method: "erpnext.crm.doctype.opportunity.opportunity.make_opportunity_from_communication", + args: { + communication: frm.doc.name, + company: data.company, + }, + freeze: true, + callback: (r) => { + if (r.message) { + frm.reload_doc(); + frappe.show_alert({ + message: __("Opportunity {0} created", [ + '' + r.message + "", + ]), + indicator: "green", + }); + } + }, + }); + }, + "Create an Opportunity", + "Create" + ); + }, }); diff --git a/erpnext/public/js/conf.js b/erpnext/public/js/conf.js index a0f56a2d07fa..2e6e9ba1ad43 100644 --- a/erpnext/public/js/conf.js +++ b/erpnext/public/js/conf.js @@ -1,26 +1,26 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -frappe.provide('erpnext'); +frappe.provide("erpnext"); // preferred modules for breadcrumbs $.extend(frappe.breadcrumbs.preferred, { "Item Group": "Stock", "Customer Group": "Selling", "Supplier Group": "Buying", - "Territory": "Selling", + Territory: "Selling", "Sales Person": "Selling", "Sales Partner": "Selling", - "Brand": "Stock", + Brand: "Stock", "Maintenance Schedule": "Support", - "Maintenance Visit": "Support" + "Maintenance Visit": "Support", }); $.extend(frappe.breadcrumbs.module_map, { - 'ERPNext Integrations': 'Integrations', - 'Geo': 'Settings', - 'Portal': 'Website', - 'Utilities': 'Settings', - 'E-commerce': 'Website', - 'Contacts': 'CRM' + "ERPNext Integrations": "Integrations", + Geo: "Settings", + Portal: "Website", + Utilities: "Settings", + "E-commerce": "Website", + Contacts: "CRM", }); diff --git a/erpnext/public/js/contact.js b/erpnext/public/js/contact.js index 41a0e8a9f999..ecfc4eeef935 100644 --- a/erpnext/public/js/contact.js +++ b/erpnext/public/js/contact.js @@ -1,16 +1,14 @@ - - frappe.ui.form.on("Contact", { refresh(frm) { - frm.set_query('link_doctype', "links", function() { + frm.set_query("link_doctype", "links", function () { return { query: "frappe.contacts.address_and_contact.filter_dynamic_link_doctypes", filters: { fieldtype: ["in", ["HTML", "Text Editor"]], fieldname: ["in", ["contact_html", "company_description"]], - } + }, }; }); frm.refresh_field("links"); - } + }, }); diff --git a/erpnext/public/js/customer_reviews.js b/erpnext/public/js/customer_reviews.js index e13ded6b489f..26deb9a6dd0f 100644 --- a/erpnext/public/js/customer_reviews.js +++ b/erpnext/public/js/customer_reviews.js @@ -13,27 +13,27 @@ $(() => { write_review() { //TODO: make dialog popup on stray page - $('.page_content').on('click', '.btn-write-review', (e) => { + $(".page_content").on("click", ".btn-write-review", (e) => { // Bind action on write a review button const $btn = $(e.currentTarget); let d = new frappe.ui.Dialog({ title: __("Write a Review"), fields: [ - {fieldname: "title", fieldtype: "Data", label: "Headline", reqd: 1}, - {fieldname: "rating", fieldtype: "Rating", label: "Overall Rating", reqd: 1}, - {fieldtype: "Section Break"}, - {fieldname: "comment", fieldtype: "Small Text", label: "Your Review"} + { fieldname: "title", fieldtype: "Data", label: "Headline", reqd: 1 }, + { fieldname: "rating", fieldtype: "Rating", label: "Overall Rating", reqd: 1 }, + { fieldtype: "Section Break" }, + { fieldname: "comment", fieldtype: "Small Text", label: "Your Review" }, ], - primary_action: function() { + primary_action: function () { let data = d.get_values(); frappe.call({ method: "erpnext.e_commerce.doctype.item_review.item_review.add_item_review", args: { - web_item: $btn.attr('data-web-item'), + web_item: $btn.attr("data-web-item"), title: data.title, rating: data.rating, - comment: data.comment + comment: data.comment, }, freeze: true, freeze_message: __("Submitting Review ..."), @@ -42,25 +42,25 @@ $(() => { frappe.msgprint({ message: __("Thank you for submitting your review"), title: __("Review Submitted"), - indicator: "green" + indicator: "green", }); d.hide(); location.reload(); } - } + }, }); }, - primary_action_label: __('Submit') + primary_action_label: __("Submit"), }); d.show(); }); } view_more() { - $('.page_content').on('click', '.btn-view-more', (e) => { + $(".page_content").on("click", ".btn-view-more", (e) => { // Bind action on view more button const $btn = $(e.currentTarget); - $btn.prop('disabled', true); + $btn.prop("disabled", true); this.start += this.page_length; let me = this; @@ -68,30 +68,28 @@ $(() => { frappe.call({ method: "erpnext.e_commerce.doctype.item_review.item_review.get_item_reviews", args: { - web_item: $btn.attr('data-web-item'), + web_item: $btn.attr("data-web-item"), start: me.start, - end: me.page_length + end: me.page_length, }, callback: (result) => { if (result.message) { let res = result.message; me.get_user_review_html(res.reviews); - $btn.prop('disabled', false); - if (res.total_reviews <= (me.start + me.page_length)) { + $btn.prop("disabled", false); + if (res.total_reviews <= me.start + me.page_length) { $btn.hide(); } - } - } + }, }); }); - } get_user_review_html(reviews) { let me = this; - let $content = $('.user-reviews'); + let $content = $(".user-reviews"); reviews.forEach((review) => { $content.append(` @@ -123,7 +121,7 @@ $(() => { get_review_stars(rating) { let stars = ``; for (let i = 1; i < 6; i++) { - let fill_class = i <= rating ? 'star-click' : ''; + let fill_class = i <= rating ? "star-click" : ""; stars += ` @@ -135,4 +133,4 @@ $(() => { } new CustomerReviews(); -}); \ No newline at end of file +}); diff --git a/erpnext/public/js/erpnext-web.bundle.js b/erpnext/public/js/erpnext-web.bundle.js index cbe899dc0607..7c20d6eb8d6a 100644 --- a/erpnext/public/js/erpnext-web.bundle.js +++ b/erpnext/public/js/erpnext-web.bundle.js @@ -5,4 +5,4 @@ import "./customer_reviews"; import "../../e_commerce/product_ui/list"; import "../../e_commerce/product_ui/views"; import "../../e_commerce/product_ui/grid"; -import "../../e_commerce/product_ui/search"; \ No newline at end of file +import "../../e_commerce/product_ui/search"; diff --git a/erpnext/public/js/event.js b/erpnext/public/js/event.js index 665c8fbe1f40..a6733915a5c4 100644 --- a/erpnext/public/js/event.js +++ b/erpnext/public/js/event.js @@ -3,33 +3,53 @@ frappe.provide("frappe.desk"); frappe.ui.form.on("Event", { - refresh: function(frm) { - frm.set_query('reference_doctype', "event_participants", function() { + refresh: function (frm) { + frm.set_query("reference_doctype", "event_participants", function () { return { - "filters": { - "name": ["in", ["Contact", "Lead", "Customer", "Supplier", "Employee", "Sales Partner"]] - } + filters: { + name: ["in", ["Contact", "Lead", "Customer", "Supplier", "Employee", "Sales Partner"]], + }, }; }); - frm.add_custom_button(__('Add Leads'), function() { - new frappe.desk.eventParticipants(frm, "Lead"); - }, __("Add Participants")); + frm.add_custom_button( + __("Add Leads"), + function () { + new frappe.desk.eventParticipants(frm, "Lead"); + }, + __("Add Participants") + ); - frm.add_custom_button(__('Add Customers'), function() { - new frappe.desk.eventParticipants(frm, "Customer"); - }, __("Add Participants")); + frm.add_custom_button( + __("Add Customers"), + function () { + new frappe.desk.eventParticipants(frm, "Customer"); + }, + __("Add Participants") + ); - frm.add_custom_button(__('Add Suppliers'), function() { - new frappe.desk.eventParticipants(frm, "Supplier"); - }, __("Add Participants")); + frm.add_custom_button( + __("Add Suppliers"), + function () { + new frappe.desk.eventParticipants(frm, "Supplier"); + }, + __("Add Participants") + ); - frm.add_custom_button(__('Add Employees'), function() { - new frappe.desk.eventParticipants(frm, "Employee"); - }, __("Add Participants")); + frm.add_custom_button( + __("Add Employees"), + function () { + new frappe.desk.eventParticipants(frm, "Employee"); + }, + __("Add Participants") + ); - frm.add_custom_button(__('Add Sales Partners'), function() { - new frappe.desk.eventParticipants(frm, "Sales Partners"); - }, __("Add Participants")); - } + frm.add_custom_button( + __("Add Sales Partners"), + function () { + new frappe.desk.eventParticipants(frm, "Sales Partners"); + }, + __("Add Participants") + ); + }, }); diff --git a/erpnext/public/js/financial_statements.js b/erpnext/public/js/financial_statements.js index 666505e2e383..d489c91c305d 100644 --- a/erpnext/public/js/financial_statements.js +++ b/erpnext/public/js/financial_statements.js @@ -1,59 +1,57 @@ frappe.provide("erpnext.financial_statements"); erpnext.financial_statements = { - "filters": get_filters(), - "baseData": null, - "formatter": function(value, row, column, data, default_formatter, filter) { - if(frappe.query_report.get_filter_value("selected_view") == "Growth" && data && column.colIndex >= 3){ + filters: get_filters(), + baseData: null, + formatter: function (value, row, column, data, default_formatter, filter) { + if ( + frappe.query_report.get_filter_value("selected_view") == "Growth" && + data && + column.colIndex >= 3 + ) { //Assuming that the first three columns are s.no, account name and the very first year of the accounting values, to calculate the relative percentage values of the successive columns. const lastAnnualValue = row[column.colIndex - 1].content; const currentAnnualvalue = data[column.fieldname]; - if(currentAnnualvalue == undefined) return 'NA'; //making this not applicable for undefined/null values + if (currentAnnualvalue == undefined) return "NA"; //making this not applicable for undefined/null values let annualGrowth = 0; - if(lastAnnualValue == 0 && currentAnnualvalue > 0){ + if (lastAnnualValue == 0 && currentAnnualvalue > 0) { //If the previous year value is 0 and the current value is greater than 0 annualGrowth = 1; - } - else if(lastAnnualValue > 0){ - annualGrowth = (currentAnnualvalue - lastAnnualValue) / lastAnnualValue; + } else if (lastAnnualValue > 0) { + annualGrowth = (currentAnnualvalue - lastAnnualValue) / lastAnnualValue; } - const growthPercent = (Math.round(annualGrowth*10000)/100); //calculating the rounded off percentage + const growthPercent = Math.round(annualGrowth * 10000) / 100; //calculating the rounded off percentage - value = $(`${((growthPercent >=0)? '+':'' )+growthPercent+'%'}`); - if(growthPercent < 0){ + value = $(`${(growthPercent >= 0 ? "+" : "") + growthPercent + "%"}`); + if (growthPercent < 0) { value = $(value).addClass("text-danger"); - } - else{ + } else { value = $(value).addClass("text-success"); } value = $(value).wrap("

    ").parent().html(); return value; - } - else if(frappe.query_report.get_filter_value("selected_view") == "Margin" && data){ - if(column.fieldname =="account" && data.account_name == __("Income")){ + } else if (frappe.query_report.get_filter_value("selected_view") == "Margin" && data) { + if (column.fieldname == "account" && data.account_name == __("Income")) { //Taking the total income from each column (for all the financial years) as the base (100%) this.baseData = row; } - if(column.colIndex >= 2){ + if (column.colIndex >= 2) { //Assuming that the first two columns are s.no and account name, to calculate the relative percentage values of the successive columns. const currentAnnualvalue = data[column.fieldname]; const baseValue = this.baseData[column.colIndex].content; - if(currentAnnualvalue == undefined || baseValue <= 0) return 'NA'; - const marginPercent = Math.round((currentAnnualvalue/baseValue)*10000)/100; + if (currentAnnualvalue == undefined || baseValue <= 0) return "NA"; + const marginPercent = Math.round((currentAnnualvalue / baseValue) * 10000) / 100; - value = $(`${marginPercent+'%'}`); - if(marginPercent < 0) - value = $(value).addClass("text-danger"); - else - value = $(value).addClass("text-success"); + value = $(`${marginPercent + "%"}`); + if (marginPercent < 0) value = $(value).addClass("text-danger"); + else value = $(value).addClass("text-success"); value = $(value).wrap("

    ").parent().html(); return value; } - } - if (data && column.fieldname=="account") { + if (data && column.fieldname == "account") { value = data.account_name || value; if (filter && filter?.text && filter?.type == "contains") { @@ -84,16 +82,18 @@ erpnext.financial_statements = { return value; }, - "open_general_ledger": function(data) { + open_general_ledger: function (data) { if (!data.account) return; - let project = $.grep(frappe.query_report.filters, function(e){ return e.df.fieldname == 'project'; }); + let project = $.grep(frappe.query_report.filters, function (e) { + return e.df.fieldname == "project"; + }); frappe.route_options = { - "account": data.account, - "company": frappe.query_report.get_filter_value('company'), - "from_date": data.from_date || data.year_start_date, - "to_date": data.to_date || data.year_end_date, - "project": (project && project.length > 0) ? project[0].$input.val() : "" + account: data.account, + company: frappe.query_report.get_filter_value("company"), + from_date: data.from_date || data.year_start_date, + to_date: data.to_date || data.year_end_date, + project: project && project.length > 0 ? project[0].$input.val() : "", }; let report = "General Ledger"; @@ -106,152 +106,161 @@ erpnext.financial_statements = { frappe.set_route("query-report", report); }, - "tree": true, - "name_field": "account", - "parent_field": "parent_account", - "initial_depth": 3, - onload: function(report) { + tree: true, + name_field: "account", + parent_field: "parent_account", + initial_depth: 3, + onload: function (report) { // dropdown for links to other financial statements - erpnext.financial_statements.filters = get_filters() + erpnext.financial_statements.filters = get_filters(); let fiscal_year = erpnext.utils.get_fiscal_year(frappe.datetime.get_today()); - frappe.model.with_doc("Fiscal Year", fiscal_year, function(r) { + frappe.model.with_doc("Fiscal Year", fiscal_year, function (r) { var fy = frappe.model.get_doc("Fiscal Year", fiscal_year); frappe.query_report.set_filter_value({ period_start_date: fy.year_start_date, - period_end_date: fy.year_end_date + period_end_date: fy.year_end_date, }); }); - const views_menu = report.page.add_custom_button_group(__('Financial Statements')); + const views_menu = report.page.add_custom_button_group(__("Financial Statements")); - report.page.add_custom_menu_item(views_menu, __("Balance Sheet"), function() { + report.page.add_custom_menu_item(views_menu, __("Balance Sheet"), function () { var filters = report.get_values(); - frappe.set_route('query-report', 'Balance Sheet', {company: filters.company}); + frappe.set_route("query-report", "Balance Sheet", { company: filters.company }); }); - report.page.add_custom_menu_item(views_menu, __("Profit and Loss"), function() { + report.page.add_custom_menu_item(views_menu, __("Profit and Loss"), function () { var filters = report.get_values(); - frappe.set_route('query-report', 'Profit and Loss Statement', {company: filters.company}); + frappe.set_route("query-report", "Profit and Loss Statement", { company: filters.company }); }); - report.page.add_custom_menu_item(views_menu, __("Cash Flow Statement"), function() { + report.page.add_custom_menu_item(views_menu, __("Cash Flow Statement"), function () { var filters = report.get_values(); - frappe.set_route('query-report', 'Cash Flow', {company: filters.company}); + frappe.set_route("query-report", "Cash Flow", { company: filters.company }); }); - } + }, }; function get_filters() { let filters = [ { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_user_default("Company"), - "reqd": 1 + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), + reqd: 1, }, { - "fieldname":"finance_book", - "label": __("Finance Book"), - "fieldtype": "Link", - "options": "Finance Book" + fieldname: "finance_book", + label: __("Finance Book"), + fieldtype: "Link", + options: "Finance Book", }, { - "fieldname":"filter_based_on", - "label": __("Filter Based On"), - "fieldtype": "Select", - "options": ["Fiscal Year", "Date Range"], - "default": ["Fiscal Year"], - "reqd": 1, - on_change: function() { - let filter_based_on = frappe.query_report.get_filter_value('filter_based_on'); - frappe.query_report.toggle_filter_display('from_fiscal_year', filter_based_on === 'Date Range'); - frappe.query_report.toggle_filter_display('to_fiscal_year', filter_based_on === 'Date Range'); - frappe.query_report.toggle_filter_display('period_start_date', filter_based_on === 'Fiscal Year'); - frappe.query_report.toggle_filter_display('period_end_date', filter_based_on === 'Fiscal Year'); + fieldname: "filter_based_on", + label: __("Filter Based On"), + fieldtype: "Select", + options: ["Fiscal Year", "Date Range"], + default: ["Fiscal Year"], + reqd: 1, + on_change: function () { + let filter_based_on = frappe.query_report.get_filter_value("filter_based_on"); + frappe.query_report.toggle_filter_display( + "from_fiscal_year", + filter_based_on === "Date Range" + ); + frappe.query_report.toggle_filter_display("to_fiscal_year", filter_based_on === "Date Range"); + frappe.query_report.toggle_filter_display( + "period_start_date", + filter_based_on === "Fiscal Year" + ); + frappe.query_report.toggle_filter_display( + "period_end_date", + filter_based_on === "Fiscal Year" + ); frappe.query_report.refresh(); - } + }, }, { - "fieldname":"period_start_date", - "label": __("Start Date"), - "fieldtype": "Date", - "reqd": 1, - "depends_on": "eval:doc.filter_based_on == 'Date Range'" + fieldname: "period_start_date", + label: __("Start Date"), + fieldtype: "Date", + reqd: 1, + depends_on: "eval:doc.filter_based_on == 'Date Range'", }, { - "fieldname":"period_end_date", - "label": __("End Date"), - "fieldtype": "Date", - "reqd": 1, - "depends_on": "eval:doc.filter_based_on == 'Date Range'" + fieldname: "period_end_date", + label: __("End Date"), + fieldtype: "Date", + reqd: 1, + depends_on: "eval:doc.filter_based_on == 'Date Range'", }, { - "fieldname":"from_fiscal_year", - "label": __("Start Year"), - "fieldtype": "Link", - "options": "Fiscal Year", - "default": erpnext.utils.get_fiscal_year(frappe.datetime.get_today()), - "reqd": 1, - "depends_on": "eval:doc.filter_based_on == 'Fiscal Year'" + fieldname: "from_fiscal_year", + label: __("Start Year"), + fieldtype: "Link", + options: "Fiscal Year", + default: erpnext.utils.get_fiscal_year(frappe.datetime.get_today()), + reqd: 1, + depends_on: "eval:doc.filter_based_on == 'Fiscal Year'", }, { - "fieldname":"to_fiscal_year", - "label": __("End Year"), - "fieldtype": "Link", - "options": "Fiscal Year", - "default": erpnext.utils.get_fiscal_year(frappe.datetime.get_today()), - "reqd": 1, - "depends_on": "eval:doc.filter_based_on == 'Fiscal Year'" + fieldname: "to_fiscal_year", + label: __("End Year"), + fieldtype: "Link", + options: "Fiscal Year", + default: erpnext.utils.get_fiscal_year(frappe.datetime.get_today()), + reqd: 1, + depends_on: "eval:doc.filter_based_on == 'Fiscal Year'", }, { - "fieldname": "periodicity", - "label": __("Periodicity"), - "fieldtype": "Select", - "options": [ - { "value": "Monthly", "label": __("Monthly") }, - { "value": "Quarterly", "label": __("Quarterly") }, - { "value": "Half-Yearly", "label": __("Half-Yearly") }, - { "value": "Yearly", "label": __("Yearly") } + fieldname: "periodicity", + label: __("Periodicity"), + fieldtype: "Select", + options: [ + { value: "Monthly", label: __("Monthly") }, + { value: "Quarterly", label: __("Quarterly") }, + { value: "Half-Yearly", label: __("Half-Yearly") }, + { value: "Yearly", label: __("Yearly") }, ], - "default": "Yearly", - "reqd": 1 + default: "Yearly", + reqd: 1, }, // Note: // If you are modifying this array such that the presentation_currency object // is no longer the last object, please make adjustments in cash_flow.js // accordingly. { - "fieldname": "presentation_currency", - "label": __("Currency"), - "fieldtype": "Select", - "options": erpnext.get_presentation_currency_list() + fieldname: "presentation_currency", + label: __("Currency"), + fieldtype: "Select", + options: erpnext.get_presentation_currency_list(), }, { - "fieldname": "cost_center", - "label": __("Cost Center"), - "fieldtype": "MultiSelectList", - get_data: function(txt) { - return frappe.db.get_link_options('Cost Center', txt, { - company: frappe.query_report.get_filter_value("company") + fieldname: "cost_center", + label: __("Cost Center"), + fieldtype: "MultiSelectList", + get_data: function (txt) { + return frappe.db.get_link_options("Cost Center", txt, { + company: frappe.query_report.get_filter_value("company"), }); - } + }, }, { - "fieldname": "project", - "label": __("Project"), - "fieldtype": "MultiSelectList", - get_data: function(txt) { - return frappe.db.get_link_options('Project', txt, { - company: frappe.query_report.get_filter_value("company") + fieldname: "project", + label: __("Project"), + fieldtype: "MultiSelectList", + get_data: function (txt) { + return frappe.db.get_link_options("Project", txt, { + company: frappe.query_report.get_filter_value("company"), }); }, - } - ] + }, + ]; return filters; } diff --git a/erpnext/public/js/help_links.js b/erpnext/public/js/help_links.js index b643ccae9475..b37bd11ead06 100644 --- a/erpnext/public/js/help_links.js +++ b/erpnext/public/js/help_links.js @@ -14,9 +14,7 @@ frappe.help.help_links["Form/Rename Tool"] = [ frappe.help.help_links["List/User"] = [ { label: "New User", - url: - docsUrl + - "user/manual/en/setting-up/users-and-permissions/adding-users", + url: docsUrl + "user/manual/en/setting-up/users-and-permissions/adding-users", }, { label: "Rename User", @@ -27,9 +25,7 @@ frappe.help.help_links["List/User"] = [ frappe.help.help_links["permission-manager"] = [ { label: "Role Permissions Manager", - url: - docsUrl + - "user/manual/en/setting-up/users-and-permissions/role-based-permissions", + url: docsUrl + "user/manual/en/setting-up/users-and-permissions/role-based-permissions", }, { label: "Managing Perm Level in Permissions Manager", @@ -37,14 +33,11 @@ frappe.help.help_links["permission-manager"] = [ }, { label: "User Permissions", - url: - docsUrl + - "user/manual/en/setting-up/users-and-permissions/user-permissions", + url: docsUrl + "user/manual/en/setting-up/users-and-permissions/user-permissions", }, { label: "Sharing", - url: - docsUrl + "user/manual/en/setting-up/users-and-permissions/sharing", + url: docsUrl + "user/manual/en/setting-up/users-and-permissions/sharing", }, { label: "Password", @@ -66,9 +59,7 @@ frappe.help.help_links["Form/Data Import"] = [ }, { label: "Overwriting Data from Data Import Tool", - url: - docsUrl + - "user/manual/en/setting-up/articles/overwriting-data-from-data-import-tool", + url: docsUrl + "user/manual/en/setting-up/articles/overwriting-data-from-data-import-tool", }, ]; @@ -79,18 +70,14 @@ frappe.help.help_links["List/Data Import"] = [ }, { label: "Overwriting Data from Data Import Tool", - url: - docsUrl + - "user/manual/en/setting-up/articles/overwriting-data-from-data-import-tool", + url: docsUrl + "user/manual/en/setting-up/articles/overwriting-data-from-data-import-tool", }, ]; frappe.help.help_links["module_setup"] = [ { label: "Role Permissions Manager", - url: - docsUrl + - "user/manual/en/setting-up/users-and-permissions/role-based-permissions", + url: docsUrl + "user/manual/en/setting-up/users-and-permissions/role-based-permissions", }, ]; @@ -101,9 +88,7 @@ frappe.help.help_links["Form/Naming Series"] = [ }, { label: "Setting the Current Value for Naming Series", - url: - docsUrl + - "user/manual/en/setting-up/articles/naming-series-current-value", + url: docsUrl + "user/manual/en/setting-up/articles/naming-series-current-value", }, ]; @@ -217,18 +202,14 @@ frappe.help.help_links["print-format-builder"] = [ frappe.help.help_links["Form/PayPal Settings"] = [ { label: "PayPal Settings", - url: - docsUrl + - "user/manual/en/erpnext_integration/paypal-integration", + url: docsUrl + "user/manual/en/erpnext_integration/paypal-integration", }, ]; frappe.help.help_links["Form/Razorpay Settings"] = [ { label: "Razorpay Settings", - url: - docsUrl + - "user/manual/en/erpnext_integration/razorpay-integration", + url: docsUrl + "user/manual/en/erpnext_integration/razorpay-integration", }, ]; @@ -242,17 +223,14 @@ frappe.help.help_links["Form/Dropbox Settings"] = [ frappe.help.help_links["Form/LDAP Settings"] = [ { label: "LDAP Settings", - url: - docsUrl + "user/manual/en/erpnext_integration/ldap-integration", + url: docsUrl + "user/manual/en/erpnext_integration/ldap-integration", }, ]; frappe.help.help_links["Form/Stripe Settings"] = [ { label: "Stripe Settings", - url: - docsUrl + - "user/manual/en/erpnext_integration/stripe-integration", + url: docsUrl + "user/manual/en/erpnext_integration/stripe-integration", }, ]; @@ -266,9 +244,7 @@ frappe.help.help_links["Form/Quotation"] = [ }, { label: "Sales Person", - url: - docsUrl + - "user/manual/en/selling/articles/sales-persons-in-the-sales-transactions", + url: docsUrl + "user/manual/en/selling/articles/sales-persons-in-the-sales-transactions", }, { label: "Applying Margin", @@ -340,9 +316,7 @@ frappe.help.help_links["Form/Sales Order"] = [ }, { label: "Sales Person", - url: - docsUrl + - "user/manual/en/selling/articles/sales-persons-in-the-sales-transactions", + url: docsUrl + "user/manual/en/selling/articles/sales-persons-in-the-sales-transactions", }, { label: "Close Sales Order", @@ -421,15 +395,11 @@ frappe.help.help_links["Form/Purchase Order"] = [ }, { label: "Item UoM", - url: - docsUrl + - "user/manual/en/buying/articles/purchasing-in-different-unit", + url: docsUrl + "user/manual/en/buying/articles/purchasing-in-different-unit", }, { label: "Supplier Item Code", - url: - docsUrl + - "user/manual/en/buying/articles/maintaining-suppliers-part-no-in-item", + url: docsUrl + "user/manual/en/buying/articles/maintaining-suppliers-part-no-in-item", }, { label: "Recurring Purchase Order", @@ -472,9 +442,7 @@ frappe.help.help_links["Form/SMS Settings"] = [ frappe.help.help_links["List/Stock Reconciliation"] = [ { label: "Stock Reconciliation", - url: - docsUrl + - "user/manual/en/stock/stock-reconciliation", + url: docsUrl + "user/manual/en/stock/stock-reconciliation", }, ]; @@ -496,9 +464,7 @@ frappe.help.help_links["List/Company"] = [ }, { label: "Delete All Related Transactions for a Company", - url: - docsUrl + - "user/manual/en/setting-up/articles/delete-a-company-and-all-related-transactions", + url: docsUrl + "user/manual/en/setting-up/articles/delete-a-company-and-all-related-transactions", }, ]; @@ -511,9 +477,7 @@ frappe.help.help_links["Tree/Account"] = [ }, { label: "Managing Tree Mastes", - url: - docsUrl + - "user/manual/en/setting-up/articles/managing-tree-structure-masters", + url: docsUrl + "user/manual/en/setting-up/articles/managing-tree-structure-masters", }, ]; @@ -648,8 +612,7 @@ frappe.help.help_links["List/Item"] = [ }, { label: "Barcode", - url: - docsUrl + "user/manual/en/stock/articles/track-items-using-barcode", + url: docsUrl + "user/manual/en/stock/articles/track-items-using-barcode", }, { label: "Item Wise Taxation", @@ -669,9 +632,7 @@ frappe.help.help_links["List/Item"] = [ }, { label: "Item Valuation", - url: - docsUrl + - "user/manual/en/stock/articles/item-valuation-fifo-and-moving-average", + url: docsUrl + "user/manual/en/stock/articles/item-valuation-fifo-and-moving-average", }, ]; @@ -683,8 +644,7 @@ frappe.help.help_links["Form/Item"] = [ }, { label: "Barcode", - url: - docsUrl + "user/manual/en/stock/articles/track-items-using-barcode", + url: docsUrl + "user/manual/en/stock/articles/track-items-using-barcode", }, { label: "Item Wise Taxation", @@ -704,9 +664,7 @@ frappe.help.help_links["Form/Item"] = [ }, { label: "Item Valuation", - url: - docsUrl + - "user/manual/en/stock/item/item-valuation-fifo-and-moving-average", + url: docsUrl + "user/manual/en/stock/item/item-valuation-fifo-and-moving-average", }, ]; @@ -717,8 +675,7 @@ frappe.help.help_links["List/Purchase Receipt"] = [ }, { label: "Barcode", - url: - docsUrl + "user/manual/en/stock/articles/track-items-using-barcode", + url: docsUrl + "user/manual/en/stock/articles/track-items-using-barcode", }, ]; @@ -729,8 +686,7 @@ frappe.help.help_links["List/Delivery Note"] = [ }, { label: "Barcode", - url: - docsUrl + "user/manual/en/stock/articles/track-items-using-barcode", + url: docsUrl + "user/manual/en/stock/articles/track-items-using-barcode", }, { label: "Sales Return", @@ -749,8 +705,7 @@ frappe.help.help_links["Form/Delivery Note"] = [ }, { label: "Barcode", - url: - docsUrl + "user/manual/en/stock/articles/track-items-using-barcode", + url: docsUrl + "user/manual/en/stock/articles/track-items-using-barcode", }, ]; @@ -772,9 +727,7 @@ frappe.help.help_links["List/Material Request"] = [ }, { label: "Auto-creation of Material Request", - url: - docsUrl + - "user/manual/en/stock/articles/auto-creation-of-material-request", + url: docsUrl + "user/manual/en/stock/articles/auto-creation-of-material-request", }, ]; @@ -785,9 +738,7 @@ frappe.help.help_links["Form/Material Request"] = [ }, { label: "Auto-creation of Material Request", - url: - docsUrl + - "user/manual/en/stock/articles/auto-creation-of-material-request", + url: docsUrl + "user/manual/en/stock/articles/auto-creation-of-material-request", }, ]; @@ -827,13 +778,9 @@ frappe.help.help_links["Form/Serial No"] = [ { label: "Serial No", url: docsUrl + "user/manual/en/stock/serial-no" }, ]; -frappe.help.help_links["List/Batch"] = [ - { label: "Batch", url: docsUrl + "user/manual/en/stock/batch" }, -]; +frappe.help.help_links["List/Batch"] = [{ label: "Batch", url: docsUrl + "user/manual/en/stock/batch" }]; -frappe.help.help_links["Form/Batch"] = [ - { label: "Batch", url: docsUrl + "user/manual/en/stock/batch" }, -]; +frappe.help.help_links["Form/Batch"] = [{ label: "Batch", url: docsUrl + "user/manual/en/stock/batch" }]; frappe.help.help_links["Form/Packing Slip"] = [ { @@ -873,8 +820,7 @@ frappe.help.help_links["Form/Item Attribute"] = [ frappe.help.help_links["Form/UOM"] = [ { label: "Fractions in UOM", - url: - docsUrl + "user/manual/en/stock/articles/managing-fractions-in-uom", + url: docsUrl + "user/manual/en/stock/articles/managing-fractions-in-uom", }, ]; @@ -887,21 +833,15 @@ frappe.help.help_links["Form/Stock Reconciliation"] = [ //CRM -frappe.help.help_links["Form/Lead"] = [ - { label: "Lead", url: docsUrl + "user/manual/en/CRM/lead" }, -]; +frappe.help.help_links["Form/Lead"] = [{ label: "Lead", url: docsUrl + "user/manual/en/CRM/lead" }]; frappe.help.help_links["Form/Opportunity"] = [ { label: "Opportunity", url: docsUrl + "user/manual/en/CRM/opportunity" }, ]; -frappe.help.help_links["Form/Address"] = [ - { label: "Address", url: docsUrl + "user/manual/en/CRM/address" }, -]; +frappe.help.help_links["Form/Address"] = [{ label: "Address", url: docsUrl + "user/manual/en/CRM/address" }]; -frappe.help.help_links["Form/Contact"] = [ - { label: "Contact", url: docsUrl + "user/manual/en/CRM/contact" }, -]; +frappe.help.help_links["Form/Contact"] = [{ label: "Contact", url: docsUrl + "user/manual/en/CRM/contact" }]; frappe.help.help_links["Form/Newsletter"] = [ { label: "Newsletter", url: docsUrl + "user/manual/en/CRM/newsletter" }, @@ -921,15 +861,11 @@ frappe.help.help_links["Tree/Sales Person"] = [ frappe.help.help_links["Form/Sales Person"] = [ { label: "Sales Person Target", - url: - docsUrl + - "user/manual/en/selling/sales-person-target-allocation", + url: docsUrl + "user/manual/en/selling/sales-person-target-allocation", }, { label: "Sales Person in Transactions", - url: - docsUrl + - "user/manual/en/selling/articles/sales-persons-in-the-sales-transactions", + url: docsUrl + "user/manual/en/selling/articles/sales-persons-in-the-sales-transactions", }, ]; @@ -942,9 +878,7 @@ frappe.help.help_links["Form/BOM"] = [ }, { label: "Nested BOM Structure", - url: - docsUrl + - "user/manual/en/manufacturing/articles/managing-multi-level-bom", + url: docsUrl + "user/manual/en/manufacturing/articles/managing-multi-level-bom", }, ]; diff --git a/erpnext/public/js/hierarchy_chart/hierarchy_chart_desktop.js b/erpnext/public/js/hierarchy_chart/hierarchy_chart_desktop.js index 516c98a143db..013ace62d748 100644 --- a/erpnext/public/js/hierarchy_chart/hierarchy_chart_desktop.js +++ b/erpnext/public/js/hierarchy_chart/hierarchy_chart_desktop.js @@ -1,4 +1,4 @@ -import html2canvas from 'html2canvas'; +import html2canvas from "html2canvas"; erpnext.HierarchyChart = class { /* Options: - doctype @@ -13,7 +13,7 @@ erpnext.HierarchyChart = class { this.doctype = doctype; this.setup_page_style(); - this.page.main.addClass('frappe-card'); + this.page.main.addClass("frappe-card"); this.nodes = {}; this.setup_node_class(); @@ -21,10 +21,10 @@ erpnext.HierarchyChart = class { setup_page_style() { this.page.main.css({ - 'min-height': '300px', - 'max-height': '600px', - 'overflow': 'auto', - 'position': 'relative' + "min-height": "300px", + "max-height": "600px", + overflow: "auto", + position: "relative", }); } @@ -32,7 +32,15 @@ erpnext.HierarchyChart = class { let me = this; this.Node = class { constructor({ - id, parent, parent_id, image, name, title, expandable, connections, is_root // eslint-disable-line + id, + parent, + parent_id, + image, + name, + title, + expandable, + connections, + is_root, // eslint-disable-line }) { // to setup values passed via constructor $.extend(this, arguments[0]); @@ -52,14 +60,14 @@ erpnext.HierarchyChart = class { } make_node_element(node) { - let node_card = frappe.render_template('node_card', { + let node_card = frappe.render_template("node_card", { id: node.id, name: node.name, title: node.title, image: node.image, parent: node.parent_id, connections: node.connections, - is_mobile: false + is_mobile: false, }); node.parent.append(node_card); @@ -72,16 +80,16 @@ erpnext.HierarchyChart = class { let me = this; let company = this.page.add_field({ - fieldtype: 'Link', - options: 'Company', - fieldname: 'company', - placeholder: __('Select Company'), - default: frappe.defaults.get_default('company'), + fieldtype: "Link", + options: "Company", + fieldname: "company", + placeholder: __("Select Company"), + default: frappe.defaults.get_default("company"), only_select: true, reqd: 1, change: () => { - me.company = ''; - $('#hierarchy-chart-wrapper').remove(); + me.company = ""; + $("#hierarchy-chart-wrapper").remove(); if (company.get_value()) { me.company = company.get_value(); @@ -92,75 +100,76 @@ erpnext.HierarchyChart = class { me.render_root_nodes(); me.all_nodes_expanded = false; } else { - frappe.throw(__('Please select a company first.')); + frappe.throw(__("Please select a company first.")); } - } + }, }); company.refresh(); - $(`[data-fieldname="company"]`).trigger('change'); - $(`[data-fieldname="company"] .link-field`).css('z-index', 2); + $(`[data-fieldname="company"]`).trigger("change"); + $(`[data-fieldname="company"] .link-field`).css("z-index", 2); } setup_actions() { let me = this; this.page.clear_inner_toolbar(); - this.page.add_inner_button(__('Export'), function() { + this.page.add_inner_button(__("Export"), function () { me.export_chart(); }); - this.page.add_inner_button(__('Expand All'), function() { + this.page.add_inner_button(__("Expand All"), function () { me.load_children(me.root_node, true); me.all_nodes_expanded = true; - me.page.remove_inner_button(__('Expand All')); - me.page.add_inner_button(__('Collapse All'), function() { + me.page.remove_inner_button(__("Expand All")); + me.page.add_inner_button(__("Collapse All"), function () { me.setup_hierarchy(); me.render_root_nodes(); me.all_nodes_expanded = false; - me.page.remove_inner_button(__('Collapse All')); + me.page.remove_inner_button(__("Collapse All")); me.setup_actions(); }); }); } export_chart() { - frappe.dom.freeze(__('Exporting...')); + frappe.dom.freeze(__("Exporting...")); this.page.main.css({ - 'min-height': '', - 'max-height': '', - 'overflow': 'visible', - 'position': 'fixed', - 'left': '0', - 'top': '0' + "min-height": "", + "max-height": "", + overflow: "visible", + position: "fixed", + left: "0", + top: "0", }); - $('.node-card').addClass('exported'); + $(".node-card").addClass("exported"); - html2canvas(document.querySelector('#hierarchy-chart-wrapper'), { + html2canvas(document.querySelector("#hierarchy-chart-wrapper"), { scrollY: -window.scrollY, - scrollX: 0 - }).then(function(canvas) { - // Export the canvas to its data URI representation - let dataURL = canvas.toDataURL('image/png'); - - // download the image - let a = document.createElement('a'); - a.href = dataURL; - a.download = 'hierarchy_chart'; - a.click(); - }).finally(() => { - frappe.dom.unfreeze(); - }); + scrollX: 0, + }) + .then(function (canvas) { + // Export the canvas to its data URI representation + let dataURL = canvas.toDataURL("image/png"); + + // download the image + let a = document.createElement("a"); + a.href = dataURL; + a.download = "hierarchy_chart"; + a.click(); + }) + .finally(() => { + frappe.dom.unfreeze(); + }); this.setup_page_style(); - $('.node-card').removeClass('exported'); + $(".node-card").removeClass("exported"); } setup_hierarchy() { - if (this.$hierarchy) - this.$hierarchy.remove(); + if (this.$hierarchy) this.$hierarchy.remove(); $(`#connectors`).empty(); @@ -170,18 +179,16 @@ erpnext.HierarchyChart = class {
    • - `); + ` + ); - this.page.main - .find('#hierarchy-chart') - .empty() - .append(this.$hierarchy); + this.page.main.find("#hierarchy-chart").empty().append(this.$hierarchy); this.nodes = {}; } make_svg_markers() { - $('#hierarchy-chart-wrapper').remove(); + $("#hierarchy-chart-wrapper").remove(); this.page.main.append(`
      @@ -209,45 +216,47 @@ erpnext.HierarchyChart = class {
      `); } - render_root_nodes(expanded_view=false) { + render_root_nodes(expanded_view = false) { let me = this; - return frappe.call({ - method: me.method, - args: { - company: me.company - } - }).then(r => { - if (r.message.length) { - let expand_node; - let node; - - $.each(r.message, (_i, data) => { - if ($(`[id="${data.id}"]`).length) - return; - - node = new me.Node({ - id: data.id, - parent: $('
    • ').appendTo(me.$hierarchy.find('.node-children')), - parent_id: '', - image: data.image, - name: data.name, - title: data.title, - expandable: true, - connections: data.connections, - is_root: true + return frappe + .call({ + method: me.method, + args: { + company: me.company, + }, + }) + .then((r) => { + if (r.message.length) { + let expand_node; + let node; + + $.each(r.message, (_i, data) => { + if ($(`[id="${data.id}"]`).length) return; + + node = new me.Node({ + id: data.id, + parent: $('
    • ').appendTo( + me.$hierarchy.find(".node-children") + ), + parent_id: "", + image: data.image, + name: data.name, + title: data.title, + expandable: true, + connections: data.connections, + is_root: true, + }); + + if (!expand_node && data.connections) expand_node = node; }); - if (!expand_node && data.connections) - expand_node = node; - }); - - me.root_node = expand_node; - if (!expanded_view) { - me.expand_node(expand_node); + me.root_node = expand_node; + if (!expanded_view) { + me.expand_node(expand_node); + } } - } - }); + }); } expand_node(node) { @@ -263,7 +272,7 @@ erpnext.HierarchyChart = class { this.refresh_connectors(node.parent_id); // rebuild incoming connections - let grandparent = $(`[id="${node.parent_id}"]`).attr('data-parent'); + let grandparent = $(`[id="${node.parent_id}"]`).attr("data-parent"); this.refresh_connectors(grandparent); } @@ -282,18 +291,18 @@ erpnext.HierarchyChart = class { show_active_path(node) { // mark node parent on active path - $(`[id="${node.parent_id}"]`).addClass('active-path'); + $(`[id="${node.parent_id}"]`).addClass("active-path"); } - load_children(node, deep=false) { + load_children(node, deep = false) { if (!this.company) { - frappe.throw(__('Please select a company first.')); + frappe.throw(__("Please select a company first.")); } if (!deep) { frappe.run_serially([ () => this.get_child_nodes(node.id), - (child_nodes) => this.render_child_nodes(node, child_nodes) + (child_nodes) => this.render_child_nodes(node, child_nodes), ]); } else { frappe.run_serially([ @@ -302,26 +311,28 @@ erpnext.HierarchyChart = class { () => this.render_root_nodes(true), () => this.get_all_nodes(), (data_list) => this.render_children_of_all_nodes(data_list), - () => frappe.dom.unfreeze() + () => frappe.dom.unfreeze(), ]); } } get_child_nodes(node_id) { let me = this; - return new Promise(resolve => { - frappe.call({ - method: me.method, - args: { - parent: node_id, - company: me.company - } - }).then(r => resolve(r.message)); + return new Promise((resolve) => { + frappe + .call({ + method: me.method, + args: { + parent: node_id, + company: me.company, + }, + }) + .then((r) => resolve(r.message)); }); } render_child_nodes(node, child_nodes) { - const last_level = this.$hierarchy.find('.level:last').index(); + const last_level = this.$hierarchy.find(".level:last").index(); const current_level = $(`[id="${node.id}"]`).parent().parent().parent().index(); if (last_level === current_level) { @@ -333,7 +344,7 @@ erpnext.HierarchyChart = class { if (!node.$children) { node.$children = $('
        ') .hide() - .appendTo(this.$hierarchy.find('.level:last')); + .appendTo(this.$hierarchy.find(".level:last")); node.$children.empty(); @@ -356,16 +367,16 @@ erpnext.HierarchyChart = class { get_all_nodes() { let me = this; - return new Promise(resolve => { + return new Promise((resolve) => { frappe.call({ - method: 'erpnext.utilities.hierarchy_chart.get_all_nodes', + method: "erpnext.utilities.hierarchy_chart.get_all_nodes", args: { method: me.method, - company: me.company + company: me.company, }, callback: (r) => { resolve(r.message); - } + }, }); }); } @@ -389,16 +400,16 @@ erpnext.HierarchyChart = class { render_child_nodes_for_expanded_view(node, child_nodes) { node.$children = $('
          '); - const last_level = this.$hierarchy.find('.level:last').index(); + const last_level = this.$hierarchy.find(".level:last").index(); const node_level = $(`[id="${node.id}"]`).parent().parent().parent().index(); if (last_level === node_level) { this.$hierarchy.append(`
        • `); - node.$children.appendTo(this.$hierarchy.find('.level:last')); + node.$children.appendTo(this.$hierarchy.find(".level:last")); } else { - node.$children.appendTo(this.$hierarchy.find('.level:eq(' + (node_level + 1) + ')')); + node.$children.appendTo(this.$hierarchy.find(".level:eq(" + (node_level + 1) + ")")); } node.$children.hide().empty(); @@ -436,33 +447,40 @@ erpnext.HierarchyChart = class { const parent_node = document.getElementById(`${parent_id}`); const child_node = document.getElementById(`${child_id}`); - let path = document.createElementNS('http://www.w3.org/2000/svg', 'path'); + let path = document.createElementNS("http://www.w3.org/2000/svg", "path"); // we need to connect right side of the parent to the left side of the child node const pos_parent_right = { x: parent_node.offsetLeft + parent_node.offsetWidth, - y: parent_node.offsetTop + parent_node.offsetHeight / 2 + y: parent_node.offsetTop + parent_node.offsetHeight / 2, }; const pos_child_left = { x: child_node.offsetLeft - 5, - y: child_node.offsetTop + child_node.offsetHeight / 2 + y: child_node.offsetTop + child_node.offsetHeight / 2, }; const connector = this.get_connector(pos_parent_right, pos_child_left); - path.setAttribute('d', connector); + path.setAttribute("d", connector); this.set_path_attributes(path, parent_id, child_id); - document.getElementById('connectors').appendChild(path); + document.getElementById("connectors").appendChild(path); } get_connector(pos_parent_right, pos_child_left) { if (pos_parent_right.y === pos_child_left.y) { // don't add arcs if it's a straight line - return "M" + - (pos_parent_right.x) + "," + (pos_parent_right.y) + " " + - "L"+ - (pos_child_left.x) + "," + (pos_child_left.y); + return ( + "M" + + pos_parent_right.x + + "," + + pos_parent_right.y + + " " + + "L" + + pos_child_left.x + + "," + + pos_child_left.y + ); } else { let arc_1 = ""; let arc_2 = ""; @@ -482,15 +500,29 @@ erpnext.HierarchyChart = class { offset = -10; } - return "M" + (pos_parent_right.x) + "," + (pos_parent_right.y) + " " + + return ( + "M" + + pos_parent_right.x + + "," + + pos_parent_right.y + + " " + "L" + - (pos_parent_right.x + 40) + "," + (pos_parent_right.y) + " " + + (pos_parent_right.x + 40) + + "," + + pos_parent_right.y + + " " + arc_1 + "L" + - (pos_parent_right.x + 50) + "," + (pos_child_left.y + offset) + " " + + (pos_parent_right.x + 50) + + "," + + (pos_child_left.y + offset) + + " " + arc_2 + - "L"+ - (pos_child_left.x) + "," + (pos_child_left.y); + "L" + + pos_child_left.x + + "," + + pos_child_left.y + ); } } @@ -499,7 +531,7 @@ erpnext.HierarchyChart = class { path.setAttribute("data-child", child_id); const parent = $(`[id="${parent_id}"]`); - if (parent.hasClass('active')) { + if (parent.hasClass("active")) { path.setAttribute("class", "active-connector"); path.setAttribute("marker-start", "url(#arrowstart-active)"); path.setAttribute("marker-end", "url(#arrowhead-active)"); @@ -512,24 +544,23 @@ erpnext.HierarchyChart = class { set_selected_node(node) { // remove active class from the current node - if (this.selected_node) - this.selected_node.$link.removeClass('active'); + if (this.selected_node) this.selected_node.$link.removeClass("active"); // add active class to the newly selected node this.selected_node = node; - node.$link.addClass('active'); + node.$link.addClass("active"); } collapse_previous_level_nodes(node) { let node_parent = $(`[id="${node.parent_id}"]`); - let previous_level_nodes = node_parent.parent().parent().children('li'); + let previous_level_nodes = node_parent.parent().parent().children("li"); let node_card; - previous_level_nodes.each(function() { - node_card = $(this).find('.node-card'); + previous_level_nodes.each(function () { + node_card = $(this).find(".node-card"); - if (!node_card.hasClass('active-path')) { - node_card.addClass('collapsed'); + if (!node_card.hasClass("active-path")) { + node_card.addClass("collapsed"); } }); } @@ -547,7 +578,7 @@ erpnext.HierarchyChart = class { this.add_connector(node_parent, data.id); }); } - } + }, ]); } @@ -555,13 +586,15 @@ erpnext.HierarchyChart = class { let me = this; let node_element = $(`[id="${node.id}"]`); - node_element.click(function() { + node_element.click(function () { const is_sibling = me.selected_node.parent_id === node.parent_id; if (is_sibling) { me.collapse_node(); - } else if (node_element.is(':visible') - && (node_element.hasClass('collapsed') || node_element.hasClass('active-path'))) { + } else if ( + node_element.is(":visible") && + (node_element.hasClass("collapsed") || node_element.hasClass("active-path")) + ) { me.remove_levels_after_node(node); me.remove_orphaned_connectors(); } @@ -574,18 +607,18 @@ erpnext.HierarchyChart = class { let node_element = $(`[id="${node.id}"]`); let me = this; - node_element.find('.btn-edit-node').click(function() { - frappe.set_route('Form', me.doctype, node.id); + node_element.find(".btn-edit-node").click(function () { + frappe.set_route("Form", me.doctype, node.id); }); } remove_levels_after_node(node) { let level = $(`[id="${node.id}"]`).parent().parent().parent().index(); - level = $('.hierarchy > li:eq('+ level + ')'); - level.nextAll('li').remove(); + level = $(".hierarchy > li:eq(" + level + ")"); + level.nextAll("li").remove(); - let nodes = level.find('.node-card'); + let nodes = level.find(".node-card"); let node_object; $.each(nodes, (_i, element) => { @@ -594,17 +627,16 @@ erpnext.HierarchyChart = class { node_object.$children = null; }); - nodes.removeClass('collapsed active-path'); + nodes.removeClass("collapsed active-path"); } remove_orphaned_connectors() { - let paths = $('#connectors > path'); + let paths = $("#connectors > path"); $.each(paths, (_i, path) => { - const parent = $(path).data('parent'); - const child = $(path).data('child'); + const parent = $(path).data("parent"); + const child = $(path).data("child"); - if ($(`[id="${parent}"]`).length && $(`[id="${child}"]`).length) - return; + if ($(`[id="${parent}"]`).length && $(`[id="${child}"]`).length) return; $(path).remove(); }); diff --git a/erpnext/public/js/hierarchy_chart/hierarchy_chart_mobile.js b/erpnext/public/js/hierarchy_chart/hierarchy_chart_mobile.js index 512ea508a9d0..e8fa078b6fef 100644 --- a/erpnext/public/js/hierarchy_chart/hierarchy_chart_mobile.js +++ b/erpnext/public/js/hierarchy_chart/hierarchy_chart_mobile.js @@ -12,12 +12,12 @@ erpnext.HierarchyChartMobile = class { this.doctype = doctype; this.page.main.css({ - 'min-height': '300px', - 'max-height': '600px', - 'overflow': 'auto', - 'position': 'relative' + "min-height": "300px", + "max-height": "600px", + overflow: "auto", + position: "relative", }); - this.page.main.addClass('frappe-card'); + this.page.main.addClass("frappe-card"); this.nodes = {}; this.setup_node_class(); @@ -27,7 +27,15 @@ erpnext.HierarchyChartMobile = class { let me = this; this.Node = class { constructor({ - id, parent, parent_id, image, name, title, expandable, connections, is_root // eslint-disable-line + id, + parent, + parent_id, + image, + name, + title, + expandable, + connections, + is_root, // eslint-disable-line }) { // to setup values passed via constructor $.extend(this, arguments[0]); @@ -43,19 +51,19 @@ erpnext.HierarchyChartMobile = class { } make_node_element(node) { - let node_card = frappe.render_template('node_card', { + let node_card = frappe.render_template("node_card", { id: node.id, name: node.name, title: node.title, image: node.image, parent: node.parent_id, connections: node.connections, - is_mobile: true + is_mobile: true, }); node.parent.append(node_card); node.$link = $(`[id="${node.id}"]`); - node.$link.addClass('mobile-node'); + node.$link.addClass("mobile-node"); } show() { @@ -63,15 +71,15 @@ erpnext.HierarchyChartMobile = class { let me = this; let company = this.page.add_field({ - fieldtype: 'Link', - options: 'Company', - fieldname: 'company', - placeholder: __('Select Company'), - default: frappe.defaults.get_default('company'), + fieldtype: "Link", + options: "Company", + fieldname: "company", + placeholder: __("Select Company"), + default: frappe.defaults.get_default("company"), only_select: true, reqd: 1, change: () => { - me.company = ''; + me.company = ""; if (company.get_value() && me.company != company.get_value()) { me.company = company.get_value(); @@ -79,8 +87,7 @@ erpnext.HierarchyChartMobile = class { // svg for connectors me.make_svg_markers(); - if (me.$sibling_group) - me.$sibling_group.remove(); + if (me.$sibling_group) me.$sibling_group.remove(); // setup sibling group wrapper me.$sibling_group = $(`
          `); @@ -89,15 +96,15 @@ erpnext.HierarchyChartMobile = class { me.setup_hierarchy(); me.render_root_nodes(); } - } + }, }); company.refresh(); - $(`[data-fieldname="company"]`).trigger('change'); + $(`[data-fieldname="company"]`).trigger("change"); } make_svg_markers() { - $('#arrows').remove(); + $("#arrows").remove(); this.page.main.prepend(` @@ -123,16 +130,15 @@ erpnext.HierarchyChartMobile = class { setup_hierarchy() { $(`#connectors`).empty(); - if (this.$hierarchy) - this.$hierarchy.remove(); + if (this.$hierarchy) this.$hierarchy.remove(); - if (this.$sibling_group) - this.$sibling_group.empty(); + if (this.$sibling_group) this.$sibling_group.empty(); this.$hierarchy = $( `
          • -
          `); + ` + ); this.page.main.append(this.$hierarchy); } @@ -140,42 +146,43 @@ erpnext.HierarchyChartMobile = class { render_root_nodes() { let me = this; - frappe.call({ - method: me.method, - args: { - company: me.company - }, - }).then(r => { - if (r.message.length) { - let root_level = me.$hierarchy.find('.root-level'); - root_level.empty(); - - $.each(r.message, (_i, data) => { - return new me.Node({ - id: data.id, - parent: root_level, - parent_id: '', - image: data.image, - name: data.name, - title: data.title, - expandable: true, - connections: data.connections, - is_root: true + frappe + .call({ + method: me.method, + args: { + company: me.company, + }, + }) + .then((r) => { + if (r.message.length) { + let root_level = me.$hierarchy.find(".root-level"); + root_level.empty(); + + $.each(r.message, (_i, data) => { + return new me.Node({ + id: data.id, + parent: root_level, + parent_id: "", + image: data.image, + name: data.name, + title: data.title, + expandable: true, + connections: data.connections, + is_root: true, + }); }); - }); - } - }); + } + }); } expand_node(node) { - const is_same_node = (this.selected_node && this.selected_node.id === node.id); + const is_same_node = this.selected_node && this.selected_node.id === node.id; this.set_selected_node(node); this.show_active_path(node); if (this.$sibling_group) { - const sibling_parent = this.$sibling_group.find('.node-group').attr('data-parent'); - if (node.parent_id != '' && node.parent_id != sibling_parent) - this.$sibling_group.empty(); + const sibling_parent = this.$sibling_group.find(".node-group").attr("data-parent"); + if (node.parent_id != "" && node.parent_id != sibling_parent) this.$sibling_group.empty(); } if (!is_same_node) { @@ -184,7 +191,7 @@ erpnext.HierarchyChartMobile = class { this.refresh_connectors(node.parent_id, node.id); // rebuild incoming connections of parent - let grandparent = $(`[id="${node.parent_id}"]`).attr('data-parent'); + let grandparent = $(`[id="${node.parent_id}"]`).attr("data-parent"); this.refresh_connectors(grandparent, node.parent_id); } @@ -202,65 +209,61 @@ erpnext.HierarchyChartMobile = class { // add a collapsed level to show the collapsed parent // and a button beside it to move to that level let node_parent = node.$link.parent(); - node_parent.prepend( - `
          ` - ); + node_parent.prepend(`
          `); - node_parent - .find('.collapsed-level') - .append(node.$link); + node_parent.find(".collapsed-level").append(node.$link); frappe.run_serially([ () => this.get_child_nodes(node.parent_id, node.id), (child_nodes) => this.get_node_group(child_nodes, node.parent_id), - (node_group) => node_parent.find('.collapsed-level').append(node_group), - () => this.setup_node_group_action() + (node_group) => node_parent.find(".collapsed-level").append(node_group), + () => this.setup_node_group_action(), ]); } } show_active_path(node) { // mark node parent on active path - $(`[id="${node.parent_id}"]`).addClass('active-path'); + $(`[id="${node.parent_id}"]`).addClass("active-path"); } load_children(node) { if (!this.company) { - frappe.throw(__('Please select a company first')); + frappe.throw(__("Please select a company first")); } frappe.run_serially([ () => this.get_child_nodes(node.id), - (child_nodes) => this.render_child_nodes(node, child_nodes) + (child_nodes) => this.render_child_nodes(node, child_nodes), ]); } - get_child_nodes(node_id, exclude_node=null) { + get_child_nodes(node_id, exclude_node = null) { let me = this; - return new Promise(resolve => { - frappe.call({ - method: me.method, - args: { - parent: node_id, - company: me.company, - exclude_node: exclude_node - } - }).then(r => resolve(r.message)); + return new Promise((resolve) => { + frappe + .call({ + method: me.method, + args: { + parent: node_id, + company: me.company, + exclude_node: exclude_node, + }, + }) + .then((r) => resolve(r.message)); }); } render_child_nodes(node, child_nodes) { if (!node.$children) { - node.$children = $('
            ') - .hide() - .appendTo(node.$link.parent()); + node.$children = $('
              ').hide().appendTo(node.$link.parent()); node.$children.empty(); if (child_nodes) { $.each(child_nodes, (_i, data) => { this.add_node(node, data); - $(`[id="${data.id}"]`).addClass('active-child'); + $(`[id="${data.id}"]`).addClass("active-child"); setTimeout(() => { this.add_connector(node.id, data.id); @@ -285,7 +288,7 @@ erpnext.HierarchyChartMobile = class { title: data.title, expandable: data.expandable, connections: data.connections, - children: null + children: null, }); } @@ -293,41 +296,49 @@ erpnext.HierarchyChartMobile = class { const parent_node = document.getElementById(`${parent_id}`); const child_node = document.getElementById(`${child_id}`); - const path = document.createElementNS('http://www.w3.org/2000/svg', 'path'); + const path = document.createElementNS("http://www.w3.org/2000/svg", "path"); let connector = null; - if ($(`[id="${parent_id}"]`).hasClass('active')) { + if ($(`[id="${parent_id}"]`).hasClass("active")) { connector = this.get_connector_for_active_node(parent_node, child_node); - } else if ($(`[id="${parent_id}"]`).hasClass('active-path')) { + } else if ($(`[id="${parent_id}"]`).hasClass("active-path")) { connector = this.get_connector_for_collapsed_node(parent_node, child_node); } - path.setAttribute('d', connector); + path.setAttribute("d", connector); this.set_path_attributes(path, parent_id, child_id); - document.getElementById('connectors').appendChild(path); + document.getElementById("connectors").appendChild(path); } get_connector_for_active_node(parent_node, child_node) { // we need to connect the bottom left of the parent to the left side of the child node let pos_parent_bottom = { x: parent_node.offsetLeft + 20, - y: parent_node.offsetTop + parent_node.offsetHeight + y: parent_node.offsetTop + parent_node.offsetHeight, }; let pos_child_left = { x: child_node.offsetLeft - 5, - y: child_node.offsetTop + child_node.offsetHeight / 2 + y: child_node.offsetTop + child_node.offsetHeight / 2, }; let connector = "M" + - (pos_parent_bottom.x) + "," + (pos_parent_bottom.y) + " " + + pos_parent_bottom.x + + "," + + pos_parent_bottom.y + + " " + "L" + - (pos_parent_bottom.x) + "," + (pos_child_left.y - 10) + " " + + pos_parent_bottom.x + + "," + + (pos_child_left.y - 10) + + " " + "a10,10 1 0 0 10,10 " + "L" + - (pos_child_left.x) + "," + (pos_child_left.y); + pos_child_left.x + + "," + + pos_child_left.y; return connector; } @@ -336,18 +347,23 @@ erpnext.HierarchyChartMobile = class { // we need to connect the bottom left of the parent to the top left of the child node let pos_parent_bottom = { x: parent_node.offsetLeft + 20, - y: parent_node.offsetTop + parent_node.offsetHeight + y: parent_node.offsetTop + parent_node.offsetHeight, }; let pos_child_top = { x: child_node.offsetLeft + 20, - y: child_node.offsetTop + y: child_node.offsetTop, }; let connector = "M" + - (pos_parent_bottom.x) + "," + (pos_parent_bottom.y) + " " + + pos_parent_bottom.x + + "," + + pos_parent_bottom.y + + " " + "L" + - (pos_child_top.x) + "," + (pos_child_top.y); + pos_child_top.x + + "," + + pos_child_top.y; return connector; } @@ -357,30 +373,29 @@ erpnext.HierarchyChartMobile = class { path.setAttribute("data-child", child_id); const parent = $(`[id="${parent_id}"]`); - if (parent.hasClass('active')) { + if (parent.hasClass("active")) { path.setAttribute("class", "active-connector"); path.setAttribute("marker-start", "url(#arrowstart-active)"); path.setAttribute("marker-end", "url(#arrowhead-active)"); - } else if (parent.hasClass('active-path')) { + } else if (parent.hasClass("active-path")) { path.setAttribute("class", "collapsed-connector"); } } set_selected_node(node) { // remove .active class from the current node - if (this.selected_node) - this.selected_node.$link.removeClass('active'); + if (this.selected_node) this.selected_node.$link.removeClass("active"); // add active class to the newly selected node this.selected_node = node; - node.$link.addClass('active'); + node.$link.addClass("active"); } setup_node_click_action(node) { let me = this; let node_element = $(`[id="${node.id}"]`); - node_element.click(function() { + node_element.click(function () { let el = null; if (node.is_root) { @@ -388,7 +403,7 @@ erpnext.HierarchyChartMobile = class { me.$hierarchy.empty(); $(`#connectors`).empty(); me.add_node_to_hierarchy(el, node); - } else if (node_element.is(':visible') && node_element.hasClass('active-path')) { + } else if (node_element.is(":visible") && node_element.hasClass("active-path")) { me.remove_levels_after_node(node); me.remove_orphaned_connectors(); } else { @@ -405,17 +420,17 @@ erpnext.HierarchyChartMobile = class { let node_element = $(`[id="${node.id}"]`); let me = this; - node_element.find('.btn-edit-node').click(function() { - frappe.set_route('Form', me.doctype, node.id); + node_element.find(".btn-edit-node").click(function () { + frappe.set_route("Form", me.doctype, node.id); }); } setup_node_group_action() { let me = this; - $('.node-group').on('click', function() { - let parent = $(this).attr('data-parent'); - if (parent == '') { + $(".node-group").on("click", function () { + let parent = $(this).attr("data-parent"); + if (parent == "") { me.setup_hierarchy(); me.render_root_nodes(); } else { @@ -426,8 +441,8 @@ erpnext.HierarchyChartMobile = class { add_node_to_hierarchy(node_element, node) { this.$hierarchy.append(`
            • `); - node_element.removeClass('active-child active-path'); - this.$hierarchy.find('.level:last').append(node_element); + node_element.removeClass("active-child active-path"); + this.$hierarchy.find(".level:last").append(node_element); let node_object = this.nodes[node.id]; node_object.expanded = 0; @@ -435,14 +450,12 @@ erpnext.HierarchyChartMobile = class { this.nodes[node.id] = node_object; } - get_node_group(nodes, parent, collapsed=true) { + get_node_group(nodes, parent, collapsed = true) { let limit = 2; const display_nodes = nodes.slice(0, limit); const extra_nodes = nodes.slice(limit); - let html = display_nodes.map(node => - this.get_avatar(node) - ).join(''); + let html = display_nodes.map((node) => this.get_avatar(node)).join(""); if (extra_nodes.length === 1) { let node = extra_nodes[0]; @@ -452,7 +465,7 @@ erpnext.HierarchyChartMobile = class { ${html}
              + title="${extra_nodes.map((node) => node.name).join(", ")}"> +${extra_nodes.length}
              @@ -460,15 +473,13 @@ erpnext.HierarchyChartMobile = class { } if (html) { - const $node_group = - $(`
              + const $node_group = $(`
              ${html}
              `); - if (collapsed) - $node_group.addClass('collapsed'); + if (collapsed) $node_group.addClass("collapsed"); return $node_group; } @@ -486,7 +497,7 @@ erpnext.HierarchyChartMobile = class { let node_object = this.nodes[parent]; let node = node_object.$link; - node.removeClass('active-child active-path'); + node.removeClass("active-child active-path"); node_object.expanded = 0; node_object.$children = null; this.nodes[node.id] = node_object; @@ -496,11 +507,10 @@ erpnext.HierarchyChartMobile = class { () => this.get_child_nodes(node_object.parent_id, node_object.id), (child_nodes) => this.get_node_group(child_nodes, node_object.parent_id, false), (node_group) => { - if (node_group) - this.$sibling_group.empty().append(node_group); + if (node_group) this.$sibling_group.empty().append(node_group); }, () => this.setup_node_group_action(), - () => this.reattach_and_expand_node(node, node_object) + () => this.reattach_and_expand_node(node, node_object), ]); } @@ -510,7 +520,7 @@ erpnext.HierarchyChartMobile = class { this.$hierarchy.empty().append(`
            • `); - this.$hierarchy.find('.level').append(el); + this.$hierarchy.find(".level").append(el); $(`#connectors`).empty(); this.expand_node(node_object); } @@ -518,13 +528,13 @@ erpnext.HierarchyChartMobile = class { remove_levels_after_node(node) { let level = $(`[id="${node.id}"]`).parent().parent().index(); - level = $('.hierarchy-mobile > li:eq('+ level + ')'); - level.nextAll('li').remove(); + level = $(".hierarchy-mobile > li:eq(" + level + ")"); + level.nextAll("li").remove(); let node_object = this.nodes[node.id]; let current_node = level.find(`[id="${node.id}"]`).detach(); - current_node.removeClass('active-child active-path'); + current_node.removeClass("active-child active-path"); node_object.expanded = 0; node_object.$children = null; @@ -533,13 +543,12 @@ erpnext.HierarchyChartMobile = class { } remove_orphaned_connectors() { - let paths = $('#connectors > path'); + let paths = $("#connectors > path"); $.each(paths, (_i, path) => { - const parent = $(path).data('parent'); - const child = $(path).data('child'); + const parent = $(path).data("parent"); + const child = $(path).data("child"); - if ($(`[id="${parent}"]`).length && $(`[id="${child}"]`).length) - return; + if ($(`[id="${parent}"]`).length && $(`[id="${child}"]`).length) return; $(path).remove(); }); diff --git a/erpnext/public/js/leaflet/leaflet.draw.js b/erpnext/public/js/leaflet/leaflet.draw.js index 26f1e19da5a8..534506187801 100755 --- a/erpnext/public/js/leaflet/leaflet.draw.js +++ b/erpnext/public/js/leaflet/leaflet.draw.js @@ -6,138 +6,1731 @@ http://leafletjs.com https://github.com/jacobtoye */ -! function(t, e) { - L.drawVersion = "0.2.3", L.drawLocal = { draw: { toolbar: { actions: { title: "Cancel drawing", text: "Cancel" }, undo: { title: "Delete last point drawn", text: "Delete last point" }, buttons: { polyline: "Draw a polyline", polygon: "Draw a polygon", rectangle: "Draw a rectangle", circle: "Draw a circle", marker: "Draw a marker" } }, handlers: { circle: { tooltip: { start: "Click and drag to draw circle." } }, marker: { tooltip: { start: "Click map to place marker." } }, polygon: { tooltip: { start: "Click to start drawing shape.", cont: "Click to continue drawing shape.", end: "Click first point to close this shape." } }, polyline: { error: "Error: shape edges cannot cross!", tooltip: { start: "Click to start drawing line.", cont: "Click to continue drawing line.", end: "Click last point to finish line." } }, rectangle: { tooltip: { start: "Click and drag to draw rectangle." } }, simpleshape: { tooltip: { end: "Release mouse to finish drawing." } } } }, edit: { toolbar: { actions: { save: { title: "Save changes.", text: "Save" }, cancel: { title: "Cancel editing, discards all changes.", text: "Cancel" } }, buttons: { edit: "Edit layers.", editDisabled: "No layers to edit.", remove: "Delete layers.", removeDisabled: "No layers to delete." } }, handlers: { edit: { tooltip: { text: "Drag handles, or marker to edit feature.", subtext: "Click cancel to undo changes." } }, remove: { tooltip: { text: "Click on a feature to remove" } } } } }, L.Draw = {}, L.Draw.Feature = L.Handler.extend({ includes: L.Mixin.Events, initialize: function(t, e) { this._map = t, this._container = t._container, this._overlayPane = t._panes.overlayPane, this._popupPane = t._panes.popupPane, e && e.shapeOptions && (e.shapeOptions = L.Util.extend({}, this.options.shapeOptions, e.shapeOptions)), L.setOptions(this, e) }, enable: function() { this._enabled || (this.fire("enabled", { handler: this.type }), this._map.fire("draw:drawstart", { layerType: this.type }), L.Handler.prototype.enable.call(this)) }, disable: function() { this._enabled && (L.Handler.prototype.disable.call(this), this._map.fire("draw:drawstop", { layerType: this.type }), this.fire("disabled", { handler: this.type })) }, addHooks: function() { var t = this._map; - t && (L.DomUtil.disableTextSelection(), t.getContainer().focus(), this._tooltip = new L.Tooltip(this._map), L.DomEvent.on(this._container, "keyup", this._cancelDrawing, this)) }, removeHooks: function() { this._map && (L.DomUtil.enableTextSelection(), this._tooltip.dispose(), this._tooltip = null, L.DomEvent.off(this._container, "keyup", this._cancelDrawing, this)) }, setOptions: function(t) { L.setOptions(this, t) }, _fireCreatedEvent: function(t) { this._map.fire("draw:created", { layer: t, layerType: this.type }) }, _cancelDrawing: function(t) { 27 === t.keyCode && this.disable() } }), L.Draw.Polyline = L.Draw.Feature.extend({ statics: { TYPE: "polyline" }, Poly: L.Polyline, options: { allowIntersection: !0, repeatMode: !1, drawError: { color: "#b00b00", timeout: 2500 }, icon: new L.DivIcon({ iconSize: new L.Point(8, 8), className: "leaflet-div-icon leaflet-editing-icon" }), guidelineDistance: 20, maxGuideLineLength: 4e3, shapeOptions: { stroke: !0, color: "#f06eaa", weight: 4, opacity: .5, fill: !1, clickable: !0 }, metric: !0, showLength: !0, zIndexOffset: 2e3 }, initialize: function(t, e) { this.options.drawError.message = L.drawLocal.draw.handlers.polyline.error, e && e.drawError && (e.drawError = L.Util.extend({}, this.options.drawError, e.drawError)), this.type = L.Draw.Polyline.TYPE, L.Draw.Feature.prototype.initialize.call(this, t, e) }, addHooks: function() { L.Draw.Feature.prototype.addHooks.call(this), this._map && (this._markers = [], this._markerGroup = new L.LayerGroup, this._map.addLayer(this._markerGroup), this._poly = new L.Polyline([], this.options.shapeOptions), this._tooltip.updateContent(this._getTooltipText()), this._mouseMarker || (this._mouseMarker = L.marker(this._map.getCenter(), { icon: L.divIcon({ className: "leaflet-mouse-marker", iconAnchor: [20, 20], iconSize: [40, 40] }), opacity: 0, zIndexOffset: this.options.zIndexOffset })), this._mouseMarker.on("mousedown", this._onMouseDown, this).addTo(this._map), this._map.on("mousemove", this._onMouseMove, this).on("mouseup", this._onMouseUp, this).on("zoomend", this._onZoomEnd, this)) }, removeHooks: function() { L.Draw.Feature.prototype.removeHooks.call(this), this._clearHideErrorTimeout(), this._cleanUpShape(), this._map.removeLayer(this._markerGroup), delete this._markerGroup, delete this._markers, this._map.removeLayer(this._poly), delete this._poly, this._mouseMarker.off("mousedown", this._onMouseDown, this).off("mouseup", this._onMouseUp, this), this._map.removeLayer(this._mouseMarker), delete this._mouseMarker, this._clearGuides(), this._map.off("mousemove", this._onMouseMove, this).off("zoomend", this._onZoomEnd, this) }, deleteLastVertex: function() { if (!(this._markers.length <= 1)) { var t = this._markers.pop(), - e = this._poly, - i = this._poly.spliceLatLngs(e.getLatLngs().length - 1, 1)[0]; - this._markerGroup.removeLayer(t), e.getLatLngs().length < 2 && this._map.removeLayer(e), this._vertexChanged(i, !1) } }, addVertex: function(t) { var e = this._markers.length; return e > 0 && !this.options.allowIntersection && this._poly.newLatLngIntersects(t) ? void this._showErrorTooltip() : (this._errorShown && this._hideErrorTooltip(), this._markers.push(this._createMarker(t)), this._poly.addLatLng(t), 2 === this._poly.getLatLngs().length && this._map.addLayer(this._poly), void this._vertexChanged(t, !0)) }, _finishShape: function() { var t = this._poly.newLatLngIntersects(this._poly.getLatLngs()[0], !0); return !this.options.allowIntersection && t || !this._shapeIsValid() ? void this._showErrorTooltip() : (this._fireCreatedEvent(), this.disable(), void(this.options.repeatMode && this.enable())) }, _shapeIsValid: function() { return !0 }, _onZoomEnd: function() { this._updateGuide() }, _onMouseMove: function(t) { var e = t.layerPoint, - i = t.latlng; - this._currentLatLng = i, this._updateTooltip(i), this._updateGuide(e), this._mouseMarker.setLatLng(i), L.DomEvent.preventDefault(t.originalEvent) }, _vertexChanged: function(t, e) { this._updateFinishHandler(), this._updateRunningMeasure(t, e), this._clearGuides(), this._updateTooltip() }, _onMouseDown: function(t) { var e = t.originalEvent; - this._mouseDownOrigin = L.point(e.clientX, e.clientY) }, _onMouseUp: function(e) { if (this._mouseDownOrigin) { var i = L.point(e.originalEvent.clientX, e.originalEvent.clientY).distanceTo(this._mouseDownOrigin); - Math.abs(i) < 9 * (t.devicePixelRatio || 1) && this.addVertex(e.latlng) } - this._mouseDownOrigin = null }, _updateFinishHandler: function() { var t = this._markers.length; - t > 1 && this._markers[t - 1].on("click", this._finishShape, this), t > 2 && this._markers[t - 2].off("click", this._finishShape, this) }, _createMarker: function(t) { var e = new L.Marker(t, { icon: this.options.icon, zIndexOffset: 2 * this.options.zIndexOffset }); return this._markerGroup.addLayer(e), e }, _updateGuide: function(t) { var e = this._markers.length; - e > 0 && (t = t || this._map.latLngToLayerPoint(this._currentLatLng), this._clearGuides(), this._drawGuide(this._map.latLngToLayerPoint(this._markers[e - 1].getLatLng()), t)) }, _updateTooltip: function(t) { var e = this._getTooltipText(); - t && this._tooltip.updatePosition(t), this._errorShown || this._tooltip.updateContent(e) }, _drawGuide: function(t, e) { var i, o, a, s = Math.floor(Math.sqrt(Math.pow(e.x - t.x, 2) + Math.pow(e.y - t.y, 2))), - r = this.options.guidelineDistance, - n = this.options.maxGuideLineLength, - l = s > n ? s - n : r; for (this._guidesContainer || (this._guidesContainer = L.DomUtil.create("div", "leaflet-draw-guides", this._overlayPane)); s > l; l += this.options.guidelineDistance) i = l / s, o = { x: Math.floor(t.x * (1 - i) + i * e.x), y: Math.floor(t.y * (1 - i) + i * e.y) }, a = L.DomUtil.create("div", "leaflet-draw-guide-dash", this._guidesContainer), a.style.backgroundColor = this._errorShown ? this.options.drawError.color : this.options.shapeOptions.color, L.DomUtil.setPosition(a, o) }, _updateGuideColor: function(t) { if (this._guidesContainer) - for (var e = 0, i = this._guidesContainer.childNodes.length; i > e; e++) this._guidesContainer.childNodes[e].style.backgroundColor = t }, _clearGuides: function() { if (this._guidesContainer) - for (; this._guidesContainer.firstChild;) this._guidesContainer.removeChild(this._guidesContainer.firstChild) }, _getTooltipText: function() { var t, e, i = this.options.showLength; return 0 === this._markers.length ? t = { text: L.drawLocal.draw.handlers.polyline.tooltip.start } : (e = i ? this._getMeasurementString() : "", t = 1 === this._markers.length ? { text: L.drawLocal.draw.handlers.polyline.tooltip.cont, subtext: e } : { text: L.drawLocal.draw.handlers.polyline.tooltip.end, subtext: e }), t }, _updateRunningMeasure: function(t, e) { var i, o, a = this._markers.length; - 1 === this._markers.length ? this._measurementRunningTotal = 0 : (i = a - (e ? 2 : 1), o = t.distanceTo(this._markers[i].getLatLng()), this._measurementRunningTotal += o * (e ? 1 : -1)) }, _getMeasurementString: function() { var t, e = this._currentLatLng, - i = this._markers[this._markers.length - 1].getLatLng(); return t = this._measurementRunningTotal + e.distanceTo(i), L.GeometryUtil.readableDistance(t, this.options.metric) }, _showErrorTooltip: function() { this._errorShown = !0, this._tooltip.showAsError().updateContent({ text: this.options.drawError.message }), this._updateGuideColor(this.options.drawError.color), this._poly.setStyle({ color: this.options.drawError.color }), this._clearHideErrorTimeout(), this._hideErrorTimeout = setTimeout(L.Util.bind(this._hideErrorTooltip, this), this.options.drawError.timeout) }, _hideErrorTooltip: function() { this._errorShown = !1, this._clearHideErrorTimeout(), this._tooltip.removeError().updateContent(this._getTooltipText()), this._updateGuideColor(this.options.shapeOptions.color), this._poly.setStyle({ color: this.options.shapeOptions.color }) }, _clearHideErrorTimeout: function() { this._hideErrorTimeout && (clearTimeout(this._hideErrorTimeout), this._hideErrorTimeout = null) }, _cleanUpShape: function() { this._markers.length > 1 && this._markers[this._markers.length - 1].off("click", this._finishShape, this) }, _fireCreatedEvent: function() { var t = new this.Poly(this._poly.getLatLngs(), this.options.shapeOptions); - L.Draw.Feature.prototype._fireCreatedEvent.call(this, t) } }), L.Draw.Polygon = L.Draw.Polyline.extend({ statics: { TYPE: "polygon" }, Poly: L.Polygon, options: { showArea: !1, shapeOptions: { stroke: !0, color: "#f06eaa", weight: 4, opacity: .5, fill: !0, fillColor: null, fillOpacity: .2, clickable: !0 } }, initialize: function(t, e) { L.Draw.Polyline.prototype.initialize.call(this, t, e), this.type = L.Draw.Polygon.TYPE }, _updateFinishHandler: function() { var t = this._markers.length; - 1 === t && this._markers[0].on("click", this._finishShape, this), t > 2 && (this._markers[t - 1].on("dblclick", this._finishShape, this), t > 3 && this._markers[t - 2].off("dblclick", this._finishShape, this)) }, _getTooltipText: function() { var t, e; return 0 === this._markers.length ? t = L.drawLocal.draw.handlers.polygon.tooltip.start : this._markers.length < 3 ? t = L.drawLocal.draw.handlers.polygon.tooltip.cont : (t = L.drawLocal.draw.handlers.polygon.tooltip.end, e = this._getMeasurementString()), { text: t, subtext: e } }, _getMeasurementString: function() { var t = this._area; return t ? L.GeometryUtil.readableArea(t, this.options.metric) : null }, _shapeIsValid: function() { return this._markers.length >= 3 }, _vertexAdded: function() { if (!this.options.allowIntersection && this.options.showArea) { var t = this._poly.getLatLngs(); - this._area = L.GeometryUtil.geodesicArea(t) } }, _cleanUpShape: function() { var t = this._markers.length; - t > 0 && (this._markers[0].off("click", this._finishShape, this), t > 2 && this._markers[t - 1].off("dblclick", this._finishShape, this)) } }), L.SimpleShape = {}, L.Draw.SimpleShape = L.Draw.Feature.extend({ options: { repeatMode: !1 }, initialize: function(t, e) { this._endLabelText = L.drawLocal.draw.handlers.simpleshape.tooltip.end, L.Draw.Feature.prototype.initialize.call(this, t, e) }, addHooks: function() { L.Draw.Feature.prototype.addHooks.call(this), this._map && (this._mapDraggable = this._map.dragging.enabled(), this._mapDraggable && this._map.dragging.disable(), this._container.style.cursor = "crosshair", this._tooltip.updateContent({ text: this._initialLabelText }), this._map.on("mousedown", this._onMouseDown, this).on("mousemove", this._onMouseMove, this)) }, removeHooks: function() { L.Draw.Feature.prototype.removeHooks.call(this), this._map && (this._mapDraggable && this._map.dragging.enable(), this._container.style.cursor = "", this._map.off("mousedown", this._onMouseDown, this).off("mousemove", this._onMouseMove, this), L.DomEvent.off(e, "mouseup", this._onMouseUp, this), this._shape && (this._map.removeLayer(this._shape), delete this._shape)), this._isDrawing = !1 }, _onMouseDown: function(t) { this._isDrawing = !0, this._startLatLng = t.latlng, L.DomEvent.on(e, "mouseup", this._onMouseUp, this).preventDefault(t.originalEvent) }, _onMouseMove: function(t) { var e = t.latlng; - this._tooltip.updatePosition(e), this._isDrawing && (this._tooltip.updateContent({ text: this._endLabelText }), this._drawShape(e)) }, _onMouseUp: function() { this._shape && this._fireCreatedEvent(), this.disable(), this.options.repeatMode && this.enable() } }), L.Draw.Rectangle = L.Draw.SimpleShape.extend({ statics: { TYPE: "rectangle" }, options: { shapeOptions: { stroke: !0, color: "#f06eaa", weight: 4, opacity: .5, fill: !0, fillColor: null, fillOpacity: .2, clickable: !0 } }, initialize: function(t, e) { this.type = L.Draw.Rectangle.TYPE, this._initialLabelText = L.drawLocal.draw.handlers.rectangle.tooltip.start, L.Draw.SimpleShape.prototype.initialize.call(this, t, e) }, _drawShape: function(t) { this._shape ? this._shape.setBounds(new L.LatLngBounds(this._startLatLng, t)) : (this._shape = new L.Rectangle(new L.LatLngBounds(this._startLatLng, t), this.options.shapeOptions), this._map.addLayer(this._shape)) }, _fireCreatedEvent: function() { var t = new L.Rectangle(this._shape.getBounds(), this.options.shapeOptions); - L.Draw.SimpleShape.prototype._fireCreatedEvent.call(this, t) } }), L.Draw.Circle = L.Draw.SimpleShape.extend({ statics: { TYPE: "circle" }, options: { shapeOptions: { stroke: !0, color: "#f06eaa", weight: 4, opacity: .5, fill: !0, fillColor: null, fillOpacity: .2, clickable: !0 }, showRadius: !0, metric: !0 }, initialize: function(t, e) { this.type = L.Draw.Circle.TYPE, this._initialLabelText = L.drawLocal.draw.handlers.circle.tooltip.start, L.Draw.SimpleShape.prototype.initialize.call(this, t, e) }, _drawShape: function(t) { this._shape ? this._shape.setRadius(this._startLatLng.distanceTo(t)) : (this._shape = new L.Circle(this._startLatLng, this._startLatLng.distanceTo(t), this.options.shapeOptions), this._map.addLayer(this._shape)) }, _fireCreatedEvent: function() { var t = new L.Circle(this._startLatLng, this._shape.getRadius(), this.options.shapeOptions); - L.Draw.SimpleShape.prototype._fireCreatedEvent.call(this, t) }, _onMouseMove: function(t) { var e, i = t.latlng, - o = this.options.showRadius, - a = this.options.metric; - this._tooltip.updatePosition(i), this._isDrawing && (this._drawShape(i), e = this._shape.getRadius().toFixed(1), this._tooltip.updateContent({ text: this._endLabelText, subtext: o ? "Radius: " + L.GeometryUtil.readableDistance(e, a) : "" })) } }), L.Draw.Marker = L.Draw.Feature.extend({ statics: { TYPE: "marker" }, options: { icon: new L.Icon.Default, repeatMode: !1, zIndexOffset: 2e3 }, initialize: function(t, e) { this.type = L.Draw.Marker.TYPE, L.Draw.Feature.prototype.initialize.call(this, t, e) }, addHooks: function() { L.Draw.Feature.prototype.addHooks.call(this), this._map && (this._tooltip.updateContent({ text: L.drawLocal.draw.handlers.marker.tooltip.start }), this._mouseMarker || (this._mouseMarker = L.marker(this._map.getCenter(), { icon: L.divIcon({ className: "leaflet-mouse-marker", iconAnchor: [20, 20], iconSize: [40, 40] }), opacity: 0, zIndexOffset: this.options.zIndexOffset })), this._mouseMarker.on("click", this._onClick, this).addTo(this._map), this._map.on("mousemove", this._onMouseMove, this)) }, removeHooks: function() { L.Draw.Feature.prototype.removeHooks.call(this), this._map && (this._marker && (this._marker.off("click", this._onClick, this), this._map.off("click", this._onClick, this).removeLayer(this._marker), delete this._marker), this._mouseMarker.off("click", this._onClick, this), this._map.removeLayer(this._mouseMarker), delete this._mouseMarker, this._map.off("mousemove", this._onMouseMove, this)) }, _onMouseMove: function(t) { var e = t.latlng; - this._tooltip.updatePosition(e), this._mouseMarker.setLatLng(e), this._marker ? (e = this._mouseMarker.getLatLng(), this._marker.setLatLng(e)) : (this._marker = new L.Marker(e, { icon: this.options.icon, zIndexOffset: this.options.zIndexOffset }), this._marker.on("click", this._onClick, this), this._map.on("click", this._onClick, this).addLayer(this._marker)) }, _onClick: function() { this._fireCreatedEvent(), this.disable(), this.options.repeatMode && this.enable() }, _fireCreatedEvent: function() { var t = new L.Marker(this._marker.getLatLng(), { icon: this.options.icon }); - L.Draw.Feature.prototype._fireCreatedEvent.call(this, t) } }), L.Edit = L.Edit || {}, L.Edit.Poly = L.Handler.extend({ options: { icon: new L.DivIcon({ iconSize: new L.Point(8, 8), className: "leaflet-div-icon leaflet-editing-icon" }) }, initialize: function(t, e) { this._poly = t, L.setOptions(this, e) }, addHooks: function() { this._poly._map && (this._markerGroup || this._initMarkers(), this._poly._map.addLayer(this._markerGroup)) }, removeHooks: function() { this._poly._map && (this._poly._map.removeLayer(this._markerGroup), delete this._markerGroup, delete this._markers) }, updateMarkers: function() { this._markerGroup.clearLayers(), this._initMarkers() }, _initMarkers: function() { this._markerGroup || (this._markerGroup = new L.LayerGroup), this._markers = []; var t, e, i, o, a = this._poly._latlngs; for (t = 0, i = a.length; i > t; t++) o = this._createMarker(a[t], t), o.on("click", this._onMarkerClick, this), this._markers.push(o); var s, r; for (t = 0, e = i - 1; i > t; e = t++)(0 !== t || L.Polygon && this._poly instanceof L.Polygon) && (s = this._markers[e], r = this._markers[t], this._createMiddleMarker(s, r), this._updatePrevNext(s, r)) }, _createMarker: function(t, e) { var i = new L.Marker(t, { draggable: !0, icon: this.options.icon }); return i._origLatLng = t, i._index = e, i.on("drag", this._onMarkerDrag, this), i.on("dragend", this._fireEdit, this), this._markerGroup.addLayer(i), i }, _removeMarker: function(t) { var e = t._index; - this._markerGroup.removeLayer(t), this._markers.splice(e, 1), this._poly.spliceLatLngs(e, 1), this._updateIndexes(e, -1), t.off("drag", this._onMarkerDrag, this).off("dragend", this._fireEdit, this).off("click", this._onMarkerClick, this) }, _fireEdit: function() { this._poly.edited = !0, this._poly.fire("edit") }, _onMarkerDrag: function(t) { var e = t.target; - L.extend(e._origLatLng, e._latlng), e._middleLeft && e._middleLeft.setLatLng(this._getMiddleLatLng(e._prev, e)), e._middleRight && e._middleRight.setLatLng(this._getMiddleLatLng(e, e._next)), this._poly.redraw() }, _onMarkerClick: function(t) { var e = L.Polygon && this._poly instanceof L.Polygon ? 4 : 3, - i = t.target; - this._poly._latlngs.length < e || (this._removeMarker(i), this._updatePrevNext(i._prev, i._next), i._middleLeft && this._markerGroup.removeLayer(i._middleLeft), i._middleRight && this._markerGroup.removeLayer(i._middleRight), i._prev && i._next ? this._createMiddleMarker(i._prev, i._next) : i._prev ? i._next || (i._prev._middleRight = null) : i._next._middleLeft = null, this._fireEdit()) }, _updateIndexes: function(t, e) { this._markerGroup.eachLayer(function(i) { i._index > t && (i._index += e) }) }, _createMiddleMarker: function(t, e) { var i, o, a, s = this._getMiddleLatLng(t, e), - r = this._createMarker(s); - r.setOpacity(.6), t._middleRight = e._middleLeft = r, o = function() { var o = e._index; - r._index = o, r.off("click", i, this).on("click", this._onMarkerClick, this), s.lat = r.getLatLng().lat, s.lng = r.getLatLng().lng, this._poly.spliceLatLngs(o, 0, s), this._markers.splice(o, 0, r), r.setOpacity(1), this._updateIndexes(o, 1), e._index++, this._updatePrevNext(t, r), this._updatePrevNext(r, e), this._poly.fire("editstart") }, a = function() { r.off("dragstart", o, this), r.off("dragend", a, this), this._createMiddleMarker(t, r), this._createMiddleMarker(r, e) }, i = function() { o.call(this), a.call(this), this._fireEdit() }, r.on("click", i, this).on("dragstart", o, this).on("dragend", a, this), this._markerGroup.addLayer(r) }, _updatePrevNext: function(t, e) { t && (t._next = e), e && (e._prev = t) }, _getMiddleLatLng: function(t, e) { var i = this._poly._map, - o = i.project(t.getLatLng()), - a = i.project(e.getLatLng()); return i.unproject(o._add(a)._divideBy(2)) } }), L.Polyline.addInitHook(function() { this.editing || (L.Edit.Poly && (this.editing = new L.Edit.Poly(this), this.options.editable && this.editing.enable()), this.on("add", function() { this.editing && this.editing.enabled() && this.editing.addHooks() }), this.on("remove", function() { this.editing && this.editing.enabled() && this.editing.removeHooks() })) }), L.Edit = L.Edit || {}, L.Edit.SimpleShape = L.Handler.extend({ options: { moveIcon: new L.DivIcon({ iconSize: new L.Point(8, 8), className: "leaflet-div-icon leaflet-editing-icon leaflet-edit-move" }), resizeIcon: new L.DivIcon({ iconSize: new L.Point(8, 8), className: "leaflet-div-icon leaflet-editing-icon leaflet-edit-resize" }) }, initialize: function(t, e) { this._shape = t, L.Util.setOptions(this, e) }, addHooks: function() { this._shape._map && (this._map = this._shape._map, this._markerGroup || this._initMarkers(), this._map.addLayer(this._markerGroup)) }, removeHooks: function() { if (this._shape._map) { this._unbindMarker(this._moveMarker); for (var t = 0, e = this._resizeMarkers.length; e > t; t++) this._unbindMarker(this._resizeMarkers[t]); - this._resizeMarkers = null, this._map.removeLayer(this._markerGroup), delete this._markerGroup } - this._map = null }, updateMarkers: function() { this._markerGroup.clearLayers(), this._initMarkers() }, _initMarkers: function() { this._markerGroup || (this._markerGroup = new L.LayerGroup), this._createMoveMarker(), this._createResizeMarker() }, _createMoveMarker: function() {}, _createResizeMarker: function() {}, _createMarker: function(t, e) { var i = new L.Marker(t, { draggable: !0, icon: e, zIndexOffset: 10 }); return this._bindMarker(i), this._markerGroup.addLayer(i), i }, _bindMarker: function(t) { t.on("dragstart", this._onMarkerDragStart, this).on("drag", this._onMarkerDrag, this).on("dragend", this._onMarkerDragEnd, this) }, _unbindMarker: function(t) { t.off("dragstart", this._onMarkerDragStart, this).off("drag", this._onMarkerDrag, this).off("dragend", this._onMarkerDragEnd, this) }, _onMarkerDragStart: function(t) { var e = t.target; - e.setOpacity(0), this._shape.fire("editstart") }, _fireEdit: function() { this._shape.edited = !0, this._shape.fire("edit") }, _onMarkerDrag: function(t) { var e = t.target, - i = e.getLatLng(); - e === this._moveMarker ? this._move(i) : this._resize(i), this._shape.redraw() }, _onMarkerDragEnd: function(t) { var e = t.target; - e.setOpacity(1), this._fireEdit() }, _move: function() {}, _resize: function() {} }), L.Edit = L.Edit || {}, L.Edit.Rectangle = L.Edit.SimpleShape.extend({ _createMoveMarker: function() { var t = this._shape.getBounds(), - e = t.getCenter(); - this._moveMarker = this._createMarker(e, this.options.moveIcon) }, _createResizeMarker: function() { var t = this._getCorners(); - this._resizeMarkers = []; for (var e = 0, i = t.length; i > e; e++) this._resizeMarkers.push(this._createMarker(t[e], this.options.resizeIcon)), this._resizeMarkers[e]._cornerIndex = e }, _onMarkerDragStart: function(t) { L.Edit.SimpleShape.prototype._onMarkerDragStart.call(this, t); var e = this._getCorners(), - i = t.target, - o = i._cornerIndex; - this._oppositeCorner = e[(o + 2) % 4], this._toggleCornerMarkers(0, o) }, _onMarkerDragEnd: function(t) { var e, i, o = t.target; - o === this._moveMarker && (e = this._shape.getBounds(), i = e.getCenter(), o.setLatLng(i)), this._toggleCornerMarkers(1), this._repositionCornerMarkers(), L.Edit.SimpleShape.prototype._onMarkerDragEnd.call(this, t) }, _move: function(t) { for (var e, i = this._shape.getLatLngs(), o = this._shape.getBounds(), a = o.getCenter(), s = [], r = 0, n = i.length; n > r; r++) e = [i[r].lat - a.lat, i[r].lng - a.lng], s.push([t.lat + e[0], t.lng + e[1]]); - this._shape.setLatLngs(s), this._repositionCornerMarkers() }, _resize: function(t) { var e; - this._shape.setBounds(L.latLngBounds(t, this._oppositeCorner)), e = this._shape.getBounds(), this._moveMarker.setLatLng(e.getCenter()) }, _getCorners: function() { var t = this._shape.getBounds(), - e = t.getNorthWest(), - i = t.getNorthEast(), - o = t.getSouthEast(), - a = t.getSouthWest(); return [e, i, o, a] }, _toggleCornerMarkers: function(t) { for (var e = 0, i = this._resizeMarkers.length; i > e; e++) this._resizeMarkers[e].setOpacity(t) }, _repositionCornerMarkers: function() { for (var t = this._getCorners(), e = 0, i = this._resizeMarkers.length; i > e; e++) this._resizeMarkers[e].setLatLng(t[e]) } }), L.Rectangle.addInitHook(function() { L.Edit.Rectangle && (this.editing = new L.Edit.Rectangle(this), this.options.editable && this.editing.enable()) }), L.Edit = L.Edit || {}, L.Edit.Circle = L.Edit.SimpleShape.extend({ _createMoveMarker: function() { var t = this._shape.getLatLng(); - this._moveMarker = this._createMarker(t, this.options.moveIcon) }, _createResizeMarker: function() { var t = this._shape.getLatLng(), - e = this._getResizeMarkerPoint(t); - this._resizeMarkers = [], this._resizeMarkers.push(this._createMarker(e, this.options.resizeIcon)) }, _getResizeMarkerPoint: function(t) { var e = this._shape._radius * Math.cos(Math.PI / 4), - i = this._map.project(t); return this._map.unproject([i.x + e, i.y - e]) }, _move: function(t) { var e = this._getResizeMarkerPoint(t); - this._resizeMarkers[0].setLatLng(e), this._shape.setLatLng(t) }, _resize: function(t) { var e = this._moveMarker.getLatLng(), - i = e.distanceTo(t); - this._shape.setRadius(i) } }), L.Circle.addInitHook(function() { L.Edit.Circle && (this.editing = new L.Edit.Circle(this), this.options.editable && this.editing.enable()), this.on("add", function() { this.editing && this.editing.enabled() && this.editing.addHooks() }), this.on("remove", function() { this.editing && this.editing.enabled() && this.editing.removeHooks() }) }), L.LatLngUtil = { cloneLatLngs: function(t) { for (var e = [], i = 0, o = t.length; o > i; i++) e.push(this.cloneLatLng(t[i])); return e }, cloneLatLng: function(t) { return L.latLng(t.lat, t.lng) } }, L.GeometryUtil = L.extend(L.GeometryUtil || {}, { geodesicArea: function(t) { var e, i, o = t.length, - a = 0, - s = L.LatLng.DEG_TO_RAD; if (o > 2) { for (var r = 0; o > r; r++) e = t[r], i = t[(r + 1) % o], a += (i.lng - e.lng) * s * (2 + Math.sin(e.lat * s) + Math.sin(i.lat * s)); - a = 6378137 * a * 6378137 / 2 } return Math.abs(a) }, readableArea: function(t, e) { var i; return e ? i = t >= 1e4 ? (1e-4 * t).toFixed(2) + " ha" : t.toFixed(2) + " m²" : (t *= .836127, i = t >= 3097600 ? (t / 3097600).toFixed(2) + " mi²" : t >= 4840 ? (t / 4840).toFixed(2) + " acres" : Math.ceil(t) + " yd²"), i }, readableDistance: function(t, e) { var i; return e ? i = t > 1e3 ? (t / 1e3).toFixed(2) + " km" : Math.ceil(t) + " m" : (t *= 1.09361, i = t > 1760 ? (t / 1760).toFixed(2) + " miles" : Math.ceil(t) + " yd"), i } }), L.Util.extend(L.LineUtil, { segmentsIntersect: function(t, e, i, o) { return this._checkCounterclockwise(t, i, o) !== this._checkCounterclockwise(e, i, o) && this._checkCounterclockwise(t, e, i) !== this._checkCounterclockwise(t, e, o) }, _checkCounterclockwise: function(t, e, i) { return (i.y - t.y) * (e.x - t.x) > (e.y - t.y) * (i.x - t.x) } }), L.Polyline.include({ intersects: function() { var t, e, i, o = this._originalPoints, - a = o ? o.length : 0; if (this._tooFewPointsForIntersection()) return !1; for (t = a - 1; t >= 3; t--) - if (e = o[t - 1], i = o[t], this._lineSegmentsIntersectsRange(e, i, t - 2)) return !0; - return !1 }, newLatLngIntersects: function(t, e) { return this._map ? this.newPointIntersects(this._map.latLngToLayerPoint(t), e) : !1 }, newPointIntersects: function(t, e) { var i = this._originalPoints, - o = i ? i.length : 0, - a = i ? i[o - 1] : null, - s = o - 2; return this._tooFewPointsForIntersection(1) ? !1 : this._lineSegmentsIntersectsRange(a, t, s, e ? 1 : 0) }, _tooFewPointsForIntersection: function(t) { var e = this._originalPoints, - i = e ? e.length : 0; return i += t || 0, !this._originalPoints || 3 >= i }, _lineSegmentsIntersectsRange: function(t, e, i, o) { var a, s, r = this._originalPoints; - o = o || 0; for (var n = i; n > o; n--) - if (a = r[n - 1], s = r[n], L.LineUtil.segmentsIntersect(t, e, a, s)) return !0; - return !1 } }), L.Polygon.include({ intersects: function() { var t, e, i, o, a, s = this._originalPoints; return this._tooFewPointsForIntersection() ? !1 : (t = L.Polyline.prototype.intersects.call(this)) ? !0 : (e = s.length, i = s[0], o = s[e - 1], a = e - 2, this._lineSegmentsIntersectsRange(o, i, a, 1)) } }), L.Control.Draw = L.Control.extend({ options: { position: "topleft", draw: {}, edit: !1 }, initialize: function(t) { if (L.version < "0.7") throw new Error("Leaflet.draw 0.2.3+ requires Leaflet 0.7.0+. Download latest from https://github.com/Leaflet/Leaflet/"); - L.Control.prototype.initialize.call(this, t); var e, i; - this._toolbars = {}, L.DrawToolbar && this.options.draw && (i = new L.DrawToolbar(this.options.draw), e = L.stamp(i), this._toolbars[e] = i, this._toolbars[e].on("enable", this._toolbarEnabled, this)), L.EditToolbar && this.options.edit && (i = new L.EditToolbar(this.options.edit), e = L.stamp(i), this._toolbars[e] = i, this._toolbars[e].on("enable", this._toolbarEnabled, this)) }, onAdd: function(t) { var e, i = L.DomUtil.create("div", "leaflet-draw"), - o = !1, - a = "leaflet-draw-toolbar-top"; for (var s in this._toolbars) this._toolbars.hasOwnProperty(s) && (e = this._toolbars[s].addToolbar(t), e && (o || (L.DomUtil.hasClass(e, a) || L.DomUtil.addClass(e.childNodes[0], a), o = !0), i.appendChild(e))); return i }, onRemove: function() { for (var t in this._toolbars) this._toolbars.hasOwnProperty(t) && this._toolbars[t].removeToolbar() }, setDrawingOptions: function(t) { for (var e in this._toolbars) this._toolbars[e] instanceof L.DrawToolbar && this._toolbars[e].setOptions(t) }, _toolbarEnabled: function(t) { var e = "" + L.stamp(t.target); for (var i in this._toolbars) this._toolbars.hasOwnProperty(i) && i !== e && this._toolbars[i].disable() } }), L.Map.mergeOptions({ drawControlTooltips: !0, drawControl: !1 }), L.Map.addInitHook(function() { this.options.drawControl && (this.drawControl = new L.Control.Draw, this.addControl(this.drawControl)) }), L.Toolbar = L.Class.extend({ - includes: [L.Mixin.Events], - initialize: function(t) { L.setOptions(this, t), this._modes = {}, this._actionButtons = [], this._activeMode = null }, - enabled: function() { return null !== this._activeMode }, - disable: function() { this.enabled() && this._activeMode.handler.disable() }, - addToolbar: function(t) { var e, i = L.DomUtil.create("div", "leaflet-draw-section"), - o = 0, - a = this._toolbarClass || "", - s = this.getModeHandlers(t); for (this._toolbarContainer = L.DomUtil.create("div", "leaflet-draw-toolbar leaflet-bar"), this._map = t, e = 0; e < s.length; e++) s[e].enabled && this._initModeHandler(s[e].handler, this._toolbarContainer, o++, a, s[e].title); return o ? (this._lastButtonIndex = --o, this._actionsContainer = L.DomUtil.create("ul", "leaflet-draw-actions"), i.appendChild(this._toolbarContainer), i.appendChild(this._actionsContainer), i) : void 0 }, - removeToolbar: function() { for (var t in this._modes) this._modes.hasOwnProperty(t) && (this._disposeButton(this._modes[t].button, this._modes[t].handler.enable, this._modes[t].handler), this._modes[t].handler.disable(), this._modes[t].handler.off("enabled", this._handlerActivated, this).off("disabled", this._handlerDeactivated, this)); - this._modes = {}; for (var e = 0, i = this._actionButtons.length; i > e; e++) this._disposeButton(this._actionButtons[e].button, this._actionButtons[e].callback, this); - this._actionButtons = [], this._actionsContainer = null }, - _initModeHandler: function(t, e, i, o, a) { var s = t.type; - this._modes[s] = {}, this._modes[s].handler = t, this._modes[s].button = this._createButton({ title: a, className: o + "-" + s, container: e, callback: this._modes[s].handler.enable, context: this._modes[s].handler }), this._modes[s].buttonIndex = i, this._modes[s].handler.on("enabled", this._handlerActivated, this).on("disabled", this._handlerDeactivated, this) }, - _createButton: function(t) { var e = L.DomUtil.create("a", t.className || "", t.container); return e.href = "#", t.text && (e.innerHTML = t.text), t.title && (e.title = t.title), L.DomEvent.on(e, "click", L.DomEvent.stopPropagation).on(e, "mousedown", L.DomEvent.stopPropagation).on(e, "dblclick", L.DomEvent.stopPropagation).on(e, "click", L.DomEvent.preventDefault).on(e, "click", t.callback, t.context), e }, - _disposeButton: function(t, e) { L.DomEvent.off(t, "click", L.DomEvent.stopPropagation).off(t, "mousedown", L.DomEvent.stopPropagation).off(t, "dblclick", L.DomEvent.stopPropagation).off(t, "click", L.DomEvent.preventDefault).off(t, "click", e) }, - _handlerActivated: function(t) { this.disable(), this._activeMode = this._modes[t.handler], L.DomUtil.addClass(this._activeMode.button, "leaflet-draw-toolbar-button-enabled"), this._showActionsToolbar(), this.fire("enable") }, - _handlerDeactivated: function() { this._hideActionsToolbar(), L.DomUtil.removeClass(this._activeMode.button, "leaflet-draw-toolbar-button-enabled"), this._activeMode = null, this.fire("disable") }, - _createActions: function(t) { var e, i, o, a, s = this._actionsContainer, - r = this.getActions(t), - n = r.length; for (i = 0, o = this._actionButtons.length; o > i; i++) this._disposeButton(this._actionButtons[i].button, this._actionButtons[i].callback); for (this._actionButtons = []; s.firstChild;) s.removeChild(s.firstChild); for (var l = 0; n > l; l++) "enabled" in r[l] && !r[l].enabled || (e = L.DomUtil.create("li", "", s), a = this._createButton({ title: r[l].title, text: r[l].text, container: e, callback: r[l].callback, context: r[l].context }), this._actionButtons.push({ button: a, callback: r[l].callback })) }, - _showActionsToolbar: function() { - var t = this._activeMode.buttonIndex, - e = this._lastButtonIndex, - i = this._activeMode.button.offsetTop - 1; - this._createActions(this._activeMode.handler), this._actionsContainer.style.top = i + "px", 0 === t && (L.DomUtil.addClass(this._toolbarContainer, "leaflet-draw-toolbar-notop"), L.DomUtil.addClass(this._actionsContainer, "leaflet-draw-actions-top")), t === e && (L.DomUtil.addClass(this._toolbarContainer, "leaflet-draw-toolbar-nobottom"), L.DomUtil.addClass(this._actionsContainer, "leaflet-draw-actions-bottom")), this._actionsContainer.style.display = "block" - }, - _hideActionsToolbar: function() { this._actionsContainer.style.display = "none", L.DomUtil.removeClass(this._toolbarContainer, "leaflet-draw-toolbar-notop"), L.DomUtil.removeClass(this._toolbarContainer, "leaflet-draw-toolbar-nobottom"), L.DomUtil.removeClass(this._actionsContainer, "leaflet-draw-actions-top"), L.DomUtil.removeClass(this._actionsContainer, "leaflet-draw-actions-bottom") } - }), L.Tooltip = L.Class.extend({ initialize: function(t) { this._map = t, this._popupPane = t._panes.popupPane, this._container = t.options.drawControlTooltips ? L.DomUtil.create("div", "leaflet-draw-tooltip", this._popupPane) : null, this._singleLineLabel = !1 }, dispose: function() { this._container && (this._popupPane.removeChild(this._container), this._container = null) }, updateContent: function(t) { return this._container ? (t.subtext = t.subtext || "", 0 !== t.subtext.length || this._singleLineLabel ? t.subtext.length > 0 && this._singleLineLabel && (L.DomUtil.removeClass(this._container, "leaflet-draw-tooltip-single"), this._singleLineLabel = !1) : (L.DomUtil.addClass(this._container, "leaflet-draw-tooltip-single"), this._singleLineLabel = !0), this._container.innerHTML = (t.subtext.length > 0 ? '' + t.subtext + "
              " : "") + "" + t.text + "", this) : this }, updatePosition: function(t) { var e = this._map.latLngToLayerPoint(t), - i = this._container; return this._container && (i.style.visibility = "inherit", L.DomUtil.setPosition(i, e)), this }, showAsError: function() { return this._container && L.DomUtil.addClass(this._container, "leaflet-error-draw-tooltip"), this }, removeError: function() { return this._container && L.DomUtil.removeClass(this._container, "leaflet-error-draw-tooltip"), this } }), L.DrawToolbar = L.Toolbar.extend({ options: { polyline: {}, polygon: {}, rectangle: {}, circle: {}, marker: {} }, initialize: function(t) { for (var e in this.options) this.options.hasOwnProperty(e) && t[e] && (t[e] = L.extend({}, this.options[e], t[e])); - this._toolbarClass = "leaflet-draw-draw", L.Toolbar.prototype.initialize.call(this, t) }, getModeHandlers: function(t) { return [{ enabled: this.options.polyline, handler: new L.Draw.Polyline(t, this.options.polyline), title: L.drawLocal.draw.toolbar.buttons.polyline }, { enabled: this.options.polygon, handler: new L.Draw.Polygon(t, this.options.polygon), title: L.drawLocal.draw.toolbar.buttons.polygon }, { enabled: this.options.rectangle, handler: new L.Draw.Rectangle(t, this.options.rectangle), title: L.drawLocal.draw.toolbar.buttons.rectangle }, { enabled: this.options.circle, handler: new L.Draw.Circle(t, this.options.circle), title: L.drawLocal.draw.toolbar.buttons.circle }, { enabled: this.options.marker, handler: new L.Draw.Marker(t, this.options.marker), title: L.drawLocal.draw.toolbar.buttons.marker }] }, getActions: function(t) { return [{ enabled: t.deleteLastVertex, title: L.drawLocal.draw.toolbar.undo.title, text: L.drawLocal.draw.toolbar.undo.text, callback: t.deleteLastVertex, context: t }, { title: L.drawLocal.draw.toolbar.actions.title, text: L.drawLocal.draw.toolbar.actions.text, callback: this.disable, context: this }] }, setOptions: function(t) { L.setOptions(this, t); for (var e in this._modes) this._modes.hasOwnProperty(e) && t.hasOwnProperty(e) && this._modes[e].handler.setOptions(t[e]) } }), L.EditToolbar = L.Toolbar.extend({ options: { edit: { selectedPathOptions: { color: "#fe57a1", opacity: .6, dashArray: "10, 10", fill: !0, fillColor: "#fe57a1", fillOpacity: .1 } }, remove: {}, featureGroup: null }, initialize: function(t) { t.edit && ("undefined" == typeof t.edit.selectedPathOptions && (t.edit.selectedPathOptions = this.options.edit.selectedPathOptions), t.edit = L.extend({}, this.options.edit, t.edit)), t.remove && (t.remove = L.extend({}, this.options.remove, t.remove)), this._toolbarClass = "leaflet-draw-edit", L.Toolbar.prototype.initialize.call(this, t), this._selectedFeatureCount = 0 }, getModeHandlers: function(t) { var e = this.options.featureGroup; return [{ enabled: this.options.edit, handler: new L.EditToolbar.Edit(t, { featureGroup: e, selectedPathOptions: this.options.edit.selectedPathOptions }), title: L.drawLocal.edit.toolbar.buttons.edit }, { enabled: this.options.remove, handler: new L.EditToolbar.Delete(t, { featureGroup: e }), title: L.drawLocal.edit.toolbar.buttons.remove }] }, getActions: function() { return [{ title: L.drawLocal.edit.toolbar.actions.save.title, text: L.drawLocal.edit.toolbar.actions.save.text, callback: this._save, context: this }, { title: L.drawLocal.edit.toolbar.actions.cancel.title, text: L.drawLocal.edit.toolbar.actions.cancel.text, callback: this.disable, context: this }] }, addToolbar: function(t) { var e = L.Toolbar.prototype.addToolbar.call(this, t); return this._checkDisabled(), this.options.featureGroup.on("layeradd layerremove", this._checkDisabled, this), e }, removeToolbar: function() { this.options.featureGroup.off("layeradd layerremove", this._checkDisabled, this), L.Toolbar.prototype.removeToolbar.call(this) }, disable: function() { this.enabled() && (this._activeMode.handler.revertLayers(), L.Toolbar.prototype.disable.call(this)) }, _save: function() { this._activeMode.handler.save(), this._activeMode.handler.disable() }, _checkDisabled: function() { var t, e = this.options.featureGroup, - i = 0 !== e.getLayers().length; - this.options.edit && (t = this._modes[L.EditToolbar.Edit.TYPE].button, i ? L.DomUtil.removeClass(t, "leaflet-disabled") : L.DomUtil.addClass(t, "leaflet-disabled"), t.setAttribute("title", i ? L.drawLocal.edit.toolbar.buttons.edit : L.drawLocal.edit.toolbar.buttons.editDisabled)), this.options.remove && (t = this._modes[L.EditToolbar.Delete.TYPE].button, i ? L.DomUtil.removeClass(t, "leaflet-disabled") : L.DomUtil.addClass(t, "leaflet-disabled"), t.setAttribute("title", i ? L.drawLocal.edit.toolbar.buttons.remove : L.drawLocal.edit.toolbar.buttons.removeDisabled)) } }), L.EditToolbar.Edit = L.Handler.extend({ statics: { TYPE: "edit" }, includes: L.Mixin.Events, initialize: function(t, e) { if (L.Handler.prototype.initialize.call(this, t), this._selectedPathOptions = e.selectedPathOptions, this._featureGroup = e.featureGroup, !(this._featureGroup instanceof L.FeatureGroup)) throw new Error("options.featureGroup must be a L.FeatureGroup"); - this._uneditedLayerProps = {}, this.type = L.EditToolbar.Edit.TYPE }, enable: function() {!this._enabled && this._hasAvailableLayers() && (this.fire("enabled", { handler: this.type }), this._map.fire("draw:editstart", { handler: this.type }), L.Handler.prototype.enable.call(this), this._featureGroup.on("layeradd", this._enableLayerEdit, this).on("layerremove", this._disableLayerEdit, this)) }, disable: function() { this._enabled && (this._featureGroup.off("layeradd", this._enableLayerEdit, this).off("layerremove", this._disableLayerEdit, this), L.Handler.prototype.disable.call(this), this._map.fire("draw:editstop", { handler: this.type }), this.fire("disabled", { handler: this.type })) }, addHooks: function() { var t = this._map; - t && (t.getContainer().focus(), this._featureGroup.eachLayer(this._enableLayerEdit, this), this._tooltip = new L.Tooltip(this._map), this._tooltip.updateContent({ text: L.drawLocal.edit.handlers.edit.tooltip.text, subtext: L.drawLocal.edit.handlers.edit.tooltip.subtext }), this._map.on("mousemove", this._onMouseMove, this)) }, removeHooks: function() { this._map && (this._featureGroup.eachLayer(this._disableLayerEdit, this), this._uneditedLayerProps = {}, this._tooltip.dispose(), this._tooltip = null, this._map.off("mousemove", this._onMouseMove, this)) }, revertLayers: function() { this._featureGroup.eachLayer(function(t) { this._revertLayer(t) }, this) }, save: function() { var t = new L.LayerGroup; - this._featureGroup.eachLayer(function(e) { e.edited && (t.addLayer(e), e.edited = !1) }), this._map.fire("draw:edited", { layers: t }) }, _backupLayer: function(t) { var e = L.Util.stamp(t); - this._uneditedLayerProps[e] || (t instanceof L.Polyline || t instanceof L.Polygon || t instanceof L.Rectangle ? this._uneditedLayerProps[e] = { latlngs: L.LatLngUtil.cloneLatLngs(t.getLatLngs()) } : t instanceof L.Circle ? this._uneditedLayerProps[e] = { latlng: L.LatLngUtil.cloneLatLng(t.getLatLng()), radius: t.getRadius() } : t instanceof L.Marker && (this._uneditedLayerProps[e] = { latlng: L.LatLngUtil.cloneLatLng(t.getLatLng()) })) }, _revertLayer: function(t) { var e = L.Util.stamp(t); - t.edited = !1, this._uneditedLayerProps.hasOwnProperty(e) && (t instanceof L.Polyline || t instanceof L.Polygon || t instanceof L.Rectangle ? t.setLatLngs(this._uneditedLayerProps[e].latlngs) : t instanceof L.Circle ? (t.setLatLng(this._uneditedLayerProps[e].latlng), t.setRadius(this._uneditedLayerProps[e].radius)) : t instanceof L.Marker && t.setLatLng(this._uneditedLayerProps[e].latlng)) }, _toggleMarkerHighlight: function(t) { if (t._icon) { var e = t._icon; - e.style.display = "none", L.DomUtil.hasClass(e, "leaflet-edit-marker-selected") ? (L.DomUtil.removeClass(e, "leaflet-edit-marker-selected"), this._offsetMarker(e, -4)) : (L.DomUtil.addClass(e, "leaflet-edit-marker-selected"), this._offsetMarker(e, 4)), e.style.display = "" } }, _offsetMarker: function(t, e) { var i = parseInt(t.style.marginTop, 10) - e, - o = parseInt(t.style.marginLeft, 10) - e; - t.style.marginTop = i + "px", t.style.marginLeft = o + "px" }, _enableLayerEdit: function(t) { var e, i = t.layer || t.target || t, - o = i instanceof L.Marker; - (!o || i._icon) && (this._backupLayer(i), this._selectedPathOptions && (e = L.Util.extend({}, this._selectedPathOptions), o ? this._toggleMarkerHighlight(i) : (i.options.previousOptions = L.Util.extend({ dashArray: null }, i.options), i instanceof L.Circle || i instanceof L.Polygon || i instanceof L.Rectangle || (e.fill = !1), i.setStyle(e))), o ? (i.dragging.enable(), i.on("dragend", this._onMarkerDragEnd)) : i.editing.enable()) }, _disableLayerEdit: function(t) { var e = t.layer || t.target || t; - e.edited = !1, this._selectedPathOptions && (e instanceof L.Marker ? this._toggleMarkerHighlight(e) : (e.setStyle(e.options.previousOptions), delete e.options.previousOptions)), e instanceof L.Marker ? (e.dragging.disable(), e.off("dragend", this._onMarkerDragEnd, this)) : e.editing.disable() }, _onMarkerDragEnd: function(t) { var e = t.target; - e.edited = !0 }, _onMouseMove: function(t) { this._tooltip.updatePosition(t.latlng) }, _hasAvailableLayers: function() { return 0 !== this._featureGroup.getLayers().length } }), L.EditToolbar.Delete = L.Handler.extend({ statics: { TYPE: "remove" }, includes: L.Mixin.Events, initialize: function(t, e) { if (L.Handler.prototype.initialize.call(this, t), L.Util.setOptions(this, e), this._deletableLayers = this.options.featureGroup, !(this._deletableLayers instanceof L.FeatureGroup)) throw new Error("options.featureGroup must be a L.FeatureGroup"); - this.type = L.EditToolbar.Delete.TYPE }, enable: function() {!this._enabled && this._hasAvailableLayers() && (this.fire("enabled", { handler: this.type }), this._map.fire("draw:deletestart", { handler: this.type }), L.Handler.prototype.enable.call(this), this._deletableLayers.on("layeradd", this._enableLayerDelete, this).on("layerremove", this._disableLayerDelete, this)) }, disable: function() { this._enabled && (this._deletableLayers.off("layeradd", this._enableLayerDelete, this).off("layerremove", this._disableLayerDelete, this), L.Handler.prototype.disable.call(this), this._map.fire("draw:deletestop", { handler: this.type }), this.fire("disabled", { handler: this.type })) }, addHooks: function() { var t = this._map; - t && (t.getContainer().focus(), this._deletableLayers.eachLayer(this._enableLayerDelete, this), this._deletedLayers = new L.layerGroup, this._tooltip = new L.Tooltip(this._map), this._tooltip.updateContent({ text: L.drawLocal.edit.handlers.remove.tooltip.text }), this._map.on("mousemove", this._onMouseMove, this)) }, removeHooks: function() { this._map && (this._deletableLayers.eachLayer(this._disableLayerDelete, this), this._deletedLayers = null, this._tooltip.dispose(), this._tooltip = null, this._map.off("mousemove", this._onMouseMove, this)) }, revertLayers: function() { this._deletedLayers.eachLayer(function(t) { this._deletableLayers.addLayer(t) }, this) }, save: function() { this._map.fire("draw:deleted", { layers: this._deletedLayers }) }, _enableLayerDelete: function(t) { var e = t.layer || t.target || t; - e.on("click", this._removeLayer, this) }, _disableLayerDelete: function(t) { var e = t.layer || t.target || t; - e.off("click", this._removeLayer, this), this._deletedLayers.removeLayer(e) }, _removeLayer: function(t) { var e = t.layer || t.target || t; - this._deletableLayers.removeLayer(e), this._deletedLayers.addLayer(e) }, _onMouseMove: function(t) { this._tooltip.updatePosition(t.latlng) }, _hasAvailableLayers: function() { return 0 !== this._deletableLayers.getLayers().length } }) -}(window, document); +!(function (t, e) { + (L.drawVersion = "0.2.3"), + (L.drawLocal = { + draw: { + toolbar: { + actions: { title: "Cancel drawing", text: "Cancel" }, + undo: { title: "Delete last point drawn", text: "Delete last point" }, + buttons: { + polyline: "Draw a polyline", + polygon: "Draw a polygon", + rectangle: "Draw a rectangle", + circle: "Draw a circle", + marker: "Draw a marker", + }, + }, + handlers: { + circle: { tooltip: { start: "Click and drag to draw circle." } }, + marker: { tooltip: { start: "Click map to place marker." } }, + polygon: { + tooltip: { + start: "Click to start drawing shape.", + cont: "Click to continue drawing shape.", + end: "Click first point to close this shape.", + }, + }, + polyline: { + error: "Error: shape edges cannot cross!", + tooltip: { + start: "Click to start drawing line.", + cont: "Click to continue drawing line.", + end: "Click last point to finish line.", + }, + }, + rectangle: { tooltip: { start: "Click and drag to draw rectangle." } }, + simpleshape: { tooltip: { end: "Release mouse to finish drawing." } }, + }, + }, + edit: { + toolbar: { + actions: { + save: { title: "Save changes.", text: "Save" }, + cancel: { title: "Cancel editing, discards all changes.", text: "Cancel" }, + }, + buttons: { + edit: "Edit layers.", + editDisabled: "No layers to edit.", + remove: "Delete layers.", + removeDisabled: "No layers to delete.", + }, + }, + handlers: { + edit: { + tooltip: { + text: "Drag handles, or marker to edit feature.", + subtext: "Click cancel to undo changes.", + }, + }, + remove: { tooltip: { text: "Click on a feature to remove" } }, + }, + }, + }), + (L.Draw = {}), + (L.Draw.Feature = L.Handler.extend({ + includes: L.Mixin.Events, + initialize: function (t, e) { + (this._map = t), + (this._container = t._container), + (this._overlayPane = t._panes.overlayPane), + (this._popupPane = t._panes.popupPane), + e && + e.shapeOptions && + (e.shapeOptions = L.Util.extend({}, this.options.shapeOptions, e.shapeOptions)), + L.setOptions(this, e); + }, + enable: function () { + this._enabled || + (this.fire("enabled", { handler: this.type }), + this._map.fire("draw:drawstart", { layerType: this.type }), + L.Handler.prototype.enable.call(this)); + }, + disable: function () { + this._enabled && + (L.Handler.prototype.disable.call(this), + this._map.fire("draw:drawstop", { layerType: this.type }), + this.fire("disabled", { handler: this.type })); + }, + addHooks: function () { + var t = this._map; + t && + (L.DomUtil.disableTextSelection(), + t.getContainer().focus(), + (this._tooltip = new L.Tooltip(this._map)), + L.DomEvent.on(this._container, "keyup", this._cancelDrawing, this)); + }, + removeHooks: function () { + this._map && + (L.DomUtil.enableTextSelection(), + this._tooltip.dispose(), + (this._tooltip = null), + L.DomEvent.off(this._container, "keyup", this._cancelDrawing, this)); + }, + setOptions: function (t) { + L.setOptions(this, t); + }, + _fireCreatedEvent: function (t) { + this._map.fire("draw:created", { layer: t, layerType: this.type }); + }, + _cancelDrawing: function (t) { + 27 === t.keyCode && this.disable(); + }, + })), + (L.Draw.Polyline = L.Draw.Feature.extend({ + statics: { TYPE: "polyline" }, + Poly: L.Polyline, + options: { + allowIntersection: !0, + repeatMode: !1, + drawError: { color: "#b00b00", timeout: 2500 }, + icon: new L.DivIcon({ + iconSize: new L.Point(8, 8), + className: "leaflet-div-icon leaflet-editing-icon", + }), + guidelineDistance: 20, + maxGuideLineLength: 4e3, + shapeOptions: { + stroke: !0, + color: "#f06eaa", + weight: 4, + opacity: 0.5, + fill: !1, + clickable: !0, + }, + metric: !0, + showLength: !0, + zIndexOffset: 2e3, + }, + initialize: function (t, e) { + (this.options.drawError.message = L.drawLocal.draw.handlers.polyline.error), + e && + e.drawError && + (e.drawError = L.Util.extend({}, this.options.drawError, e.drawError)), + (this.type = L.Draw.Polyline.TYPE), + L.Draw.Feature.prototype.initialize.call(this, t, e); + }, + addHooks: function () { + L.Draw.Feature.prototype.addHooks.call(this), + this._map && + ((this._markers = []), + (this._markerGroup = new L.LayerGroup()), + this._map.addLayer(this._markerGroup), + (this._poly = new L.Polyline([], this.options.shapeOptions)), + this._tooltip.updateContent(this._getTooltipText()), + this._mouseMarker || + (this._mouseMarker = L.marker(this._map.getCenter(), { + icon: L.divIcon({ + className: "leaflet-mouse-marker", + iconAnchor: [20, 20], + iconSize: [40, 40], + }), + opacity: 0, + zIndexOffset: this.options.zIndexOffset, + })), + this._mouseMarker.on("mousedown", this._onMouseDown, this).addTo(this._map), + this._map + .on("mousemove", this._onMouseMove, this) + .on("mouseup", this._onMouseUp, this) + .on("zoomend", this._onZoomEnd, this)); + }, + removeHooks: function () { + L.Draw.Feature.prototype.removeHooks.call(this), + this._clearHideErrorTimeout(), + this._cleanUpShape(), + this._map.removeLayer(this._markerGroup), + delete this._markerGroup, + delete this._markers, + this._map.removeLayer(this._poly), + delete this._poly, + this._mouseMarker + .off("mousedown", this._onMouseDown, this) + .off("mouseup", this._onMouseUp, this), + this._map.removeLayer(this._mouseMarker), + delete this._mouseMarker, + this._clearGuides(), + this._map.off("mousemove", this._onMouseMove, this).off("zoomend", this._onZoomEnd, this); + }, + deleteLastVertex: function () { + if (!(this._markers.length <= 1)) { + var t = this._markers.pop(), + e = this._poly, + i = this._poly.spliceLatLngs(e.getLatLngs().length - 1, 1)[0]; + this._markerGroup.removeLayer(t), + e.getLatLngs().length < 2 && this._map.removeLayer(e), + this._vertexChanged(i, !1); + } + }, + addVertex: function (t) { + var e = this._markers.length; + return e > 0 && !this.options.allowIntersection && this._poly.newLatLngIntersects(t) + ? void this._showErrorTooltip() + : (this._errorShown && this._hideErrorTooltip(), + this._markers.push(this._createMarker(t)), + this._poly.addLatLng(t), + 2 === this._poly.getLatLngs().length && this._map.addLayer(this._poly), + void this._vertexChanged(t, !0)); + }, + _finishShape: function () { + var t = this._poly.newLatLngIntersects(this._poly.getLatLngs()[0], !0); + return (!this.options.allowIntersection && t) || !this._shapeIsValid() + ? void this._showErrorTooltip() + : (this._fireCreatedEvent(), + this.disable(), + void (this.options.repeatMode && this.enable())); + }, + _shapeIsValid: function () { + return !0; + }, + _onZoomEnd: function () { + this._updateGuide(); + }, + _onMouseMove: function (t) { + var e = t.layerPoint, + i = t.latlng; + (this._currentLatLng = i), + this._updateTooltip(i), + this._updateGuide(e), + this._mouseMarker.setLatLng(i), + L.DomEvent.preventDefault(t.originalEvent); + }, + _vertexChanged: function (t, e) { + this._updateFinishHandler(), + this._updateRunningMeasure(t, e), + this._clearGuides(), + this._updateTooltip(); + }, + _onMouseDown: function (t) { + var e = t.originalEvent; + this._mouseDownOrigin = L.point(e.clientX, e.clientY); + }, + _onMouseUp: function (e) { + if (this._mouseDownOrigin) { + var i = L.point(e.originalEvent.clientX, e.originalEvent.clientY).distanceTo( + this._mouseDownOrigin + ); + Math.abs(i) < 9 * (t.devicePixelRatio || 1) && this.addVertex(e.latlng); + } + this._mouseDownOrigin = null; + }, + _updateFinishHandler: function () { + var t = this._markers.length; + t > 1 && this._markers[t - 1].on("click", this._finishShape, this), + t > 2 && this._markers[t - 2].off("click", this._finishShape, this); + }, + _createMarker: function (t) { + var e = new L.Marker(t, { + icon: this.options.icon, + zIndexOffset: 2 * this.options.zIndexOffset, + }); + return this._markerGroup.addLayer(e), e; + }, + _updateGuide: function (t) { + var e = this._markers.length; + e > 0 && + ((t = t || this._map.latLngToLayerPoint(this._currentLatLng)), + this._clearGuides(), + this._drawGuide(this._map.latLngToLayerPoint(this._markers[e - 1].getLatLng()), t)); + }, + _updateTooltip: function (t) { + var e = this._getTooltipText(); + t && this._tooltip.updatePosition(t), this._errorShown || this._tooltip.updateContent(e); + }, + _drawGuide: function (t, e) { + var i, + o, + a, + s = Math.floor(Math.sqrt(Math.pow(e.x - t.x, 2) + Math.pow(e.y - t.y, 2))), + r = this.options.guidelineDistance, + n = this.options.maxGuideLineLength, + l = s > n ? s - n : r; + for ( + this._guidesContainer || + (this._guidesContainer = L.DomUtil.create( + "div", + "leaflet-draw-guides", + this._overlayPane + )); + s > l; + l += this.options.guidelineDistance + ) + (i = l / s), + (o = { + x: Math.floor(t.x * (1 - i) + i * e.x), + y: Math.floor(t.y * (1 - i) + i * e.y), + }), + (a = L.DomUtil.create("div", "leaflet-draw-guide-dash", this._guidesContainer)), + (a.style.backgroundColor = this._errorShown + ? this.options.drawError.color + : this.options.shapeOptions.color), + L.DomUtil.setPosition(a, o); + }, + _updateGuideColor: function (t) { + if (this._guidesContainer) + for (var e = 0, i = this._guidesContainer.childNodes.length; i > e; e++) + this._guidesContainer.childNodes[e].style.backgroundColor = t; + }, + _clearGuides: function () { + if (this._guidesContainer) + for (; this._guidesContainer.firstChild; ) + this._guidesContainer.removeChild(this._guidesContainer.firstChild); + }, + _getTooltipText: function () { + var t, + e, + i = this.options.showLength; + return ( + 0 === this._markers.length + ? (t = { text: L.drawLocal.draw.handlers.polyline.tooltip.start }) + : ((e = i ? this._getMeasurementString() : ""), + (t = + 1 === this._markers.length + ? { text: L.drawLocal.draw.handlers.polyline.tooltip.cont, subtext: e } + : { text: L.drawLocal.draw.handlers.polyline.tooltip.end, subtext: e })), + t + ); + }, + _updateRunningMeasure: function (t, e) { + var i, + o, + a = this._markers.length; + 1 === this._markers.length + ? (this._measurementRunningTotal = 0) + : ((i = a - (e ? 2 : 1)), + (o = t.distanceTo(this._markers[i].getLatLng())), + (this._measurementRunningTotal += o * (e ? 1 : -1))); + }, + _getMeasurementString: function () { + var t, + e = this._currentLatLng, + i = this._markers[this._markers.length - 1].getLatLng(); + return ( + (t = this._measurementRunningTotal + e.distanceTo(i)), + L.GeometryUtil.readableDistance(t, this.options.metric) + ); + }, + _showErrorTooltip: function () { + (this._errorShown = !0), + this._tooltip.showAsError().updateContent({ text: this.options.drawError.message }), + this._updateGuideColor(this.options.drawError.color), + this._poly.setStyle({ color: this.options.drawError.color }), + this._clearHideErrorTimeout(), + (this._hideErrorTimeout = setTimeout( + L.Util.bind(this._hideErrorTooltip, this), + this.options.drawError.timeout + )); + }, + _hideErrorTooltip: function () { + (this._errorShown = !1), + this._clearHideErrorTimeout(), + this._tooltip.removeError().updateContent(this._getTooltipText()), + this._updateGuideColor(this.options.shapeOptions.color), + this._poly.setStyle({ color: this.options.shapeOptions.color }); + }, + _clearHideErrorTimeout: function () { + this._hideErrorTimeout && + (clearTimeout(this._hideErrorTimeout), (this._hideErrorTimeout = null)); + }, + _cleanUpShape: function () { + this._markers.length > 1 && + this._markers[this._markers.length - 1].off("click", this._finishShape, this); + }, + _fireCreatedEvent: function () { + var t = new this.Poly(this._poly.getLatLngs(), this.options.shapeOptions); + L.Draw.Feature.prototype._fireCreatedEvent.call(this, t); + }, + })), + (L.Draw.Polygon = L.Draw.Polyline.extend({ + statics: { TYPE: "polygon" }, + Poly: L.Polygon, + options: { + showArea: !1, + shapeOptions: { + stroke: !0, + color: "#f06eaa", + weight: 4, + opacity: 0.5, + fill: !0, + fillColor: null, + fillOpacity: 0.2, + clickable: !0, + }, + }, + initialize: function (t, e) { + L.Draw.Polyline.prototype.initialize.call(this, t, e), (this.type = L.Draw.Polygon.TYPE); + }, + _updateFinishHandler: function () { + var t = this._markers.length; + 1 === t && this._markers[0].on("click", this._finishShape, this), + t > 2 && + (this._markers[t - 1].on("dblclick", this._finishShape, this), + t > 3 && this._markers[t - 2].off("dblclick", this._finishShape, this)); + }, + _getTooltipText: function () { + var t, e; + return ( + 0 === this._markers.length + ? (t = L.drawLocal.draw.handlers.polygon.tooltip.start) + : this._markers.length < 3 + ? (t = L.drawLocal.draw.handlers.polygon.tooltip.cont) + : ((t = L.drawLocal.draw.handlers.polygon.tooltip.end), + (e = this._getMeasurementString())), + { text: t, subtext: e } + ); + }, + _getMeasurementString: function () { + var t = this._area; + return t ? L.GeometryUtil.readableArea(t, this.options.metric) : null; + }, + _shapeIsValid: function () { + return this._markers.length >= 3; + }, + _vertexAdded: function () { + if (!this.options.allowIntersection && this.options.showArea) { + var t = this._poly.getLatLngs(); + this._area = L.GeometryUtil.geodesicArea(t); + } + }, + _cleanUpShape: function () { + var t = this._markers.length; + t > 0 && + (this._markers[0].off("click", this._finishShape, this), + t > 2 && this._markers[t - 1].off("dblclick", this._finishShape, this)); + }, + })), + (L.SimpleShape = {}), + (L.Draw.SimpleShape = L.Draw.Feature.extend({ + options: { repeatMode: !1 }, + initialize: function (t, e) { + (this._endLabelText = L.drawLocal.draw.handlers.simpleshape.tooltip.end), + L.Draw.Feature.prototype.initialize.call(this, t, e); + }, + addHooks: function () { + L.Draw.Feature.prototype.addHooks.call(this), + this._map && + ((this._mapDraggable = this._map.dragging.enabled()), + this._mapDraggable && this._map.dragging.disable(), + (this._container.style.cursor = "crosshair"), + this._tooltip.updateContent({ text: this._initialLabelText }), + this._map + .on("mousedown", this._onMouseDown, this) + .on("mousemove", this._onMouseMove, this)); + }, + removeHooks: function () { + L.Draw.Feature.prototype.removeHooks.call(this), + this._map && + (this._mapDraggable && this._map.dragging.enable(), + (this._container.style.cursor = ""), + this._map + .off("mousedown", this._onMouseDown, this) + .off("mousemove", this._onMouseMove, this), + L.DomEvent.off(e, "mouseup", this._onMouseUp, this), + this._shape && (this._map.removeLayer(this._shape), delete this._shape)), + (this._isDrawing = !1); + }, + _onMouseDown: function (t) { + (this._isDrawing = !0), + (this._startLatLng = t.latlng), + L.DomEvent.on(e, "mouseup", this._onMouseUp, this).preventDefault(t.originalEvent); + }, + _onMouseMove: function (t) { + var e = t.latlng; + this._tooltip.updatePosition(e), + this._isDrawing && + (this._tooltip.updateContent({ text: this._endLabelText }), this._drawShape(e)); + }, + _onMouseUp: function () { + this._shape && this._fireCreatedEvent(), + this.disable(), + this.options.repeatMode && this.enable(); + }, + })), + (L.Draw.Rectangle = L.Draw.SimpleShape.extend({ + statics: { TYPE: "rectangle" }, + options: { + shapeOptions: { + stroke: !0, + color: "#f06eaa", + weight: 4, + opacity: 0.5, + fill: !0, + fillColor: null, + fillOpacity: 0.2, + clickable: !0, + }, + }, + initialize: function (t, e) { + (this.type = L.Draw.Rectangle.TYPE), + (this._initialLabelText = L.drawLocal.draw.handlers.rectangle.tooltip.start), + L.Draw.SimpleShape.prototype.initialize.call(this, t, e); + }, + _drawShape: function (t) { + this._shape + ? this._shape.setBounds(new L.LatLngBounds(this._startLatLng, t)) + : ((this._shape = new L.Rectangle( + new L.LatLngBounds(this._startLatLng, t), + this.options.shapeOptions + )), + this._map.addLayer(this._shape)); + }, + _fireCreatedEvent: function () { + var t = new L.Rectangle(this._shape.getBounds(), this.options.shapeOptions); + L.Draw.SimpleShape.prototype._fireCreatedEvent.call(this, t); + }, + })), + (L.Draw.Circle = L.Draw.SimpleShape.extend({ + statics: { TYPE: "circle" }, + options: { + shapeOptions: { + stroke: !0, + color: "#f06eaa", + weight: 4, + opacity: 0.5, + fill: !0, + fillColor: null, + fillOpacity: 0.2, + clickable: !0, + }, + showRadius: !0, + metric: !0, + }, + initialize: function (t, e) { + (this.type = L.Draw.Circle.TYPE), + (this._initialLabelText = L.drawLocal.draw.handlers.circle.tooltip.start), + L.Draw.SimpleShape.prototype.initialize.call(this, t, e); + }, + _drawShape: function (t) { + this._shape + ? this._shape.setRadius(this._startLatLng.distanceTo(t)) + : ((this._shape = new L.Circle( + this._startLatLng, + this._startLatLng.distanceTo(t), + this.options.shapeOptions + )), + this._map.addLayer(this._shape)); + }, + _fireCreatedEvent: function () { + var t = new L.Circle(this._startLatLng, this._shape.getRadius(), this.options.shapeOptions); + L.Draw.SimpleShape.prototype._fireCreatedEvent.call(this, t); + }, + _onMouseMove: function (t) { + var e, + i = t.latlng, + o = this.options.showRadius, + a = this.options.metric; + this._tooltip.updatePosition(i), + this._isDrawing && + (this._drawShape(i), + (e = this._shape.getRadius().toFixed(1)), + this._tooltip.updateContent({ + text: this._endLabelText, + subtext: o ? "Radius: " + L.GeometryUtil.readableDistance(e, a) : "", + })); + }, + })), + (L.Draw.Marker = L.Draw.Feature.extend({ + statics: { TYPE: "marker" }, + options: { icon: new L.Icon.Default(), repeatMode: !1, zIndexOffset: 2e3 }, + initialize: function (t, e) { + (this.type = L.Draw.Marker.TYPE), L.Draw.Feature.prototype.initialize.call(this, t, e); + }, + addHooks: function () { + L.Draw.Feature.prototype.addHooks.call(this), + this._map && + (this._tooltip.updateContent({ + text: L.drawLocal.draw.handlers.marker.tooltip.start, + }), + this._mouseMarker || + (this._mouseMarker = L.marker(this._map.getCenter(), { + icon: L.divIcon({ + className: "leaflet-mouse-marker", + iconAnchor: [20, 20], + iconSize: [40, 40], + }), + opacity: 0, + zIndexOffset: this.options.zIndexOffset, + })), + this._mouseMarker.on("click", this._onClick, this).addTo(this._map), + this._map.on("mousemove", this._onMouseMove, this)); + }, + removeHooks: function () { + L.Draw.Feature.prototype.removeHooks.call(this), + this._map && + (this._marker && + (this._marker.off("click", this._onClick, this), + this._map.off("click", this._onClick, this).removeLayer(this._marker), + delete this._marker), + this._mouseMarker.off("click", this._onClick, this), + this._map.removeLayer(this._mouseMarker), + delete this._mouseMarker, + this._map.off("mousemove", this._onMouseMove, this)); + }, + _onMouseMove: function (t) { + var e = t.latlng; + this._tooltip.updatePosition(e), + this._mouseMarker.setLatLng(e), + this._marker + ? ((e = this._mouseMarker.getLatLng()), this._marker.setLatLng(e)) + : ((this._marker = new L.Marker(e, { + icon: this.options.icon, + zIndexOffset: this.options.zIndexOffset, + })), + this._marker.on("click", this._onClick, this), + this._map.on("click", this._onClick, this).addLayer(this._marker)); + }, + _onClick: function () { + this._fireCreatedEvent(), this.disable(), this.options.repeatMode && this.enable(); + }, + _fireCreatedEvent: function () { + var t = new L.Marker(this._marker.getLatLng(), { icon: this.options.icon }); + L.Draw.Feature.prototype._fireCreatedEvent.call(this, t); + }, + })), + (L.Edit = L.Edit || {}), + (L.Edit.Poly = L.Handler.extend({ + options: { + icon: new L.DivIcon({ + iconSize: new L.Point(8, 8), + className: "leaflet-div-icon leaflet-editing-icon", + }), + }, + initialize: function (t, e) { + (this._poly = t), L.setOptions(this, e); + }, + addHooks: function () { + this._poly._map && + (this._markerGroup || this._initMarkers(), this._poly._map.addLayer(this._markerGroup)); + }, + removeHooks: function () { + this._poly._map && + (this._poly._map.removeLayer(this._markerGroup), + delete this._markerGroup, + delete this._markers); + }, + updateMarkers: function () { + this._markerGroup.clearLayers(), this._initMarkers(); + }, + _initMarkers: function () { + this._markerGroup || (this._markerGroup = new L.LayerGroup()), (this._markers = []); + var t, + e, + i, + o, + a = this._poly._latlngs; + for (t = 0, i = a.length; i > t; t++) + (o = this._createMarker(a[t], t)), + o.on("click", this._onMarkerClick, this), + this._markers.push(o); + var s, r; + for (t = 0, e = i - 1; i > t; e = t++) + (0 !== t || (L.Polygon && this._poly instanceof L.Polygon)) && + ((s = this._markers[e]), + (r = this._markers[t]), + this._createMiddleMarker(s, r), + this._updatePrevNext(s, r)); + }, + _createMarker: function (t, e) { + var i = new L.Marker(t, { draggable: !0, icon: this.options.icon }); + return ( + (i._origLatLng = t), + (i._index = e), + i.on("drag", this._onMarkerDrag, this), + i.on("dragend", this._fireEdit, this), + this._markerGroup.addLayer(i), + i + ); + }, + _removeMarker: function (t) { + var e = t._index; + this._markerGroup.removeLayer(t), + this._markers.splice(e, 1), + this._poly.spliceLatLngs(e, 1), + this._updateIndexes(e, -1), + t + .off("drag", this._onMarkerDrag, this) + .off("dragend", this._fireEdit, this) + .off("click", this._onMarkerClick, this); + }, + _fireEdit: function () { + (this._poly.edited = !0), this._poly.fire("edit"); + }, + _onMarkerDrag: function (t) { + var e = t.target; + L.extend(e._origLatLng, e._latlng), + e._middleLeft && e._middleLeft.setLatLng(this._getMiddleLatLng(e._prev, e)), + e._middleRight && e._middleRight.setLatLng(this._getMiddleLatLng(e, e._next)), + this._poly.redraw(); + }, + _onMarkerClick: function (t) { + var e = L.Polygon && this._poly instanceof L.Polygon ? 4 : 3, + i = t.target; + this._poly._latlngs.length < e || + (this._removeMarker(i), + this._updatePrevNext(i._prev, i._next), + i._middleLeft && this._markerGroup.removeLayer(i._middleLeft), + i._middleRight && this._markerGroup.removeLayer(i._middleRight), + i._prev && i._next + ? this._createMiddleMarker(i._prev, i._next) + : i._prev + ? i._next || (i._prev._middleRight = null) + : (i._next._middleLeft = null), + this._fireEdit()); + }, + _updateIndexes: function (t, e) { + this._markerGroup.eachLayer(function (i) { + i._index > t && (i._index += e); + }); + }, + _createMiddleMarker: function (t, e) { + var i, + o, + a, + s = this._getMiddleLatLng(t, e), + r = this._createMarker(s); + r.setOpacity(0.6), + (t._middleRight = e._middleLeft = r), + (o = function () { + var o = e._index; + (r._index = o), + r.off("click", i, this).on("click", this._onMarkerClick, this), + (s.lat = r.getLatLng().lat), + (s.lng = r.getLatLng().lng), + this._poly.spliceLatLngs(o, 0, s), + this._markers.splice(o, 0, r), + r.setOpacity(1), + this._updateIndexes(o, 1), + e._index++, + this._updatePrevNext(t, r), + this._updatePrevNext(r, e), + this._poly.fire("editstart"); + }), + (a = function () { + r.off("dragstart", o, this), + r.off("dragend", a, this), + this._createMiddleMarker(t, r), + this._createMiddleMarker(r, e); + }), + (i = function () { + o.call(this), a.call(this), this._fireEdit(); + }), + r.on("click", i, this).on("dragstart", o, this).on("dragend", a, this), + this._markerGroup.addLayer(r); + }, + _updatePrevNext: function (t, e) { + t && (t._next = e), e && (e._prev = t); + }, + _getMiddleLatLng: function (t, e) { + var i = this._poly._map, + o = i.project(t.getLatLng()), + a = i.project(e.getLatLng()); + return i.unproject(o._add(a)._divideBy(2)); + }, + })), + L.Polyline.addInitHook(function () { + this.editing || + (L.Edit.Poly && + ((this.editing = new L.Edit.Poly(this)), this.options.editable && this.editing.enable()), + this.on("add", function () { + this.editing && this.editing.enabled() && this.editing.addHooks(); + }), + this.on("remove", function () { + this.editing && this.editing.enabled() && this.editing.removeHooks(); + })); + }), + (L.Edit = L.Edit || {}), + (L.Edit.SimpleShape = L.Handler.extend({ + options: { + moveIcon: new L.DivIcon({ + iconSize: new L.Point(8, 8), + className: "leaflet-div-icon leaflet-editing-icon leaflet-edit-move", + }), + resizeIcon: new L.DivIcon({ + iconSize: new L.Point(8, 8), + className: "leaflet-div-icon leaflet-editing-icon leaflet-edit-resize", + }), + }, + initialize: function (t, e) { + (this._shape = t), L.Util.setOptions(this, e); + }, + addHooks: function () { + this._shape._map && + ((this._map = this._shape._map), + this._markerGroup || this._initMarkers(), + this._map.addLayer(this._markerGroup)); + }, + removeHooks: function () { + if (this._shape._map) { + this._unbindMarker(this._moveMarker); + for (var t = 0, e = this._resizeMarkers.length; e > t; t++) + this._unbindMarker(this._resizeMarkers[t]); + (this._resizeMarkers = null), + this._map.removeLayer(this._markerGroup), + delete this._markerGroup; + } + this._map = null; + }, + updateMarkers: function () { + this._markerGroup.clearLayers(), this._initMarkers(); + }, + _initMarkers: function () { + this._markerGroup || (this._markerGroup = new L.LayerGroup()), + this._createMoveMarker(), + this._createResizeMarker(); + }, + _createMoveMarker: function () {}, + _createResizeMarker: function () {}, + _createMarker: function (t, e) { + var i = new L.Marker(t, { draggable: !0, icon: e, zIndexOffset: 10 }); + return this._bindMarker(i), this._markerGroup.addLayer(i), i; + }, + _bindMarker: function (t) { + t.on("dragstart", this._onMarkerDragStart, this) + .on("drag", this._onMarkerDrag, this) + .on("dragend", this._onMarkerDragEnd, this); + }, + _unbindMarker: function (t) { + t.off("dragstart", this._onMarkerDragStart, this) + .off("drag", this._onMarkerDrag, this) + .off("dragend", this._onMarkerDragEnd, this); + }, + _onMarkerDragStart: function (t) { + var e = t.target; + e.setOpacity(0), this._shape.fire("editstart"); + }, + _fireEdit: function () { + (this._shape.edited = !0), this._shape.fire("edit"); + }, + _onMarkerDrag: function (t) { + var e = t.target, + i = e.getLatLng(); + e === this._moveMarker ? this._move(i) : this._resize(i), this._shape.redraw(); + }, + _onMarkerDragEnd: function (t) { + var e = t.target; + e.setOpacity(1), this._fireEdit(); + }, + _move: function () {}, + _resize: function () {}, + })), + (L.Edit = L.Edit || {}), + (L.Edit.Rectangle = L.Edit.SimpleShape.extend({ + _createMoveMarker: function () { + var t = this._shape.getBounds(), + e = t.getCenter(); + this._moveMarker = this._createMarker(e, this.options.moveIcon); + }, + _createResizeMarker: function () { + var t = this._getCorners(); + this._resizeMarkers = []; + for (var e = 0, i = t.length; i > e; e++) + this._resizeMarkers.push(this._createMarker(t[e], this.options.resizeIcon)), + (this._resizeMarkers[e]._cornerIndex = e); + }, + _onMarkerDragStart: function (t) { + L.Edit.SimpleShape.prototype._onMarkerDragStart.call(this, t); + var e = this._getCorners(), + i = t.target, + o = i._cornerIndex; + (this._oppositeCorner = e[(o + 2) % 4]), this._toggleCornerMarkers(0, o); + }, + _onMarkerDragEnd: function (t) { + var e, + i, + o = t.target; + o === this._moveMarker && + ((e = this._shape.getBounds()), (i = e.getCenter()), o.setLatLng(i)), + this._toggleCornerMarkers(1), + this._repositionCornerMarkers(), + L.Edit.SimpleShape.prototype._onMarkerDragEnd.call(this, t); + }, + _move: function (t) { + for ( + var e, + i = this._shape.getLatLngs(), + o = this._shape.getBounds(), + a = o.getCenter(), + s = [], + r = 0, + n = i.length; + n > r; + r++ + ) + (e = [i[r].lat - a.lat, i[r].lng - a.lng]), s.push([t.lat + e[0], t.lng + e[1]]); + this._shape.setLatLngs(s), this._repositionCornerMarkers(); + }, + _resize: function (t) { + var e; + this._shape.setBounds(L.latLngBounds(t, this._oppositeCorner)), + (e = this._shape.getBounds()), + this._moveMarker.setLatLng(e.getCenter()); + }, + _getCorners: function () { + var t = this._shape.getBounds(), + e = t.getNorthWest(), + i = t.getNorthEast(), + o = t.getSouthEast(), + a = t.getSouthWest(); + return [e, i, o, a]; + }, + _toggleCornerMarkers: function (t) { + for (var e = 0, i = this._resizeMarkers.length; i > e; e++) + this._resizeMarkers[e].setOpacity(t); + }, + _repositionCornerMarkers: function () { + for (var t = this._getCorners(), e = 0, i = this._resizeMarkers.length; i > e; e++) + this._resizeMarkers[e].setLatLng(t[e]); + }, + })), + L.Rectangle.addInitHook(function () { + L.Edit.Rectangle && + ((this.editing = new L.Edit.Rectangle(this)), this.options.editable && this.editing.enable()); + }), + (L.Edit = L.Edit || {}), + (L.Edit.Circle = L.Edit.SimpleShape.extend({ + _createMoveMarker: function () { + var t = this._shape.getLatLng(); + this._moveMarker = this._createMarker(t, this.options.moveIcon); + }, + _createResizeMarker: function () { + var t = this._shape.getLatLng(), + e = this._getResizeMarkerPoint(t); + (this._resizeMarkers = []), + this._resizeMarkers.push(this._createMarker(e, this.options.resizeIcon)); + }, + _getResizeMarkerPoint: function (t) { + var e = this._shape._radius * Math.cos(Math.PI / 4), + i = this._map.project(t); + return this._map.unproject([i.x + e, i.y - e]); + }, + _move: function (t) { + var e = this._getResizeMarkerPoint(t); + this._resizeMarkers[0].setLatLng(e), this._shape.setLatLng(t); + }, + _resize: function (t) { + var e = this._moveMarker.getLatLng(), + i = e.distanceTo(t); + this._shape.setRadius(i); + }, + })), + L.Circle.addInitHook(function () { + L.Edit.Circle && + ((this.editing = new L.Edit.Circle(this)), this.options.editable && this.editing.enable()), + this.on("add", function () { + this.editing && this.editing.enabled() && this.editing.addHooks(); + }), + this.on("remove", function () { + this.editing && this.editing.enabled() && this.editing.removeHooks(); + }); + }), + (L.LatLngUtil = { + cloneLatLngs: function (t) { + for (var e = [], i = 0, o = t.length; o > i; i++) e.push(this.cloneLatLng(t[i])); + return e; + }, + cloneLatLng: function (t) { + return L.latLng(t.lat, t.lng); + }, + }), + (L.GeometryUtil = L.extend(L.GeometryUtil || {}, { + geodesicArea: function (t) { + var e, + i, + o = t.length, + a = 0, + s = L.LatLng.DEG_TO_RAD; + if (o > 2) { + for (var r = 0; o > r; r++) + (e = t[r]), + (i = t[(r + 1) % o]), + (a += (i.lng - e.lng) * s * (2 + Math.sin(e.lat * s) + Math.sin(i.lat * s))); + a = (6378137 * a * 6378137) / 2; + } + return Math.abs(a); + }, + readableArea: function (t, e) { + var i; + return ( + e + ? (i = t >= 1e4 ? (1e-4 * t).toFixed(2) + " ha" : t.toFixed(2) + " m²") + : ((t *= 0.836127), + (i = + t >= 3097600 + ? (t / 3097600).toFixed(2) + " mi²" + : t >= 4840 + ? (t / 4840).toFixed(2) + " acres" + : Math.ceil(t) + " yd²")), + i + ); + }, + readableDistance: function (t, e) { + var i; + return ( + e + ? (i = t > 1e3 ? (t / 1e3).toFixed(2) + " km" : Math.ceil(t) + " m") + : ((t *= 1.09361), + (i = t > 1760 ? (t / 1760).toFixed(2) + " miles" : Math.ceil(t) + " yd")), + i + ); + }, + })), + L.Util.extend(L.LineUtil, { + segmentsIntersect: function (t, e, i, o) { + return ( + this._checkCounterclockwise(t, i, o) !== this._checkCounterclockwise(e, i, o) && + this._checkCounterclockwise(t, e, i) !== this._checkCounterclockwise(t, e, o) + ); + }, + _checkCounterclockwise: function (t, e, i) { + return (i.y - t.y) * (e.x - t.x) > (e.y - t.y) * (i.x - t.x); + }, + }), + L.Polyline.include({ + intersects: function () { + var t, + e, + i, + o = this._originalPoints, + a = o ? o.length : 0; + if (this._tooFewPointsForIntersection()) return !1; + for (t = a - 1; t >= 3; t--) + if (((e = o[t - 1]), (i = o[t]), this._lineSegmentsIntersectsRange(e, i, t - 2))) + return !0; + return !1; + }, + newLatLngIntersects: function (t, e) { + return this._map ? this.newPointIntersects(this._map.latLngToLayerPoint(t), e) : !1; + }, + newPointIntersects: function (t, e) { + var i = this._originalPoints, + o = i ? i.length : 0, + a = i ? i[o - 1] : null, + s = o - 2; + return this._tooFewPointsForIntersection(1) + ? !1 + : this._lineSegmentsIntersectsRange(a, t, s, e ? 1 : 0); + }, + _tooFewPointsForIntersection: function (t) { + var e = this._originalPoints, + i = e ? e.length : 0; + return (i += t || 0), !this._originalPoints || 3 >= i; + }, + _lineSegmentsIntersectsRange: function (t, e, i, o) { + var a, + s, + r = this._originalPoints; + o = o || 0; + for (var n = i; n > o; n--) + if (((a = r[n - 1]), (s = r[n]), L.LineUtil.segmentsIntersect(t, e, a, s))) return !0; + return !1; + }, + }), + L.Polygon.include({ + intersects: function () { + var t, + e, + i, + o, + a, + s = this._originalPoints; + return this._tooFewPointsForIntersection() + ? !1 + : (t = L.Polyline.prototype.intersects.call(this)) + ? !0 + : ((e = s.length), + (i = s[0]), + (o = s[e - 1]), + (a = e - 2), + this._lineSegmentsIntersectsRange(o, i, a, 1)); + }, + }), + (L.Control.Draw = L.Control.extend({ + options: { position: "topleft", draw: {}, edit: !1 }, + initialize: function (t) { + if (L.version < "0.7") + throw new Error( + "Leaflet.draw 0.2.3+ requires Leaflet 0.7.0+. Download latest from https://github.com/Leaflet/Leaflet/" + ); + L.Control.prototype.initialize.call(this, t); + var e, i; + (this._toolbars = {}), + L.DrawToolbar && + this.options.draw && + ((i = new L.DrawToolbar(this.options.draw)), + (e = L.stamp(i)), + (this._toolbars[e] = i), + this._toolbars[e].on("enable", this._toolbarEnabled, this)), + L.EditToolbar && + this.options.edit && + ((i = new L.EditToolbar(this.options.edit)), + (e = L.stamp(i)), + (this._toolbars[e] = i), + this._toolbars[e].on("enable", this._toolbarEnabled, this)); + }, + onAdd: function (t) { + var e, + i = L.DomUtil.create("div", "leaflet-draw"), + o = !1, + a = "leaflet-draw-toolbar-top"; + for (var s in this._toolbars) + this._toolbars.hasOwnProperty(s) && + ((e = this._toolbars[s].addToolbar(t)), + e && + (o || + (L.DomUtil.hasClass(e, a) || L.DomUtil.addClass(e.childNodes[0], a), + (o = !0)), + i.appendChild(e))); + return i; + }, + onRemove: function () { + for (var t in this._toolbars) + this._toolbars.hasOwnProperty(t) && this._toolbars[t].removeToolbar(); + }, + setDrawingOptions: function (t) { + for (var e in this._toolbars) + this._toolbars[e] instanceof L.DrawToolbar && this._toolbars[e].setOptions(t); + }, + _toolbarEnabled: function (t) { + var e = "" + L.stamp(t.target); + for (var i in this._toolbars) + this._toolbars.hasOwnProperty(i) && i !== e && this._toolbars[i].disable(); + }, + })), + L.Map.mergeOptions({ drawControlTooltips: !0, drawControl: !1 }), + L.Map.addInitHook(function () { + this.options.drawControl && + ((this.drawControl = new L.Control.Draw()), this.addControl(this.drawControl)); + }), + (L.Toolbar = L.Class.extend({ + includes: [L.Mixin.Events], + initialize: function (t) { + L.setOptions(this, t), + (this._modes = {}), + (this._actionButtons = []), + (this._activeMode = null); + }, + enabled: function () { + return null !== this._activeMode; + }, + disable: function () { + this.enabled() && this._activeMode.handler.disable(); + }, + addToolbar: function (t) { + var e, + i = L.DomUtil.create("div", "leaflet-draw-section"), + o = 0, + a = this._toolbarClass || "", + s = this.getModeHandlers(t); + for ( + this._toolbarContainer = L.DomUtil.create("div", "leaflet-draw-toolbar leaflet-bar"), + this._map = t, + e = 0; + e < s.length; + e++ + ) + s[e].enabled && + this._initModeHandler(s[e].handler, this._toolbarContainer, o++, a, s[e].title); + return o + ? ((this._lastButtonIndex = --o), + (this._actionsContainer = L.DomUtil.create("ul", "leaflet-draw-actions")), + i.appendChild(this._toolbarContainer), + i.appendChild(this._actionsContainer), + i) + : void 0; + }, + removeToolbar: function () { + for (var t in this._modes) + this._modes.hasOwnProperty(t) && + (this._disposeButton( + this._modes[t].button, + this._modes[t].handler.enable, + this._modes[t].handler + ), + this._modes[t].handler.disable(), + this._modes[t].handler + .off("enabled", this._handlerActivated, this) + .off("disabled", this._handlerDeactivated, this)); + this._modes = {}; + for (var e = 0, i = this._actionButtons.length; i > e; e++) + this._disposeButton(this._actionButtons[e].button, this._actionButtons[e].callback, this); + (this._actionButtons = []), (this._actionsContainer = null); + }, + _initModeHandler: function (t, e, i, o, a) { + var s = t.type; + (this._modes[s] = {}), + (this._modes[s].handler = t), + (this._modes[s].button = this._createButton({ + title: a, + className: o + "-" + s, + container: e, + callback: this._modes[s].handler.enable, + context: this._modes[s].handler, + })), + (this._modes[s].buttonIndex = i), + this._modes[s].handler + .on("enabled", this._handlerActivated, this) + .on("disabled", this._handlerDeactivated, this); + }, + _createButton: function (t) { + var e = L.DomUtil.create("a", t.className || "", t.container); + return ( + (e.href = "#"), + t.text && (e.innerHTML = t.text), + t.title && (e.title = t.title), + L.DomEvent.on(e, "click", L.DomEvent.stopPropagation) + .on(e, "mousedown", L.DomEvent.stopPropagation) + .on(e, "dblclick", L.DomEvent.stopPropagation) + .on(e, "click", L.DomEvent.preventDefault) + .on(e, "click", t.callback, t.context), + e + ); + }, + _disposeButton: function (t, e) { + L.DomEvent.off(t, "click", L.DomEvent.stopPropagation) + .off(t, "mousedown", L.DomEvent.stopPropagation) + .off(t, "dblclick", L.DomEvent.stopPropagation) + .off(t, "click", L.DomEvent.preventDefault) + .off(t, "click", e); + }, + _handlerActivated: function (t) { + this.disable(), + (this._activeMode = this._modes[t.handler]), + L.DomUtil.addClass(this._activeMode.button, "leaflet-draw-toolbar-button-enabled"), + this._showActionsToolbar(), + this.fire("enable"); + }, + _handlerDeactivated: function () { + this._hideActionsToolbar(), + L.DomUtil.removeClass(this._activeMode.button, "leaflet-draw-toolbar-button-enabled"), + (this._activeMode = null), + this.fire("disable"); + }, + _createActions: function (t) { + var e, + i, + o, + a, + s = this._actionsContainer, + r = this.getActions(t), + n = r.length; + for (i = 0, o = this._actionButtons.length; o > i; i++) + this._disposeButton(this._actionButtons[i].button, this._actionButtons[i].callback); + for (this._actionButtons = []; s.firstChild; ) s.removeChild(s.firstChild); + for (var l = 0; n > l; l++) + ("enabled" in r[l] && !r[l].enabled) || + ((e = L.DomUtil.create("li", "", s)), + (a = this._createButton({ + title: r[l].title, + text: r[l].text, + container: e, + callback: r[l].callback, + context: r[l].context, + })), + this._actionButtons.push({ button: a, callback: r[l].callback })); + }, + _showActionsToolbar: function () { + var t = this._activeMode.buttonIndex, + e = this._lastButtonIndex, + i = this._activeMode.button.offsetTop - 1; + this._createActions(this._activeMode.handler), + (this._actionsContainer.style.top = i + "px"), + 0 === t && + (L.DomUtil.addClass(this._toolbarContainer, "leaflet-draw-toolbar-notop"), + L.DomUtil.addClass(this._actionsContainer, "leaflet-draw-actions-top")), + t === e && + (L.DomUtil.addClass(this._toolbarContainer, "leaflet-draw-toolbar-nobottom"), + L.DomUtil.addClass(this._actionsContainer, "leaflet-draw-actions-bottom")), + (this._actionsContainer.style.display = "block"); + }, + _hideActionsToolbar: function () { + (this._actionsContainer.style.display = "none"), + L.DomUtil.removeClass(this._toolbarContainer, "leaflet-draw-toolbar-notop"), + L.DomUtil.removeClass(this._toolbarContainer, "leaflet-draw-toolbar-nobottom"), + L.DomUtil.removeClass(this._actionsContainer, "leaflet-draw-actions-top"), + L.DomUtil.removeClass(this._actionsContainer, "leaflet-draw-actions-bottom"); + }, + })), + (L.Tooltip = L.Class.extend({ + initialize: function (t) { + (this._map = t), + (this._popupPane = t._panes.popupPane), + (this._container = t.options.drawControlTooltips + ? L.DomUtil.create("div", "leaflet-draw-tooltip", this._popupPane) + : null), + (this._singleLineLabel = !1); + }, + dispose: function () { + this._container && (this._popupPane.removeChild(this._container), (this._container = null)); + }, + updateContent: function (t) { + return this._container + ? ((t.subtext = t.subtext || ""), + 0 !== t.subtext.length || this._singleLineLabel + ? t.subtext.length > 0 && + this._singleLineLabel && + (L.DomUtil.removeClass(this._container, "leaflet-draw-tooltip-single"), + (this._singleLineLabel = !1)) + : (L.DomUtil.addClass(this._container, "leaflet-draw-tooltip-single"), + (this._singleLineLabel = !0)), + (this._container.innerHTML = + (t.subtext.length > 0 + ? '' + t.subtext + "
              " + : "") + + "" + + t.text + + ""), + this) + : this; + }, + updatePosition: function (t) { + var e = this._map.latLngToLayerPoint(t), + i = this._container; + return ( + this._container && ((i.style.visibility = "inherit"), L.DomUtil.setPosition(i, e)), this + ); + }, + showAsError: function () { + return ( + this._container && L.DomUtil.addClass(this._container, "leaflet-error-draw-tooltip"), this + ); + }, + removeError: function () { + return ( + this._container && L.DomUtil.removeClass(this._container, "leaflet-error-draw-tooltip"), + this + ); + }, + })), + (L.DrawToolbar = L.Toolbar.extend({ + options: { polyline: {}, polygon: {}, rectangle: {}, circle: {}, marker: {} }, + initialize: function (t) { + for (var e in this.options) + this.options.hasOwnProperty(e) && t[e] && (t[e] = L.extend({}, this.options[e], t[e])); + (this._toolbarClass = "leaflet-draw-draw"), L.Toolbar.prototype.initialize.call(this, t); + }, + getModeHandlers: function (t) { + return [ + { + enabled: this.options.polyline, + handler: new L.Draw.Polyline(t, this.options.polyline), + title: L.drawLocal.draw.toolbar.buttons.polyline, + }, + { + enabled: this.options.polygon, + handler: new L.Draw.Polygon(t, this.options.polygon), + title: L.drawLocal.draw.toolbar.buttons.polygon, + }, + { + enabled: this.options.rectangle, + handler: new L.Draw.Rectangle(t, this.options.rectangle), + title: L.drawLocal.draw.toolbar.buttons.rectangle, + }, + { + enabled: this.options.circle, + handler: new L.Draw.Circle(t, this.options.circle), + title: L.drawLocal.draw.toolbar.buttons.circle, + }, + { + enabled: this.options.marker, + handler: new L.Draw.Marker(t, this.options.marker), + title: L.drawLocal.draw.toolbar.buttons.marker, + }, + ]; + }, + getActions: function (t) { + return [ + { + enabled: t.deleteLastVertex, + title: L.drawLocal.draw.toolbar.undo.title, + text: L.drawLocal.draw.toolbar.undo.text, + callback: t.deleteLastVertex, + context: t, + }, + { + title: L.drawLocal.draw.toolbar.actions.title, + text: L.drawLocal.draw.toolbar.actions.text, + callback: this.disable, + context: this, + }, + ]; + }, + setOptions: function (t) { + L.setOptions(this, t); + for (var e in this._modes) + this._modes.hasOwnProperty(e) && + t.hasOwnProperty(e) && + this._modes[e].handler.setOptions(t[e]); + }, + })), + (L.EditToolbar = L.Toolbar.extend({ + options: { + edit: { + selectedPathOptions: { + color: "#fe57a1", + opacity: 0.6, + dashArray: "10, 10", + fill: !0, + fillColor: "#fe57a1", + fillOpacity: 0.1, + }, + }, + remove: {}, + featureGroup: null, + }, + initialize: function (t) { + t.edit && + ("undefined" == typeof t.edit.selectedPathOptions && + (t.edit.selectedPathOptions = this.options.edit.selectedPathOptions), + (t.edit = L.extend({}, this.options.edit, t.edit))), + t.remove && (t.remove = L.extend({}, this.options.remove, t.remove)), + (this._toolbarClass = "leaflet-draw-edit"), + L.Toolbar.prototype.initialize.call(this, t), + (this._selectedFeatureCount = 0); + }, + getModeHandlers: function (t) { + var e = this.options.featureGroup; + return [ + { + enabled: this.options.edit, + handler: new L.EditToolbar.Edit(t, { + featureGroup: e, + selectedPathOptions: this.options.edit.selectedPathOptions, + }), + title: L.drawLocal.edit.toolbar.buttons.edit, + }, + { + enabled: this.options.remove, + handler: new L.EditToolbar.Delete(t, { featureGroup: e }), + title: L.drawLocal.edit.toolbar.buttons.remove, + }, + ]; + }, + getActions: function () { + return [ + { + title: L.drawLocal.edit.toolbar.actions.save.title, + text: L.drawLocal.edit.toolbar.actions.save.text, + callback: this._save, + context: this, + }, + { + title: L.drawLocal.edit.toolbar.actions.cancel.title, + text: L.drawLocal.edit.toolbar.actions.cancel.text, + callback: this.disable, + context: this, + }, + ]; + }, + addToolbar: function (t) { + var e = L.Toolbar.prototype.addToolbar.call(this, t); + return ( + this._checkDisabled(), + this.options.featureGroup.on("layeradd layerremove", this._checkDisabled, this), + e + ); + }, + removeToolbar: function () { + this.options.featureGroup.off("layeradd layerremove", this._checkDisabled, this), + L.Toolbar.prototype.removeToolbar.call(this); + }, + disable: function () { + this.enabled() && + (this._activeMode.handler.revertLayers(), L.Toolbar.prototype.disable.call(this)); + }, + _save: function () { + this._activeMode.handler.save(), this._activeMode.handler.disable(); + }, + _checkDisabled: function () { + var t, + e = this.options.featureGroup, + i = 0 !== e.getLayers().length; + this.options.edit && + ((t = this._modes[L.EditToolbar.Edit.TYPE].button), + i + ? L.DomUtil.removeClass(t, "leaflet-disabled") + : L.DomUtil.addClass(t, "leaflet-disabled"), + t.setAttribute( + "title", + i + ? L.drawLocal.edit.toolbar.buttons.edit + : L.drawLocal.edit.toolbar.buttons.editDisabled + )), + this.options.remove && + ((t = this._modes[L.EditToolbar.Delete.TYPE].button), + i + ? L.DomUtil.removeClass(t, "leaflet-disabled") + : L.DomUtil.addClass(t, "leaflet-disabled"), + t.setAttribute( + "title", + i + ? L.drawLocal.edit.toolbar.buttons.remove + : L.drawLocal.edit.toolbar.buttons.removeDisabled + )); + }, + })), + (L.EditToolbar.Edit = L.Handler.extend({ + statics: { TYPE: "edit" }, + includes: L.Mixin.Events, + initialize: function (t, e) { + if ( + (L.Handler.prototype.initialize.call(this, t), + (this._selectedPathOptions = e.selectedPathOptions), + (this._featureGroup = e.featureGroup), + !(this._featureGroup instanceof L.FeatureGroup)) + ) + throw new Error("options.featureGroup must be a L.FeatureGroup"); + (this._uneditedLayerProps = {}), (this.type = L.EditToolbar.Edit.TYPE); + }, + enable: function () { + !this._enabled && + this._hasAvailableLayers() && + (this.fire("enabled", { handler: this.type }), + this._map.fire("draw:editstart", { handler: this.type }), + L.Handler.prototype.enable.call(this), + this._featureGroup + .on("layeradd", this._enableLayerEdit, this) + .on("layerremove", this._disableLayerEdit, this)); + }, + disable: function () { + this._enabled && + (this._featureGroup + .off("layeradd", this._enableLayerEdit, this) + .off("layerremove", this._disableLayerEdit, this), + L.Handler.prototype.disable.call(this), + this._map.fire("draw:editstop", { handler: this.type }), + this.fire("disabled", { handler: this.type })); + }, + addHooks: function () { + var t = this._map; + t && + (t.getContainer().focus(), + this._featureGroup.eachLayer(this._enableLayerEdit, this), + (this._tooltip = new L.Tooltip(this._map)), + this._tooltip.updateContent({ + text: L.drawLocal.edit.handlers.edit.tooltip.text, + subtext: L.drawLocal.edit.handlers.edit.tooltip.subtext, + }), + this._map.on("mousemove", this._onMouseMove, this)); + }, + removeHooks: function () { + this._map && + (this._featureGroup.eachLayer(this._disableLayerEdit, this), + (this._uneditedLayerProps = {}), + this._tooltip.dispose(), + (this._tooltip = null), + this._map.off("mousemove", this._onMouseMove, this)); + }, + revertLayers: function () { + this._featureGroup.eachLayer(function (t) { + this._revertLayer(t); + }, this); + }, + save: function () { + var t = new L.LayerGroup(); + this._featureGroup.eachLayer(function (e) { + e.edited && (t.addLayer(e), (e.edited = !1)); + }), + this._map.fire("draw:edited", { layers: t }); + }, + _backupLayer: function (t) { + var e = L.Util.stamp(t); + this._uneditedLayerProps[e] || + (t instanceof L.Polyline || t instanceof L.Polygon || t instanceof L.Rectangle + ? (this._uneditedLayerProps[e] = { + latlngs: L.LatLngUtil.cloneLatLngs(t.getLatLngs()), + }) + : t instanceof L.Circle + ? (this._uneditedLayerProps[e] = { + latlng: L.LatLngUtil.cloneLatLng(t.getLatLng()), + radius: t.getRadius(), + }) + : t instanceof L.Marker && + (this._uneditedLayerProps[e] = { + latlng: L.LatLngUtil.cloneLatLng(t.getLatLng()), + })); + }, + _revertLayer: function (t) { + var e = L.Util.stamp(t); + (t.edited = !1), + this._uneditedLayerProps.hasOwnProperty(e) && + (t instanceof L.Polyline || t instanceof L.Polygon || t instanceof L.Rectangle + ? t.setLatLngs(this._uneditedLayerProps[e].latlngs) + : t instanceof L.Circle + ? (t.setLatLng(this._uneditedLayerProps[e].latlng), + t.setRadius(this._uneditedLayerProps[e].radius)) + : t instanceof L.Marker && t.setLatLng(this._uneditedLayerProps[e].latlng)); + }, + _toggleMarkerHighlight: function (t) { + if (t._icon) { + var e = t._icon; + (e.style.display = "none"), + L.DomUtil.hasClass(e, "leaflet-edit-marker-selected") + ? (L.DomUtil.removeClass(e, "leaflet-edit-marker-selected"), + this._offsetMarker(e, -4)) + : (L.DomUtil.addClass(e, "leaflet-edit-marker-selected"), + this._offsetMarker(e, 4)), + (e.style.display = ""); + } + }, + _offsetMarker: function (t, e) { + var i = parseInt(t.style.marginTop, 10) - e, + o = parseInt(t.style.marginLeft, 10) - e; + (t.style.marginTop = i + "px"), (t.style.marginLeft = o + "px"); + }, + _enableLayerEdit: function (t) { + var e, + i = t.layer || t.target || t, + o = i instanceof L.Marker; + (!o || i._icon) && + (this._backupLayer(i), + this._selectedPathOptions && + ((e = L.Util.extend({}, this._selectedPathOptions)), + o + ? this._toggleMarkerHighlight(i) + : ((i.options.previousOptions = L.Util.extend({ dashArray: null }, i.options)), + i instanceof L.Circle || + i instanceof L.Polygon || + i instanceof L.Rectangle || + (e.fill = !1), + i.setStyle(e))), + o ? (i.dragging.enable(), i.on("dragend", this._onMarkerDragEnd)) : i.editing.enable()); + }, + _disableLayerEdit: function (t) { + var e = t.layer || t.target || t; + (e.edited = !1), + this._selectedPathOptions && + (e instanceof L.Marker + ? this._toggleMarkerHighlight(e) + : (e.setStyle(e.options.previousOptions), delete e.options.previousOptions)), + e instanceof L.Marker + ? (e.dragging.disable(), e.off("dragend", this._onMarkerDragEnd, this)) + : e.editing.disable(); + }, + _onMarkerDragEnd: function (t) { + var e = t.target; + e.edited = !0; + }, + _onMouseMove: function (t) { + this._tooltip.updatePosition(t.latlng); + }, + _hasAvailableLayers: function () { + return 0 !== this._featureGroup.getLayers().length; + }, + })), + (L.EditToolbar.Delete = L.Handler.extend({ + statics: { TYPE: "remove" }, + includes: L.Mixin.Events, + initialize: function (t, e) { + if ( + (L.Handler.prototype.initialize.call(this, t), + L.Util.setOptions(this, e), + (this._deletableLayers = this.options.featureGroup), + !(this._deletableLayers instanceof L.FeatureGroup)) + ) + throw new Error("options.featureGroup must be a L.FeatureGroup"); + this.type = L.EditToolbar.Delete.TYPE; + }, + enable: function () { + !this._enabled && + this._hasAvailableLayers() && + (this.fire("enabled", { handler: this.type }), + this._map.fire("draw:deletestart", { handler: this.type }), + L.Handler.prototype.enable.call(this), + this._deletableLayers + .on("layeradd", this._enableLayerDelete, this) + .on("layerremove", this._disableLayerDelete, this)); + }, + disable: function () { + this._enabled && + (this._deletableLayers + .off("layeradd", this._enableLayerDelete, this) + .off("layerremove", this._disableLayerDelete, this), + L.Handler.prototype.disable.call(this), + this._map.fire("draw:deletestop", { handler: this.type }), + this.fire("disabled", { handler: this.type })); + }, + addHooks: function () { + var t = this._map; + t && + (t.getContainer().focus(), + this._deletableLayers.eachLayer(this._enableLayerDelete, this), + (this._deletedLayers = new L.layerGroup()), + (this._tooltip = new L.Tooltip(this._map)), + this._tooltip.updateContent({ text: L.drawLocal.edit.handlers.remove.tooltip.text }), + this._map.on("mousemove", this._onMouseMove, this)); + }, + removeHooks: function () { + this._map && + (this._deletableLayers.eachLayer(this._disableLayerDelete, this), + (this._deletedLayers = null), + this._tooltip.dispose(), + (this._tooltip = null), + this._map.off("mousemove", this._onMouseMove, this)); + }, + revertLayers: function () { + this._deletedLayers.eachLayer(function (t) { + this._deletableLayers.addLayer(t); + }, this); + }, + save: function () { + this._map.fire("draw:deleted", { layers: this._deletedLayers }); + }, + _enableLayerDelete: function (t) { + var e = t.layer || t.target || t; + e.on("click", this._removeLayer, this); + }, + _disableLayerDelete: function (t) { + var e = t.layer || t.target || t; + e.off("click", this._removeLayer, this), this._deletedLayers.removeLayer(e); + }, + _removeLayer: function (t) { + var e = t.layer || t.target || t; + this._deletableLayers.removeLayer(e), this._deletedLayers.addLayer(e); + }, + _onMouseMove: function (t) { + this._tooltip.updatePosition(t.latlng); + }, + _hasAvailableLayers: function () { + return 0 !== this._deletableLayers.getLayers().length; + }, + })); +})(window, document); diff --git a/erpnext/public/js/leaflet/leaflet.js b/erpnext/public/js/leaflet/leaflet.js index 91dd3d434c77..cef823a2e1a7 100755 --- a/erpnext/public/js/leaflet/leaflet.js +++ b/erpnext/public/js/leaflet/leaflet.js @@ -2,770 +2,5633 @@ Leaflet 1.0.0-beta.2 (dd0faa1), a JS library for interactive maps. http://leafletjs.com (c) 2010-2015 Vladimir Agafonkin, (c) 2010-2011 CloudMade */ -! function(t, e, i) { - function n() { var e = t.L; - o.noConflict = function() { return t.L = e, this }, t.L = o } - var o = { version: "1.0.0-beta.2" }; - "object" == typeof module && "object" == typeof module.exports ? module.exports = o : "function" == typeof define && define.amd && define(o), "undefined" != typeof t && n(), o.Util = { extend: function(t) { var e, i, n, o; for (i = 1, n = arguments.length; n > i; i++) { o = arguments[i]; for (e in o) t[e] = o[e] } return t }, create: Object.create || function() { - function t() {} return function(e) { return t.prototype = e, new t } }(), bind: function(t, e) { var i = Array.prototype.slice; if (t.bind) return t.bind.apply(t, i.call(arguments, 1)); var n = i.call(arguments, 2); return function() { return t.apply(e, n.length ? n.concat(i.call(arguments)) : arguments) } }, stamp: function(t) { return t._leaflet_id = t._leaflet_id || ++o.Util.lastId, t._leaflet_id }, lastId: 0, throttle: function(t, e, i) { var n, o, s, r; return r = function() { n = !1, o && (s.apply(i, o), o = !1) }, s = function() { n ? o = arguments : (t.apply(i, arguments), setTimeout(r, e), n = !0) } }, wrapNum: function(t, e, i) { var n = e[1], - o = e[0], - s = n - o; return t === n && i ? t : ((t - o) % s + s) % s + o }, falseFn: function() { return !1 }, formatNum: function(t, e) { var i = Math.pow(10, e || 5); return Math.round(t * i) / i }, trim: function(t) { return t.trim ? t.trim() : t.replace(/^\s+|\s+$/g, "") }, splitWords: function(t) { return o.Util.trim(t).split(/\s+/) }, setOptions: function(t, e) { t.hasOwnProperty("options") || (t.options = t.options ? o.Util.create(t.options) : {}); for (var i in e) t.options[i] = e[i]; return t.options }, getParamString: function(t, e, i) { var n = []; for (var o in t) n.push(encodeURIComponent(i ? o.toUpperCase() : o) + "=" + encodeURIComponent(t[o])); return (e && -1 !== e.indexOf("?") ? "&" : "?") + n.join("&") }, template: function(t, e) { return t.replace(o.Util.templateRe, function(t, n) { var o = e[n]; if (o === i) throw new Error("No value provided for variable " + t); return "function" == typeof o && (o = o(e)), o }) }, templateRe: /\{ *([\w_]+) *\}/g, isArray: Array.isArray || function(t) { return "[object Array]" === Object.prototype.toString.call(t) }, indexOf: function(t, e) { for (var i = 0; i < t.length; i++) - if (t[i] === e) return i; - return -1 }, emptyImageUrl: "data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=" }, - function() { - function e(e) { return t["webkit" + e] || t["moz" + e] || t["ms" + e] } +!(function (t, e, i) { + function n() { + var e = t.L; + (o.noConflict = function () { + return (t.L = e), this; + }), + (t.L = o); + } + var o = { version: "1.0.0-beta.2" }; + "object" == typeof module && "object" == typeof module.exports + ? (module.exports = o) + : "function" == typeof define && define.amd && define(o), + "undefined" != typeof t && n(), + (o.Util = { + extend: function (t) { + var e, i, n, o; + for (i = 1, n = arguments.length; n > i; i++) { + o = arguments[i]; + for (e in o) t[e] = o[e]; + } + return t; + }, + create: + Object.create || + (function () { + function t() {} + return function (e) { + return (t.prototype = e), new t(); + }; + })(), + bind: function (t, e) { + var i = Array.prototype.slice; + if (t.bind) return t.bind.apply(t, i.call(arguments, 1)); + var n = i.call(arguments, 2); + return function () { + return t.apply(e, n.length ? n.concat(i.call(arguments)) : arguments); + }; + }, + stamp: function (t) { + return (t._leaflet_id = t._leaflet_id || ++o.Util.lastId), t._leaflet_id; + }, + lastId: 0, + throttle: function (t, e, i) { + var n, o, s, r; + return ( + (r = function () { + (n = !1), o && (s.apply(i, o), (o = !1)); + }), + (s = function () { + n ? (o = arguments) : (t.apply(i, arguments), setTimeout(r, e), (n = !0)); + }) + ); + }, + wrapNum: function (t, e, i) { + var n = e[1], + o = e[0], + s = n - o; + return t === n && i ? t : ((((t - o) % s) + s) % s) + o; + }, + falseFn: function () { + return !1; + }, + formatNum: function (t, e) { + var i = Math.pow(10, e || 5); + return Math.round(t * i) / i; + }, + trim: function (t) { + return t.trim ? t.trim() : t.replace(/^\s+|\s+$/g, ""); + }, + splitWords: function (t) { + return o.Util.trim(t).split(/\s+/); + }, + setOptions: function (t, e) { + t.hasOwnProperty("options") || (t.options = t.options ? o.Util.create(t.options) : {}); + for (var i in e) t.options[i] = e[i]; + return t.options; + }, + getParamString: function (t, e, i) { + var n = []; + for (var o in t) + n.push(encodeURIComponent(i ? o.toUpperCase() : o) + "=" + encodeURIComponent(t[o])); + return (e && -1 !== e.indexOf("?") ? "&" : "?") + n.join("&"); + }, + template: function (t, e) { + return t.replace(o.Util.templateRe, function (t, n) { + var o = e[n]; + if (o === i) throw new Error("No value provided for variable " + t); + return "function" == typeof o && (o = o(e)), o; + }); + }, + templateRe: /\{ *([\w_]+) *\}/g, + isArray: + Array.isArray || + function (t) { + return "[object Array]" === Object.prototype.toString.call(t); + }, + indexOf: function (t, e) { + for (var i = 0; i < t.length; i++) if (t[i] === e) return i; + return -1; + }, + emptyImageUrl: "data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=", + }), + (function () { + function e(e) { + return t["webkit" + e] || t["moz" + e] || t["ms" + e]; + } - function i(e) { var i = +new Date, - o = Math.max(0, 16 - (i - n)); return n = i + o, t.setTimeout(e, o) } var n = 0, - s = t.requestAnimationFrame || e("RequestAnimationFrame") || i, - r = t.cancelAnimationFrame || e("CancelAnimationFrame") || e("CancelRequestAnimationFrame") || function(e) { t.clearTimeout(e) }; - o.Util.requestAnimFrame = function(e, n, r) { return r && s === i ? void e.call(n) : s.call(t, o.bind(e, n)) }, o.Util.cancelAnimFrame = function(e) { e && r.call(t, e) } }(), o.extend = o.Util.extend, o.bind = o.Util.bind, o.stamp = o.Util.stamp, o.setOptions = o.Util.setOptions, o.Class = function() {}, o.Class.extend = function(t) { var e = function() { this.initialize && this.initialize.apply(this, arguments), this.callInitHooks() }, - i = e.__super__ = this.prototype, - n = o.Util.create(i); - n.constructor = e, e.prototype = n; for (var s in this) this.hasOwnProperty(s) && "prototype" !== s && (e[s] = this[s]); return t.statics && (o.extend(e, t.statics), delete t.statics), t.includes && (o.Util.extend.apply(null, [n].concat(t.includes)), delete t.includes), n.options && (t.options = o.Util.extend(o.Util.create(n.options), t.options)), o.extend(n, t), n._initHooks = [], n.callInitHooks = function() { if (!this._initHooksCalled) { i.callInitHooks && i.callInitHooks.call(this), this._initHooksCalled = !0; for (var t = 0, e = n._initHooks.length; e > t; t++) n._initHooks[t].call(this) } }, e }, o.Class.include = function(t) { o.extend(this.prototype, t) }, o.Class.mergeOptions = function(t) { o.extend(this.prototype.options, t) }, o.Class.addInitHook = function(t) { var e = Array.prototype.slice.call(arguments, 1), - i = "function" == typeof t ? t : function() { this[t].apply(this, e) }; - this.prototype._initHooks = this.prototype._initHooks || [], this.prototype._initHooks.push(i) }, o.Evented = o.Class.extend({ on: function(t, e, i) { if ("object" == typeof t) - for (var n in t) this._on(n, t[n], e); - else { t = o.Util.splitWords(t); for (var s = 0, r = t.length; r > s; s++) this._on(t[s], e, i) } return this }, off: function(t, e, i) { if (t) - if ("object" == typeof t) - for (var n in t) this._off(n, t[n], e); - else { t = o.Util.splitWords(t); for (var s = 0, r = t.length; r > s; s++) this._off(t[s], e, i) } - else delete this._events; return this }, _on: function(t, e, i) { var n = this._events = this._events || {}, - s = i && i !== this && o.stamp(i); if (s) { var r = t + "_idx", - a = t + "_len", - h = n[r] = n[r] || {}, - l = o.stamp(e) + "_" + s; - h[l] || (h[l] = { fn: e, ctx: i }, n[a] = (n[a] || 0) + 1) } else n[t] = n[t] || [], n[t].push({ fn: e }) }, _off: function(t, e, i) { var n = this._events, - s = t + "_idx", - r = t + "_len"; if (n) { if (!e) return delete n[t], delete n[s], void delete n[r]; var a, h, l, u, c, d = i && i !== this && o.stamp(i); if (d) c = o.stamp(e) + "_" + d, a = n[s], a && a[c] && (u = a[c], delete a[c], n[r]--); - else if (a = n[t]) - for (h = 0, l = a.length; l > h; h++) - if (a[h].fn === e) { u = a[h], a.splice(h, 1); break } - u && (u.fn = o.Util.falseFn) } }, fire: function(t, e, i) { if (!this.listens(t, i)) return this; var n = o.Util.extend({}, e, { type: t, target: this }), - s = this._events; if (s) { var r, a, h, l, u = s[t + "_idx"]; if (s[t]) - for (h = s[t].slice(), r = 0, a = h.length; a > r; r++) h[r].fn.call(this, n); for (l in u) u[l].fn.call(u[l].ctx, n) } return i && this._propagateEvent(n), this }, listens: function(t, e) { var i = this._events; if (i && (i[t] || i[t + "_len"])) return !0; if (e) - for (var n in this._eventParents) - if (this._eventParents[n].listens(t, e)) return !0; - return !1 }, once: function(t, e, i) { if ("object" == typeof t) { for (var n in t) this.once(n, t[n], e); return this } var s = o.bind(function() { this.off(t, e, i).off(t, s, i) }, this); return this.on(t, e, i).on(t, s, i) }, addEventParent: function(t) { return this._eventParents = this._eventParents || {}, this._eventParents[o.stamp(t)] = t, this }, removeEventParent: function(t) { return this._eventParents && delete this._eventParents[o.stamp(t)], this }, _propagateEvent: function(t) { for (var e in this._eventParents) this._eventParents[e].fire(t.type, o.extend({ layer: t.target }, t), !0) } }); - var s = o.Evented.prototype; - s.addEventListener = s.on, s.removeEventListener = s.clearAllEventListeners = s.off, s.addOneTimeEventListener = s.once, s.fireEvent = s.fire, s.hasEventListeners = s.listens, o.Mixin = { Events: s }, - function() { var i = navigator.userAgent.toLowerCase(), - n = e.documentElement, - s = "ActiveXObject" in t, - r = -1 !== i.indexOf("webkit"), - a = -1 !== i.indexOf("phantom"), - h = -1 !== i.search("android [23]"), - l = -1 !== i.indexOf("chrome"), - u = -1 !== i.indexOf("gecko") && !r && !t.opera && !s, - c = "undefined" != typeof orientation || -1 !== i.indexOf("mobile"), - d = !t.PointerEvent && t.MSPointerEvent, - _ = t.PointerEvent && navigator.pointerEnabled || d, - m = s && "transition" in n.style, - p = "WebKitCSSMatrix" in t && "m11" in new t.WebKitCSSMatrix && !h, - f = "MozPerspective" in n.style, - g = "OTransition" in n.style, - v = !t.L_NO_TOUCH && !a && (_ || "ontouchstart" in t || t.DocumentTouch && e instanceof t.DocumentTouch); - o.Browser = { ie: s, ielt9: s && !e.addEventListener, webkit: r, gecko: u, android: -1 !== i.indexOf("android"), android23: h, chrome: l, safari: !l && -1 !== i.indexOf("safari"), ie3d: m, webkit3d: p, gecko3d: f, opera12: g, any3d: !t.L_DISABLE_3D && (m || p || f) && !g && !a, mobile: c, mobileWebkit: c && r, mobileWebkit3d: c && p, mobileOpera: c && t.opera, mobileGecko: c && u, touch: !!v, msPointer: !!d, pointer: !!_, retina: (t.devicePixelRatio || t.screen.deviceXDPI / t.screen.logicalXDPI) > 1 } }(), o.Point = function(t, e, i) { this.x = i ? Math.round(t) : t, this.y = i ? Math.round(e) : e }, o.Point.prototype = { clone: function() { return new o.Point(this.x, this.y) }, add: function(t) { return this.clone()._add(o.point(t)) }, _add: function(t) { return this.x += t.x, this.y += t.y, this }, subtract: function(t) { return this.clone()._subtract(o.point(t)) }, _subtract: function(t) { return this.x -= t.x, this.y -= t.y, this }, divideBy: function(t) { return this.clone()._divideBy(t) }, _divideBy: function(t) { return this.x /= t, this.y /= t, this }, multiplyBy: function(t) { return this.clone()._multiplyBy(t) }, _multiplyBy: function(t) { return this.x *= t, this.y *= t, this }, scaleBy: function(t) { return new o.Point(this.x * t.x, this.y * t.y) }, unscaleBy: function(t) { return new o.Point(this.x / t.x, this.y / t.y) }, round: function() { return this.clone()._round() }, _round: function() { return this.x = Math.round(this.x), this.y = Math.round(this.y), this }, floor: function() { return this.clone()._floor() }, _floor: function() { return this.x = Math.floor(this.x), this.y = Math.floor(this.y), this }, ceil: function() { return this.clone()._ceil() }, _ceil: function() { return this.x = Math.ceil(this.x), this.y = Math.ceil(this.y), this }, distanceTo: function(t) { t = o.point(t); var e = t.x - this.x, - i = t.y - this.y; return Math.sqrt(e * e + i * i) }, equals: function(t) { return t = o.point(t), t.x === this.x && t.y === this.y }, contains: function(t) { return t = o.point(t), Math.abs(t.x) <= Math.abs(this.x) && Math.abs(t.y) <= Math.abs(this.y) }, toString: function() { return "Point(" + o.Util.formatNum(this.x) + ", " + o.Util.formatNum(this.y) + ")" } }, o.point = function(t, e, n) { return t instanceof o.Point ? t : o.Util.isArray(t) ? new o.Point(t[0], t[1]) : t === i || null === t ? t : new o.Point(t, e, n) }, o.Bounds = function(t, e) { if (t) - for (var i = e ? [t, e] : t, n = 0, o = i.length; o > n; n++) this.extend(i[n]) }, o.Bounds.prototype = { extend: function(t) { return t = o.point(t), this.min || this.max ? (this.min.x = Math.min(t.x, this.min.x), this.max.x = Math.max(t.x, this.max.x), this.min.y = Math.min(t.y, this.min.y), this.max.y = Math.max(t.y, this.max.y)) : (this.min = t.clone(), this.max = t.clone()), this }, getCenter: function(t) { return new o.Point((this.min.x + this.max.x) / 2, (this.min.y + this.max.y) / 2, t) }, getBottomLeft: function() { return new o.Point(this.min.x, this.max.y) }, getTopRight: function() { return new o.Point(this.max.x, this.min.y) }, getSize: function() { return this.max.subtract(this.min) }, contains: function(t) { var e, i; return t = "number" == typeof t[0] || t instanceof o.Point ? o.point(t) : o.bounds(t), t instanceof o.Bounds ? (e = t.min, i = t.max) : e = i = t, e.x >= this.min.x && i.x <= this.max.x && e.y >= this.min.y && i.y <= this.max.y }, intersects: function(t) { t = o.bounds(t); var e = this.min, - i = this.max, - n = t.min, - s = t.max, - r = s.x >= e.x && n.x <= i.x, - a = s.y >= e.y && n.y <= i.y; return r && a }, overlaps: function(t) { t = o.bounds(t); var e = this.min, - i = this.max, - n = t.min, - s = t.max, - r = s.x > e.x && n.x < i.x, - a = s.y > e.y && n.y < i.y; return r && a }, isValid: function() { return !(!this.min || !this.max) } }, o.bounds = function(t, e) { return !t || t instanceof o.Bounds ? t : new o.Bounds(t, e) }, o.Transformation = function(t, e, i, n) { this._a = t, this._b = e, this._c = i, this._d = n }, o.Transformation.prototype = { transform: function(t, e) { return this._transform(t.clone(), e) }, _transform: function(t, e) { return e = e || 1, t.x = e * (this._a * t.x + this._b), t.y = e * (this._c * t.y + this._d), t }, untransform: function(t, e) { return e = e || 1, new o.Point((t.x / e - this._b) / this._a, (t.y / e - this._d) / this._c) } }, o.DomUtil = { get: function(t) { return "string" == typeof t ? e.getElementById(t) : t }, getStyle: function(t, i) { var n = t.style[i] || t.currentStyle && t.currentStyle[i]; if ((!n || "auto" === n) && e.defaultView) { var o = e.defaultView.getComputedStyle(t, null); - n = o ? o[i] : null } return "auto" === n ? null : n }, create: function(t, i, n) { var o = e.createElement(t); return o.className = i, n && n.appendChild(o), o }, remove: function(t) { var e = t.parentNode; - e && e.removeChild(t) }, empty: function(t) { for (; t.firstChild;) t.removeChild(t.firstChild) }, toFront: function(t) { t.parentNode.appendChild(t) }, toBack: function(t) { var e = t.parentNode; - e.insertBefore(t, e.firstChild) }, hasClass: function(t, e) { if (t.classList !== i) return t.classList.contains(e); var n = o.DomUtil.getClass(t); return n.length > 0 && new RegExp("(^|\\s)" + e + "(\\s|$)").test(n) }, addClass: function(t, e) { if (t.classList !== i) - for (var n = o.Util.splitWords(e), s = 0, r = n.length; r > s; s++) t.classList.add(n[s]); - else if (!o.DomUtil.hasClass(t, e)) { var a = o.DomUtil.getClass(t); - o.DomUtil.setClass(t, (a ? a + " " : "") + e) } }, removeClass: function(t, e) { t.classList !== i ? t.classList.remove(e) : o.DomUtil.setClass(t, o.Util.trim((" " + o.DomUtil.getClass(t) + " ").replace(" " + e + " ", " "))) }, setClass: function(t, e) { t.className.baseVal === i ? t.className = e : t.className.baseVal = e }, getClass: function(t) { return t.className.baseVal === i ? t.className : t.className.baseVal }, setOpacity: function(t, e) { "opacity" in t.style ? t.style.opacity = e : "filter" in t.style && o.DomUtil._setOpacityIE(t, e) }, _setOpacityIE: function(t, e) { var i = !1, - n = "DXImageTransform.Microsoft.Alpha"; try { i = t.filters.item(n) } catch (o) { if (1 === e) return } - e = Math.round(100 * e), i ? (i.Enabled = 100 !== e, i.Opacity = e) : t.style.filter += " progid:" + n + "(opacity=" + e + ")" }, testProp: function(t) { for (var i = e.documentElement.style, n = 0; n < t.length; n++) - if (t[n] in i) return t[n]; - return !1 }, setTransform: function(t, e, i) { var n = e || new o.Point(0, 0); - t.style[o.DomUtil.TRANSFORM] = (o.Browser.ie3d ? "translate(" + n.x + "px," + n.y + "px)" : "translate3d(" + n.x + "px," + n.y + "px,0)") + (i ? " scale(" + i + ")" : "") }, setPosition: function(t, e) { t._leaflet_pos = e, o.Browser.any3d ? o.DomUtil.setTransform(t, e) : (t.style.left = e.x + "px", t.style.top = e.y + "px") }, getPosition: function(t) { return t._leaflet_pos } }, - function() { o.DomUtil.TRANSFORM = o.DomUtil.testProp(["transform", "WebkitTransform", "OTransform", "MozTransform", "msTransform"]); var i = o.DomUtil.TRANSITION = o.DomUtil.testProp(["webkitTransition", "transition", "OTransition", "MozTransition", "msTransition"]); if (o.DomUtil.TRANSITION_END = "webkitTransition" === i || "OTransition" === i ? i + "End" : "transitionend", "onselectstart" in e) o.DomUtil.disableTextSelection = function() { o.DomEvent.on(t, "selectstart", o.DomEvent.preventDefault) }, o.DomUtil.enableTextSelection = function() { o.DomEvent.off(t, "selectstart", o.DomEvent.preventDefault) }; - else { var n = o.DomUtil.testProp(["userSelect", "WebkitUserSelect", "OUserSelect", "MozUserSelect", "msUserSelect"]); - o.DomUtil.disableTextSelection = function() { if (n) { var t = e.documentElement.style; - this._userSelect = t[n], t[n] = "none" } }, o.DomUtil.enableTextSelection = function() { n && (e.documentElement.style[n] = this._userSelect, delete this._userSelect) } } - o.DomUtil.disableImageDrag = function() { o.DomEvent.on(t, "dragstart", o.DomEvent.preventDefault) }, o.DomUtil.enableImageDrag = function() { o.DomEvent.off(t, "dragstart", o.DomEvent.preventDefault) }, o.DomUtil.preventOutline = function(e) { for (; - 1 === e.tabIndex;) e = e.parentNode; - e && e.style && (o.DomUtil.restoreOutline(), this._outlineElement = e, this._outlineStyle = e.style.outline, e.style.outline = "none", o.DomEvent.on(t, "keydown", o.DomUtil.restoreOutline, this)) }, o.DomUtil.restoreOutline = function() { this._outlineElement && (this._outlineElement.style.outline = this._outlineStyle, delete this._outlineElement, delete this._outlineStyle, o.DomEvent.off(t, "keydown", o.DomUtil.restoreOutline, this)) } }(), o.LatLng = function(t, e, n) { if (isNaN(t) || isNaN(e)) throw new Error("Invalid LatLng object: (" + t + ", " + e + ")"); - this.lat = +t, this.lng = +e, n !== i && (this.alt = +n) }, o.LatLng.prototype = { equals: function(t, e) { if (!t) return !1; - t = o.latLng(t); var n = Math.max(Math.abs(this.lat - t.lat), Math.abs(this.lng - t.lng)); return (e === i ? 1e-9 : e) >= n }, toString: function(t) { return "LatLng(" + o.Util.formatNum(this.lat, t) + ", " + o.Util.formatNum(this.lng, t) + ")" }, distanceTo: function(t) { return o.CRS.Earth.distance(this, o.latLng(t)) }, wrap: function() { return o.CRS.Earth.wrapLatLng(this) }, toBounds: function(t) { var e = 180 * t / 40075017, - i = e / Math.cos(Math.PI / 180 * this.lat); return o.latLngBounds([this.lat - e, this.lng - i], [this.lat + e, this.lng + i]) }, clone: function() { return new o.LatLng(this.lat, this.lng, this.alt) } }, o.latLng = function(t, e, n) { return t instanceof o.LatLng ? t : o.Util.isArray(t) && "object" != typeof t[0] ? 3 === t.length ? new o.LatLng(t[0], t[1], t[2]) : 2 === t.length ? new o.LatLng(t[0], t[1]) : null : t === i || null === t ? t : "object" == typeof t && "lat" in t ? new o.LatLng(t.lat, "lng" in t ? t.lng : t.lon, t.alt) : e === i ? null : new o.LatLng(t, e, n) }, o.LatLngBounds = function(t, e) { if (t) - for (var i = e ? [t, e] : t, n = 0, o = i.length; o > n; n++) this.extend(i[n]) }, o.LatLngBounds.prototype = { extend: function(t) { var e, i, n = this._southWest, - s = this._northEast; if (t instanceof o.LatLng) e = t, i = t; - else { if (!(t instanceof o.LatLngBounds)) return t ? this.extend(o.latLng(t) || o.latLngBounds(t)) : this; if (e = t._southWest, i = t._northEast, !e || !i) return this } return n || s ? (n.lat = Math.min(e.lat, n.lat), n.lng = Math.min(e.lng, n.lng), s.lat = Math.max(i.lat, s.lat), s.lng = Math.max(i.lng, s.lng)) : (this._southWest = new o.LatLng(e.lat, e.lng), this._northEast = new o.LatLng(i.lat, i.lng)), this }, pad: function(t) { var e = this._southWest, - i = this._northEast, - n = Math.abs(e.lat - i.lat) * t, - s = Math.abs(e.lng - i.lng) * t; return new o.LatLngBounds(new o.LatLng(e.lat - n, e.lng - s), new o.LatLng(i.lat + n, i.lng + s)) }, getCenter: function() { return new o.LatLng((this._southWest.lat + this._northEast.lat) / 2, (this._southWest.lng + this._northEast.lng) / 2) }, getSouthWest: function() { return this._southWest }, getNorthEast: function() { return this._northEast }, getNorthWest: function() { return new o.LatLng(this.getNorth(), this.getWest()) }, getSouthEast: function() { return new o.LatLng(this.getSouth(), this.getEast()) }, getWest: function() { return this._southWest.lng }, getSouth: function() { return this._southWest.lat }, getEast: function() { return this._northEast.lng }, getNorth: function() { return this._northEast.lat }, contains: function(t) { t = "number" == typeof t[0] || t instanceof o.LatLng ? o.latLng(t) : o.latLngBounds(t); var e, i, n = this._southWest, - s = this._northEast; return t instanceof o.LatLngBounds ? (e = t.getSouthWest(), i = t.getNorthEast()) : e = i = t, e.lat >= n.lat && i.lat <= s.lat && e.lng >= n.lng && i.lng <= s.lng }, intersects: function(t) { t = o.latLngBounds(t); var e = this._southWest, - i = this._northEast, - n = t.getSouthWest(), - s = t.getNorthEast(), - r = s.lat >= e.lat && n.lat <= i.lat, - a = s.lng >= e.lng && n.lng <= i.lng; return r && a }, overlaps: function(t) { t = o.latLngBounds(t); var e = this._southWest, - i = this._northEast, - n = t.getSouthWest(), - s = t.getNorthEast(), - r = s.lat > e.lat && n.lat < i.lat, - a = s.lng > e.lng && n.lng < i.lng; return r && a }, toBBoxString: function() { return [this.getWest(), this.getSouth(), this.getEast(), this.getNorth()].join(",") }, equals: function(t) { return t ? (t = o.latLngBounds(t), this._southWest.equals(t.getSouthWest()) && this._northEast.equals(t.getNorthEast())) : !1 }, isValid: function() { return !(!this._southWest || !this._northEast) } }, o.latLngBounds = function(t, e) { return !t || t instanceof o.LatLngBounds ? t : new o.LatLngBounds(t, e) }, o.Projection = {}, o.Projection.LonLat = { project: function(t) { return new o.Point(t.lng, t.lat) }, unproject: function(t) { return new o.LatLng(t.y, t.x) }, bounds: o.bounds([-180, -90], [180, 90]) }, o.Projection.SphericalMercator = { R: 6378137, MAX_LATITUDE: 85.0511287798, project: function(t) { var e = Math.PI / 180, - i = this.MAX_LATITUDE, - n = Math.max(Math.min(i, t.lat), -i), - s = Math.sin(n * e); return new o.Point(this.R * t.lng * e, this.R * Math.log((1 + s) / (1 - s)) / 2) }, unproject: function(t) { var e = 180 / Math.PI; return new o.LatLng((2 * Math.atan(Math.exp(t.y / this.R)) - Math.PI / 2) * e, t.x * e / this.R) }, bounds: function() { var t = 6378137 * Math.PI; return o.bounds([-t, -t], [t, t]) }() }, o.CRS = { latLngToPoint: function(t, e) { var i = this.projection.project(t), - n = this.scale(e); return this.transformation._transform(i, n) }, pointToLatLng: function(t, e) { var i = this.scale(e), - n = this.transformation.untransform(t, i); return this.projection.unproject(n) }, project: function(t) { return this.projection.project(t) }, unproject: function(t) { return this.projection.unproject(t) }, scale: function(t) { return 256 * Math.pow(2, t) }, zoom: function(t) { return Math.log(t / 256) / Math.LN2 }, getProjectedBounds: function(t) { if (this.infinite) return null; var e = this.projection.bounds, - i = this.scale(t), - n = this.transformation.transform(e.min, i), - s = this.transformation.transform(e.max, i); return o.bounds(n, s) }, wrapLatLng: function(t) { var e = this.wrapLng ? o.Util.wrapNum(t.lng, this.wrapLng, !0) : t.lng, - i = this.wrapLat ? o.Util.wrapNum(t.lat, this.wrapLat, !0) : t.lat, - n = t.alt; return o.latLng(i, e, n) } }, o.CRS.Simple = o.extend({}, o.CRS, { projection: o.Projection.LonLat, transformation: new o.Transformation(1, 0, -1, 0), scale: function(t) { return Math.pow(2, t) }, zoom: function(t) { return Math.log(t) / Math.LN2 }, distance: function(t, e) { var i = e.lng - t.lng, - n = e.lat - t.lat; return Math.sqrt(i * i + n * n) }, infinite: !0 }), o.CRS.Earth = o.extend({}, o.CRS, { wrapLng: [-180, 180], R: 6378137, distance: function(t, e) { var i = Math.PI / 180, - n = t.lat * i, - o = e.lat * i, - s = Math.sin(n) * Math.sin(o) + Math.cos(n) * Math.cos(o) * Math.cos((e.lng - t.lng) * i); return this.R * Math.acos(Math.min(s, 1)) } }), o.CRS.EPSG3857 = o.extend({}, o.CRS.Earth, { code: "EPSG:3857", projection: o.Projection.SphericalMercator, transformation: function() { var t = .5 / (Math.PI * o.Projection.SphericalMercator.R); return new o.Transformation(t, .5, -t, .5) }() }), o.CRS.EPSG900913 = o.extend({}, o.CRS.EPSG3857, { code: "EPSG:900913" }), o.CRS.EPSG4326 = o.extend({}, o.CRS.Earth, { code: "EPSG:4326", projection: o.Projection.LonLat, transformation: new o.Transformation(1 / 180, 1, -1 / 180, .5) }), o.Map = o.Evented.extend({ - options: { crs: o.CRS.EPSG3857, fadeAnimation: !0, trackResize: !0, markerZoomAnimation: !0, maxBoundsViscosity: 0, transform3DLimit: 8388608 }, - initialize: function(t, e) { e = o.setOptions(this, e), this._initContainer(t), this._initLayout(), this._onResize = o.bind(this._onResize, this), this._initEvents(), e.maxBounds && this.setMaxBounds(e.maxBounds), e.zoom !== i && (this._zoom = this._limitZoom(e.zoom)), e.center && e.zoom !== i && this.setView(o.latLng(e.center), e.zoom, { reset: !0 }), this._handlers = [], this._layers = {}, this._zoomBoundLayers = {}, this._sizeChanged = !0, this.callInitHooks(), this._addLayers(this.options.layers) }, - setView: function(t, e) { return e = e === i ? this.getZoom() : e, this._resetView(o.latLng(t), e), this }, - setZoom: function(t, e) { return this._loaded ? this.setView(this.getCenter(), t, { zoom: e }) : (this._zoom = t, this) }, - zoomIn: function(t, e) { return this.setZoom(this._zoom + (t || 1), e) }, - zoomOut: function(t, e) { return this.setZoom(this._zoom - (t || 1), e) }, - setZoomAround: function(t, e, i) { var n = this.getZoomScale(e), - s = this.getSize().divideBy(2), - r = t instanceof o.Point ? t : this.latLngToContainerPoint(t), - a = r.subtract(s).multiplyBy(1 - 1 / n), - h = this.containerPointToLatLng(s.add(a)); return this.setView(h, e, { zoom: i }) }, - _getBoundsCenterZoom: function(t, e) { e = e || {}, t = t.getBounds ? t.getBounds() : o.latLngBounds(t); var i = o.point(e.paddingTopLeft || e.padding || [0, 0]), - n = o.point(e.paddingBottomRight || e.padding || [0, 0]), - s = this.getBoundsZoom(t, !1, i.add(n)); - s = e.maxZoom ? Math.min(e.maxZoom, s) : s; var r = n.subtract(i).divideBy(2), - a = this.project(t.getSouthWest(), s), - h = this.project(t.getNorthEast(), s), - l = this.unproject(a.add(h).divideBy(2).add(r), s); return { center: l, zoom: s } }, - fitBounds: function(t, e) { var i = this._getBoundsCenterZoom(t, e); return this.setView(i.center, i.zoom, e) }, - fitWorld: function(t) { return this.fitBounds([ - [-90, -180], - [90, 180] - ], t) }, - panTo: function(t, e) { return this.setView(t, this._zoom, { pan: e }) }, - panBy: function(t) { return this.fire("movestart"), this._rawPanBy(o.point(t)), this.fire("move"), this.fire("moveend") }, - setMaxBounds: function(t) { return (t = o.latLngBounds(t)) ? (this.options.maxBounds && this.off("moveend", this._panInsideMaxBounds), this.options.maxBounds = t, this._loaded && this._panInsideMaxBounds(), this.on("moveend", this._panInsideMaxBounds)) : this.off("moveend", this._panInsideMaxBounds) }, - setMinZoom: function(t) { return this.options.minZoom = t, this._loaded && this.getZoom() < this.options.minZoom ? this.setZoom(t) : this }, - setMaxZoom: function(t) { return this.options.maxZoom = t, this._loaded && this.getZoom() > this.options.maxZoom ? this.setZoom(t) : this }, - panInsideBounds: function(t, e) { this._enforcingBounds = !0; var i = this.getCenter(), - n = this._limitCenter(i, this._zoom, o.latLngBounds(t)); return i.equals(n) ? this : (this.panTo(n, e), this._enforcingBounds = !1, this) }, - invalidateSize: function(t) { if (!this._loaded) return this; - t = o.extend({ animate: !1, pan: !0 }, t === !0 ? { animate: !0 } : t); var e = this.getSize(); - this._sizeChanged = !0, this._lastCenter = null; var i = this.getSize(), - n = e.divideBy(2).round(), - s = i.divideBy(2).round(), - r = n.subtract(s); return r.x || r.y ? (t.animate && t.pan ? this.panBy(r) : (t.pan && this._rawPanBy(r), this.fire("move"), t.debounceMoveend ? (clearTimeout(this._sizeTimer), this._sizeTimer = setTimeout(o.bind(this.fire, this, "moveend"), 200)) : this.fire("moveend")), this.fire("resize", { oldSize: e, newSize: i })) : this }, - stop: function() { return o.Util.cancelAnimFrame(this._flyToFrame), this._panAnim && this._panAnim.stop(), this }, - addHandler: function(t, e) { if (!e) return this; var i = this[t] = new e(this); return this._handlers.push(i), this.options[t] && i.enable(), this }, - remove: function() { this._initEvents(!0); try { delete this._container._leaflet } catch (t) { this._container._leaflet = i } - o.DomUtil.remove(this._mapPane), this._clearControlPos && this._clearControlPos(), this._clearHandlers(), this._loaded && this.fire("unload"); for (var e in this._layers) this._layers[e].remove(); return this }, - createPane: function(t, e) { var i = "leaflet-pane" + (t ? " leaflet-" + t.replace("Pane", "") + "-pane" : ""), - n = o.DomUtil.create("div", i, e || this._mapPane); return t && (this._panes[t] = n), n }, - getCenter: function() { return this._checkIfLoaded(), this._lastCenter && !this._moved() ? this._lastCenter : this.layerPointToLatLng(this._getCenterLayerPoint()) }, - getZoom: function() { return this._zoom }, - getBounds: function() { var t = this.getPixelBounds(), - e = this.unproject(t.getBottomLeft()), - i = this.unproject(t.getTopRight()); return new o.LatLngBounds(e, i) }, - getMinZoom: function() { return this.options.minZoom === i ? this._layersMinZoom || 0 : this.options.minZoom }, - getMaxZoom: function() { return this.options.maxZoom === i ? this._layersMaxZoom === i ? 1 / 0 : this._layersMaxZoom : this.options.maxZoom }, - getBoundsZoom: function(t, e, i) { t = o.latLngBounds(t); var n, s = this.getMinZoom() - (e ? 1 : 0), - r = this.getMaxZoom(), - a = this.getSize(), - h = t.getNorthWest(), - l = t.getSouthEast(), - u = !0; - i = o.point(i || [0, 0]); - do s++, n = this.project(l, s).subtract(this.project(h, s)).add(i).floor(), u = e ? n.x < a.x || n.y < a.y : a.contains(n); while (u && r >= s); return u && e ? null : e ? s : s - 1 }, - getSize: function() { return (!this._size || this._sizeChanged) && (this._size = new o.Point(this._container.clientWidth, this._container.clientHeight), this._sizeChanged = !1), this._size.clone() }, - getPixelBounds: function(t, e) { var i = this._getTopLeftPoint(t, e); return new o.Bounds(i, i.add(this.getSize())) }, - getPixelOrigin: function() { return this._checkIfLoaded(), this._pixelOrigin }, - getPixelWorldBounds: function(t) { return this.options.crs.getProjectedBounds(t === i ? this.getZoom() : t) }, - getPane: function(t) { return "string" == typeof t ? this._panes[t] : t }, - getPanes: function() { return this._panes }, - getContainer: function() { return this._container }, - getZoomScale: function(t, e) { var n = this.options.crs; return e = e === i ? this._zoom : e, n.scale(t) / n.scale(e) }, - getScaleZoom: function(t, e) { var n = this.options.crs; return e = e === i ? this._zoom : e, n.zoom(t * n.scale(e)) }, - project: function(t, e) { return e = e === i ? this._zoom : e, this.options.crs.latLngToPoint(o.latLng(t), e) }, - unproject: function(t, e) { return e = e === i ? this._zoom : e, this.options.crs.pointToLatLng(o.point(t), e) }, - layerPointToLatLng: function(t) { var e = o.point(t).add(this.getPixelOrigin()); return this.unproject(e) }, - latLngToLayerPoint: function(t) { var e = this.project(o.latLng(t))._round(); return e._subtract(this.getPixelOrigin()) }, - wrapLatLng: function(t) { return this.options.crs.wrapLatLng(o.latLng(t)) }, - distance: function(t, e) { return this.options.crs.distance(o.latLng(t), o.latLng(e)) }, - containerPointToLayerPoint: function(t) { return o.point(t).subtract(this._getMapPanePos()) }, - layerPointToContainerPoint: function(t) { return o.point(t).add(this._getMapPanePos()) }, - containerPointToLatLng: function(t) { var e = this.containerPointToLayerPoint(o.point(t)); return this.layerPointToLatLng(e) }, - latLngToContainerPoint: function(t) { return this.layerPointToContainerPoint(this.latLngToLayerPoint(o.latLng(t))) }, - mouseEventToContainerPoint: function(t) { return o.DomEvent.getMousePosition(t, this._container) }, - mouseEventToLayerPoint: function(t) { return this.containerPointToLayerPoint(this.mouseEventToContainerPoint(t)) }, - mouseEventToLatLng: function(t) { return this.layerPointToLatLng(this.mouseEventToLayerPoint(t)) }, - _initContainer: function(t) { var e = this._container = o.DomUtil.get(t); if (!e) throw new Error("Map container not found."); if (e._leaflet) throw new Error("Map container is already initialized."); - o.DomEvent.addListener(e, "scroll", this._onScroll, this), e._leaflet = !0 }, - _initLayout: function() { var t = this._container; - this._fadeAnimated = this.options.fadeAnimation && o.Browser.any3d, o.DomUtil.addClass(t, "leaflet-container" + (o.Browser.touch ? " leaflet-touch" : "") + (o.Browser.retina ? " leaflet-retina" : "") + (o.Browser.ielt9 ? " leaflet-oldie" : "") + (o.Browser.safari ? " leaflet-safari" : "") + (this._fadeAnimated ? " leaflet-fade-anim" : "")); var e = o.DomUtil.getStyle(t, "position"); "absolute" !== e && "relative" !== e && "fixed" !== e && (t.style.position = "relative"), this._initPanes(), this._initControlPos && this._initControlPos() }, - _initPanes: function() { var t = this._panes = {}; - this._paneRenderers = {}, this._mapPane = this.createPane("mapPane", this._container), o.DomUtil.setPosition(this._mapPane, new o.Point(0, 0)), this.createPane("tilePane"), this.createPane("shadowPane"), this.createPane("overlayPane"), this.createPane("markerPane"), this.createPane("popupPane"), this.options.markerZoomAnimation || (o.DomUtil.addClass(t.markerPane, "leaflet-zoom-hide"), o.DomUtil.addClass(t.shadowPane, "leaflet-zoom-hide")) }, - _resetView: function(t, e) { o.DomUtil.setPosition(this._mapPane, new o.Point(0, 0)); var i = !this._loaded; - this._loaded = !0, e = this._limitZoom(e); var n = this._zoom !== e; - this._moveStart(n)._move(t, e)._moveEnd(n), this.fire("viewreset"), i && this.fire("load") }, - _moveStart: function(t) { return t && this.fire("zoomstart"), this.fire("movestart") }, - _move: function(t, e, n) { e === i && (e = this._zoom); var o = this._zoom !== e; return this._zoom = e, this._lastCenter = t, this._pixelOrigin = this._getNewPixelOrigin(t), o && this.fire("zoom", n), this.fire("move", n) }, - _moveEnd: function(t) { return t && this.fire("zoomend"), this.fire("moveend") }, - _rawPanBy: function(t) { o.DomUtil.setPosition(this._mapPane, this._getMapPanePos().subtract(t)) }, - _getZoomSpan: function() { return this.getMaxZoom() - this.getMinZoom() }, - _panInsideMaxBounds: function() { this._enforcingBounds || this.panInsideBounds(this.options.maxBounds) }, - _checkIfLoaded: function() { if (!this._loaded) throw new Error("Set map center and zoom first.") }, - _initEvents: function(e) { if (o.DomEvent) { this._targets = {}, this._targets[o.stamp(this._container)] = this; var i = e ? "off" : "on"; - o.DomEvent[i](this._container, "click dblclick mousedown mouseup mouseover mouseout mousemove contextmenu keypress", this._handleDOMEvent, this), this.options.trackResize && o.DomEvent[i](t, "resize", this._onResize, this), o.Browser.any3d && this.options.transform3DLimit && this[i]("moveend", this._onMoveEnd) } }, - _onResize: function() { o.Util.cancelAnimFrame(this._resizeRequest), this._resizeRequest = o.Util.requestAnimFrame(function() { this.invalidateSize({ debounceMoveend: !0 }) }, this) }, - _onScroll: function() { this._container.scrollTop = 0, this._container.scrollLeft = 0 }, - _onMoveEnd: function() { var t = this._getMapPanePos(); - Math.max(Math.abs(t.x), Math.abs(t.y)) >= this.options.transform3DLimit && this._resetView(this.getCenter(), this.getZoom()) }, - _findEventTargets: function(t, e) { for (var i, n = [], s = "mouseout" === e || "mouseover" === e, r = t.target || t.srcElement; r;) { if (i = this._targets[o.stamp(r)], i && i.listens(e, !0)) { if (s && !o.DomEvent._isExternalTarget(r, t)) break; if (n.push(i), s) break } if (r === this._container) break; - r = r.parentNode } return n.length || s || !o.DomEvent._isExternalTarget(r, t) || (n = [this]), n }, - _handleDOMEvent: function(t) { if (this._loaded && !o.DomEvent._skipped(t)) { var e = "keypress" === t.type && 13 === t.keyCode ? "click" : t.type; if ("click" === t.type) { var i = o.Util.extend({}, t); - i.type = "preclick", this._handleDOMEvent(i) } "mousedown" === e && o.DomUtil.preventOutline(t.target || t.srcElement), this._fireDOMEvent(t, e) } }, - _fireDOMEvent: function(t, e, i) { if (!t._stopped && (i = (i || []).concat(this._findEventTargets(t, e)), i.length)) { var n = i[0]; if ("contextmenu" === e && n.listens(e, !0) && o.DomEvent.preventDefault(t), "click" !== t.type && "preclick" !== t.type || t._simulated || !this._draggableMoved(n)) { var s = { originalEvent: t }; if ("keypress" !== t.type) { var r = n instanceof o.Marker; - s.containerPoint = r ? this.latLngToContainerPoint(n.getLatLng()) : this.mouseEventToContainerPoint(t), s.layerPoint = this.containerPointToLayerPoint(s.containerPoint), s.latlng = r ? n.getLatLng() : this.layerPointToLatLng(s.layerPoint) } for (var a = 0; a < i.length; a++) - if (i[a].fire(e, s, !0), s.originalEvent._stopped || i[a].options.nonBubblingEvents && -1 !== o.Util.indexOf(i[a].options.nonBubblingEvents, e)) return } } }, - _draggableMoved: function(t) { return t = t.options.draggable ? t : this, t.dragging && t.dragging.moved() || this.boxZoom && this.boxZoom.moved() }, - _clearHandlers: function() { for (var t = 0, e = this._handlers.length; e > t; t++) this._handlers[t].disable() }, - whenReady: function(t, e) { return this._loaded ? t.call(e || this, { target: this }) : this.on("load", t, e), this }, - _getMapPanePos: function() { return o.DomUtil.getPosition(this._mapPane) || new o.Point(0, 0) }, - _moved: function() { var t = this._getMapPanePos(); return t && !t.equals([0, 0]) }, - _getTopLeftPoint: function(t, e) { var n = t && e !== i ? this._getNewPixelOrigin(t, e) : this.getPixelOrigin(); return n.subtract(this._getMapPanePos()) }, - _getNewPixelOrigin: function(t, e) { var i = this.getSize()._divideBy(2); return this.project(t, e)._subtract(i)._add(this._getMapPanePos())._round() }, - _latLngToNewLayerPoint: function(t, e, i) { - var n = this._getNewPixelOrigin(i, e); - return this.project(t, e)._subtract(n) - }, - _getCenterLayerPoint: function() { return this.containerPointToLayerPoint(this.getSize()._divideBy(2)) }, - _getCenterOffset: function(t) { return this.latLngToLayerPoint(t).subtract(this._getCenterLayerPoint()) }, - _limitCenter: function(t, e, i) { if (!i) return t; var n = this.project(t, e), - s = this.getSize().divideBy(2), - r = new o.Bounds(n.subtract(s), n.add(s)), - a = this._getBoundsOffset(r, i, e); return this.unproject(n.add(a), e) }, - _limitOffset: function(t, e) { if (!e) return t; var i = this.getPixelBounds(), - n = new o.Bounds(i.min.add(t), i.max.add(t)); return t.add(this._getBoundsOffset(n, e)) }, - _getBoundsOffset: function(t, e, i) { var n = this.project(e.getNorthWest(), i).subtract(t.min), - s = this.project(e.getSouthEast(), i).subtract(t.max), - r = this._rebound(n.x, -s.x), - a = this._rebound(n.y, -s.y); return new o.Point(r, a) }, - _rebound: function(t, e) { return t + e > 0 ? Math.round(t - e) / 2 : Math.max(0, Math.ceil(t)) - Math.max(0, Math.floor(e)) }, - _limitZoom: function(t) { var e = this.getMinZoom(), - i = this.getMaxZoom(); return o.Browser.any3d || (t = Math.round(t)), Math.max(e, Math.min(i, t)) } - }), o.map = function(t, e) { return new o.Map(t, e) }, o.Layer = o.Evented.extend({ options: { pane: "overlayPane", nonBubblingEvents: [] }, addTo: function(t) { return t.addLayer(this), this }, remove: function() { return this.removeFrom(this._map || this._mapToAdd) }, removeFrom: function(t) { return t && t.removeLayer(this), this }, getPane: function(t) { return this._map.getPane(t ? this.options[t] || t : this.options.pane) }, addInteractiveTarget: function(t) { return this._map._targets[o.stamp(t)] = this, this }, removeInteractiveTarget: function(t) { return delete this._map._targets[o.stamp(t)], this }, _layerAdd: function(t) { var e = t.target; - e.hasLayer(this) && (this._map = e, this._zoomAnimated = e._zoomAnimated, this.getEvents && e.on(this.getEvents(), this), this.onAdd(e), this.getAttribution && this._map.attributionControl && this._map.attributionControl.addAttribution(this.getAttribution()), this.fire("add"), e.fire("layeradd", { layer: this })) } }), o.Map.include({ addLayer: function(t) { var e = o.stamp(t); return this._layers[e] ? t : (this._layers[e] = t, t._mapToAdd = this, t.beforeAdd && t.beforeAdd(this), this.whenReady(t._layerAdd, t), this) }, removeLayer: function(t) { var e = o.stamp(t); return this._layers[e] ? (this._loaded && t.onRemove(this), t.getAttribution && this.attributionControl && this.attributionControl.removeAttribution(t.getAttribution()), t.getEvents && this.off(t.getEvents(), t), delete this._layers[e], this._loaded && (this.fire("layerremove", { layer: t }), t.fire("remove")), t._map = t._mapToAdd = null, this) : this }, hasLayer: function(t) { return !!t && o.stamp(t) in this._layers }, eachLayer: function(t, e) { for (var i in this._layers) t.call(e, this._layers[i]); return this }, _addLayers: function(t) { t = t ? o.Util.isArray(t) ? t : [t] : []; for (var e = 0, i = t.length; i > e; e++) this.addLayer(t[e]) }, _addZoomLimit: function(t) { - (isNaN(t.options.maxZoom) || !isNaN(t.options.minZoom)) && (this._zoomBoundLayers[o.stamp(t)] = t, this._updateZoomLevels()) }, _removeZoomLimit: function(t) { var e = o.stamp(t); - this._zoomBoundLayers[e] && (delete this._zoomBoundLayers[e], this._updateZoomLevels()) }, _updateZoomLevels: function() { var t = 1 / 0, - e = -(1 / 0), - n = this._getZoomSpan(); for (var o in this._zoomBoundLayers) { var s = this._zoomBoundLayers[o].options; - t = s.minZoom === i ? t : Math.min(t, s.minZoom), e = s.maxZoom === i ? e : Math.max(e, s.maxZoom) } - this._layersMaxZoom = e === -(1 / 0) ? i : e, this._layersMinZoom = t === 1 / 0 ? i : t, n !== this._getZoomSpan() && this.fire("zoomlevelschange") } }), o.Projection.Mercator = { R: 6378137, R_MINOR: 6356752.314245179, bounds: o.bounds([-20037508.34279, -15496570.73972], [20037508.34279, 18764656.23138]), project: function(t) { var e = Math.PI / 180, - i = this.R, - n = t.lat * e, - s = this.R_MINOR / i, - r = Math.sqrt(1 - s * s), - a = r * Math.sin(n), - h = Math.tan(Math.PI / 4 - n / 2) / Math.pow((1 - a) / (1 + a), r / 2); return n = -i * Math.log(Math.max(h, 1e-10)), new o.Point(t.lng * e * i, n) }, unproject: function(t) { for (var e, i = 180 / Math.PI, n = this.R, s = this.R_MINOR / n, r = Math.sqrt(1 - s * s), a = Math.exp(-t.y / n), h = Math.PI / 2 - 2 * Math.atan(a), l = 0, u = .1; 15 > l && Math.abs(u) > 1e-7; l++) e = r * Math.sin(h), e = Math.pow((1 - e) / (1 + e), r / 2), u = Math.PI / 2 - 2 * Math.atan(a * e) - h, h += u; return new o.LatLng(h * i, t.x * i / n) } }, o.CRS.EPSG3395 = o.extend({}, o.CRS.Earth, { code: "EPSG:3395", projection: o.Projection.Mercator, transformation: function() { var t = .5 / (Math.PI * o.Projection.Mercator.R); return new o.Transformation(t, .5, -t, .5) }() }), o.GridLayer = o.Layer.extend({ options: { pane: "tilePane", tileSize: 256, opacity: 1, zIndex: 1, updateWhenIdle: o.Browser.mobile, updateInterval: 200, attribution: null, bounds: null, minZoom: 0 }, initialize: function(t) { t = o.setOptions(this, t) }, onAdd: function() { this._initContainer(), this._levels = {}, this._tiles = {}, this._resetView(), this._update() }, beforeAdd: function(t) { t._addZoomLimit(this) }, onRemove: function(t) { o.DomUtil.remove(this._container), t._removeZoomLimit(this), this._container = null, this._tileZoom = null }, bringToFront: function() { return this._map && (o.DomUtil.toFront(this._container), this._setAutoZIndex(Math.max)), this }, bringToBack: function() { return this._map && (o.DomUtil.toBack(this._container), this._setAutoZIndex(Math.min)), this }, getAttribution: function() { return this.options.attribution }, getContainer: function() { return this._container }, setOpacity: function(t) { return this.options.opacity = t, this._updateOpacity(), this }, setZIndex: function(t) { return this.options.zIndex = t, this._updateZIndex(), this }, isLoading: function() { return this._loading }, redraw: function() { return this._map && (this._removeAllTiles(), this._update()), this }, getEvents: function() { var t = { viewreset: this._resetAll, zoom: this._resetView, moveend: this._onMoveEnd }; return this.options.updateWhenIdle || (this._onMove || (this._onMove = o.Util.throttle(this._onMoveEnd, this.options.updateInterval, this)), t.move = this._onMove), this._zoomAnimated && (t.zoomanim = this._animateZoom), t }, createTile: function() { return e.createElement("div") }, getTileSize: function() { var t = this.options.tileSize; return t instanceof o.Point ? t : new o.Point(t, t) }, _updateZIndex: function() { this._container && this.options.zIndex !== i && null !== this.options.zIndex && (this._container.style.zIndex = this.options.zIndex) }, _setAutoZIndex: function(t) { for (var e, i = this.getPane().children, n = -t(-(1 / 0), 1 / 0), o = 0, s = i.length; s > o; o++) e = i[o].style.zIndex, i[o] !== this._container && e && (n = t(n, +e)); - isFinite(n) && (this.options.zIndex = n + t(-1, 1), this._updateZIndex()) }, _updateOpacity: function() { if (this._map && !o.Browser.ielt9 && this._map._fadeAnimated) { o.DomUtil.setOpacity(this._container, this.options.opacity); var t = +new Date, - e = !1, - i = !1; for (var n in this._tiles) { var s = this._tiles[n]; if (s.current && s.loaded) { var r = Math.min(1, (t - s.loaded) / 200); - o.DomUtil.setOpacity(s.el, r), 1 > r ? e = !0 : (s.active && (i = !0), s.active = !0) } } - i && !this._noPrune && this._pruneTiles(), e && (o.Util.cancelAnimFrame(this._fadeFrame), this._fadeFrame = o.Util.requestAnimFrame(this._updateOpacity, this)) } }, _initContainer: function() { this._container || (this._container = o.DomUtil.create("div", "leaflet-layer"), this._updateZIndex(), this.options.opacity < 1 && this._updateOpacity(), this.getPane().appendChild(this._container)) }, _updateLevels: function() { var t = this._tileZoom, - e = this.options.maxZoom; for (var i in this._levels) this._levels[i].el.children.length || i === t ? this._levels[i].el.style.zIndex = e - Math.abs(t - i) : (o.DomUtil.remove(this._levels[i].el), delete this._levels[i]); var n = this._levels[t], - s = this._map; return n || (n = this._levels[t] = {}, n.el = o.DomUtil.create("div", "leaflet-tile-container leaflet-zoom-animated", this._container), n.el.style.zIndex = e, n.origin = s.project(s.unproject(s.getPixelOrigin()), t).round(), n.zoom = t, this._setZoomTransform(n, s.getCenter(), s.getZoom()), o.Util.falseFn(n.el.offsetWidth)), this._level = n, n }, _pruneTiles: function() { var t, e, i = this._map.getZoom(); if (i > this.options.maxZoom || i < this.options.minZoom) return this._removeAllTiles(); for (t in this._tiles) e = this._tiles[t], e.retain = e.current; for (t in this._tiles) - if (e = this._tiles[t], e.current && !e.active) { var n = e.coords; - this._retainParent(n.x, n.y, n.z, n.z - 5) || this._retainChildren(n.x, n.y, n.z, n.z + 2) } - for (t in this._tiles) this._tiles[t].retain || this._removeTile(t) }, _removeAllTiles: function() { for (var t in this._tiles) this._removeTile(t) }, _resetAll: function() { for (var t in this._levels) o.DomUtil.remove(this._levels[t].el), delete this._levels[t]; - this._removeAllTiles(), this._tileZoom = null, this._resetView() }, _retainParent: function(t, e, i, n) { var o = Math.floor(t / 2), - s = Math.floor(e / 2), - r = i - 1, - a = o + ":" + s + ":" + r, - h = this._tiles[a]; return h && h.active ? (h.retain = !0, !0) : (h && h.loaded && (h.retain = !0), r > n ? this._retainParent(o, s, r, n) : !1) }, _retainChildren: function(t, e, i, n) { for (var o = 2 * t; 2 * t + 2 > o; o++) - for (var s = 2 * e; 2 * e + 2 > s; s++) { var r = o + ":" + s + ":" + (i + 1), - a = this._tiles[r]; - a && a.active ? a.retain = !0 : (a && a.loaded && (a.retain = !0), n > i + 1 && this._retainChildren(o, s, i + 1, n)) } }, _resetView: function(t) { var e = t && (t.pinch || t.flyTo); - this._setView(this._map.getCenter(), this._map.getZoom(), e, e) }, _animateZoom: function(t) { this._setView(t.center, t.zoom, !0, t.noUpdate) }, _setView: function(t, e, n, o) { var s = Math.round(e); - (this.options.maxZoom !== i && s > this.options.maxZoom || this.options.minZoom !== i && s < this.options.minZoom) && (s = i); var r = s !== this._tileZoom; - (!o || r) && (this._tileZoom = s, this._abortLoading && this._abortLoading(), this._updateLevels(), this._resetGrid(), s !== i && this._update(t), n || this._pruneTiles(), this._noPrune = !!n), this._setZoomTransforms(t, e) }, _setZoomTransforms: function(t, e) { for (var i in this._levels) this._setZoomTransform(this._levels[i], t, e) }, _setZoomTransform: function(t, e, i) { var n = this._map.getZoomScale(i, t.zoom), - s = t.origin.multiplyBy(n).subtract(this._map._getNewPixelOrigin(e, i)).round(); - o.Browser.any3d ? o.DomUtil.setTransform(t.el, s, n) : o.DomUtil.setPosition(t.el, s) }, _resetGrid: function() { var t = this._map, - e = t.options.crs, - i = this._tileSize = this.getTileSize(), - n = this._tileZoom, - o = this._map.getPixelWorldBounds(this._tileZoom); - o && (this._globalTileRange = this._pxBoundsToTileRange(o)), this._wrapX = e.wrapLng && !this.options.noWrap && [Math.floor(t.project([0, e.wrapLng[0]], n).x / i.x), Math.ceil(t.project([0, e.wrapLng[1]], n).x / i.y)], this._wrapY = e.wrapLat && !this.options.noWrap && [Math.floor(t.project([e.wrapLat[0], 0], n).y / i.x), Math.ceil(t.project([e.wrapLat[1], 0], n).y / i.y)] }, _onMoveEnd: function() { this._map && !this._map._animatingZoom && this._resetView() }, _getTiledPixelBounds: function(t, e, i) { var n = this._map, - s = n.getZoomScale(e, i), - r = n.project(t, i).floor(), - a = n.getSize().divideBy(2 * s); return new o.Bounds(r.subtract(a), r.add(a)) }, _update: function(t) { var n = this._map; if (n) { var s = n.getZoom(); if (t === i && (t = n.getCenter()), this._tileZoom !== i) { var r = this._getTiledPixelBounds(t, s, this._tileZoom), - a = this._pxBoundsToTileRange(r), - h = a.getCenter(), - l = []; for (var u in this._tiles) this._tiles[u].current = !1; if (Math.abs(s - this._tileZoom) > 1) return void this._setView(t, s); for (var c = a.min.y; c <= a.max.y; c++) - for (var d = a.min.x; d <= a.max.x; d++) { var _ = new o.Point(d, c); if (_.z = this._tileZoom, this._isValidTile(_)) { var m = this._tiles[this._tileCoordsToKey(_)]; - m ? m.current = !0 : l.push(_) } } - if (l.sort(function(t, e) { return t.distanceTo(h) - e.distanceTo(h) }), 0 !== l.length) { this._loading || (this._loading = !0, this.fire("loading")); var p = e.createDocumentFragment(); for (d = 0; d < l.length; d++) this._addTile(l[d], p); - this._level.el.appendChild(p) } } } }, _isValidTile: function(t) { var e = this._map.options.crs; if (!e.infinite) { var i = this._globalTileRange; if (!e.wrapLng && (t.x < i.min.x || t.x > i.max.x) || !e.wrapLat && (t.y < i.min.y || t.y > i.max.y)) return !1 } if (!this.options.bounds) return !0; var n = this._tileCoordsToBounds(t); return o.latLngBounds(this.options.bounds).overlaps(n) }, _keyToBounds: function(t) { return this._tileCoordsToBounds(this._keyToTileCoords(t)) }, _tileCoordsToBounds: function(t) { var e = this._map, - i = this.getTileSize(), - n = t.scaleBy(i), - s = n.add(i), - r = e.wrapLatLng(e.unproject(n, t.z)), - a = e.wrapLatLng(e.unproject(s, t.z)); return new o.LatLngBounds(r, a) }, _tileCoordsToKey: function(t) { return t.x + ":" + t.y + ":" + t.z }, _keyToTileCoords: function(t) { var e = t.split(":"), - i = new o.Point(+e[0], +e[1]); return i.z = +e[2], i }, _removeTile: function(t) { var e = this._tiles[t]; - e && (o.DomUtil.remove(e.el), delete this._tiles[t], this.fire("tileunload", { tile: e.el, coords: this._keyToTileCoords(t) })) }, _initTile: function(t) { o.DomUtil.addClass(t, "leaflet-tile"); var e = this.getTileSize(); - t.style.width = e.x + "px", t.style.height = e.y + "px", t.onselectstart = o.Util.falseFn, t.onmousemove = o.Util.falseFn, o.Browser.ielt9 && this.options.opacity < 1 && o.DomUtil.setOpacity(t, this.options.opacity), o.Browser.android && !o.Browser.android23 && (t.style.WebkitBackfaceVisibility = "hidden") }, _addTile: function(t, e) { var i = this._getTilePos(t), - n = this._tileCoordsToKey(t), - s = this.createTile(this._wrapCoords(t), o.bind(this._tileReady, this, t)); - this._initTile(s), this.createTile.length < 2 && o.Util.requestAnimFrame(o.bind(this._tileReady, this, t, null, s)), o.DomUtil.setPosition(s, i), this._tiles[n] = { el: s, coords: t, current: !0 }, e.appendChild(s), this.fire("tileloadstart", { tile: s, coords: t }) }, _tileReady: function(t, e, i) { if (this._map) { e && this.fire("tileerror", { error: e, tile: i, coords: t }); var n = this._tileCoordsToKey(t); - i = this._tiles[n], i && (i.loaded = +new Date, this._map._fadeAnimated ? (o.DomUtil.setOpacity(i.el, 0), o.Util.cancelAnimFrame(this._fadeFrame), this._fadeFrame = o.Util.requestAnimFrame(this._updateOpacity, this)) : (i.active = !0, this._pruneTiles()), o.DomUtil.addClass(i.el, "leaflet-tile-loaded"), this.fire("tileload", { tile: i.el, coords: t }), this._noTilesToLoad() && (this._loading = !1, this.fire("load"))) } }, _getTilePos: function(t) { return t.scaleBy(this.getTileSize()).subtract(this._level.origin) }, _wrapCoords: function(t) { var e = new o.Point(this._wrapX ? o.Util.wrapNum(t.x, this._wrapX) : t.x, this._wrapY ? o.Util.wrapNum(t.y, this._wrapY) : t.y); return e.z = t.z, e }, _pxBoundsToTileRange: function(t) { var e = this.getTileSize(); return new o.Bounds(t.min.unscaleBy(e).floor(), t.max.unscaleBy(e).ceil().subtract([1, 1])) }, _noTilesToLoad: function() { for (var t in this._tiles) - if (!this._tiles[t].loaded) return !1; - return !0 } }), o.gridLayer = function(t) { return new o.GridLayer(t) }, o.TileLayer = o.GridLayer.extend({ options: { maxZoom: 18, subdomains: "abc", errorTileUrl: "", zoomOffset: 0, maxNativeZoom: null, tms: !1, zoomReverse: !1, detectRetina: !1, crossOrigin: !1 }, initialize: function(t, e) { this._url = t, e = o.setOptions(this, e), e.detectRetina && o.Browser.retina && e.maxZoom > 0 && (e.tileSize = Math.floor(e.tileSize / 2), e.zoomOffset++, e.minZoom = Math.max(0, e.minZoom), e.maxZoom--), "string" == typeof e.subdomains && (e.subdomains = e.subdomains.split("")), o.Browser.android || this.on("tileunload", this._onTileRemove) }, setUrl: function(t, e) { return this._url = t, e || this.redraw(), this }, createTile: function(t, i) { var n = e.createElement("img"); return o.DomEvent.on(n, "load", o.bind(this._tileOnLoad, this, i, n)), o.DomEvent.on(n, "error", o.bind(this._tileOnError, this, i, n)), this.options.crossOrigin && (n.crossOrigin = ""), n.alt = "", n.src = this.getTileUrl(t), n }, getTileUrl: function(t) { return o.Util.template(this._url, o.extend({ r: this.options.detectRetina && o.Browser.retina && this.options.maxZoom > 0 ? "@2x" : "", s: this._getSubdomain(t), x: t.x, y: this.options.tms ? this._globalTileRange.max.y - t.y : t.y, z: this._getZoomForUrl() }, this.options)) }, _tileOnLoad: function(t, e) { o.Browser.ielt9 ? setTimeout(o.bind(t, this, null, e), 0) : t(null, e) }, _tileOnError: function(t, e, i) { var n = this.options.errorTileUrl; - n && (e.src = n), t(i, e) }, getTileSize: function() { var t = this._map, - e = o.GridLayer.prototype.getTileSize.call(this), - i = this._tileZoom + this.options.zoomOffset, - n = this.options.maxNativeZoom; return null !== n && i > n ? e.divideBy(t.getZoomScale(n, i)).round() : e }, _onTileRemove: function(t) { t.tile.onload = null }, _getZoomForUrl: function() { var t = this.options, - e = this._tileZoom; return t.zoomReverse && (e = t.maxZoom - e), e += t.zoomOffset, null !== t.maxNativeZoom ? Math.min(e, t.maxNativeZoom) : e }, _getSubdomain: function(t) { var e = Math.abs(t.x + t.y) % this.options.subdomains.length; return this.options.subdomains[e] }, _abortLoading: function() { var t, e; for (t in this._tiles) this._tiles[t].coords.z !== this._tileZoom && (e = this._tiles[t].el, e.onload = o.Util.falseFn, e.onerror = o.Util.falseFn, e.complete || (e.src = o.Util.emptyImageUrl, o.DomUtil.remove(e))) } }), o.tileLayer = function(t, e) { return new o.TileLayer(t, e) }, o.TileLayer.WMS = o.TileLayer.extend({ defaultWmsParams: { service: "WMS", request: "GetMap", version: "1.1.1", layers: "", styles: "", format: "image/jpeg", transparent: !1 }, options: { crs: null, uppercase: !1 }, initialize: function(t, e) { this._url = t; var i = o.extend({}, this.defaultWmsParams); for (var n in e) n in this.options || (i[n] = e[n]); - e = o.setOptions(this, e), i.width = i.height = e.tileSize * (e.detectRetina && o.Browser.retina ? 2 : 1), this.wmsParams = i }, onAdd: function(t) { this._crs = this.options.crs || t.options.crs, this._wmsVersion = parseFloat(this.wmsParams.version); var e = this._wmsVersion >= 1.3 ? "crs" : "srs"; - this.wmsParams[e] = this._crs.code, o.TileLayer.prototype.onAdd.call(this, t) }, getTileUrl: function(t) { var e = this._tileCoordsToBounds(t), - i = this._crs.project(e.getNorthWest()), - n = this._crs.project(e.getSouthEast()), - s = (this._wmsVersion >= 1.3 && this._crs === o.CRS.EPSG4326 ? [n.y, i.x, i.y, n.x] : [i.x, n.y, n.x, i.y]).join(","), - r = o.TileLayer.prototype.getTileUrl.call(this, t); return r + o.Util.getParamString(this.wmsParams, r, this.options.uppercase) + (this.options.uppercase ? "&BBOX=" : "&bbox=") + s }, setParams: function(t, e) { return o.extend(this.wmsParams, t), e || this.redraw(), this } }), o.tileLayer.wms = function(t, e) { return new o.TileLayer.WMS(t, e) }, o.ImageOverlay = o.Layer.extend({ options: { opacity: 1, alt: "", interactive: !1 }, initialize: function(t, e, i) { this._url = t, this._bounds = o.latLngBounds(e), o.setOptions(this, i) }, onAdd: function() { this._image || (this._initImage(), this.options.opacity < 1 && this._updateOpacity()), this.options.interactive && (o.DomUtil.addClass(this._image, "leaflet-interactive"), this.addInteractiveTarget(this._image)), this.getPane().appendChild(this._image), this._reset() }, onRemove: function() { o.DomUtil.remove(this._image), this.options.interactive && this.removeInteractiveTarget(this._image) }, setOpacity: function(t) { return this.options.opacity = t, this._image && this._updateOpacity(), this }, setStyle: function(t) { return t.opacity && this.setOpacity(t.opacity), this }, bringToFront: function() { return this._map && o.DomUtil.toFront(this._image), this }, bringToBack: function() { return this._map && o.DomUtil.toBack(this._image), this }, setUrl: function(t) { return this._url = t, this._image && (this._image.src = t), this }, setBounds: function(t) { return this._bounds = t, this._map && this._reset(), this }, getAttribution: function() { return this.options.attribution }, getEvents: function() { var t = { zoom: this._reset, viewreset: this._reset }; return this._zoomAnimated && (t.zoomanim = this._animateZoom), t }, getBounds: function() { return this._bounds }, getElement: function() { return this._image }, _initImage: function() { var t = this._image = o.DomUtil.create("img", "leaflet-image-layer " + (this._zoomAnimated ? "leaflet-zoom-animated" : "")); - t.onselectstart = o.Util.falseFn, t.onmousemove = o.Util.falseFn, t.onload = o.bind(this.fire, this, "load"), this.options.crossOrigin && (t.crossOrigin = ""), t.src = this._url, t.alt = this.options.alt }, _animateZoom: function(t) { var e = this._map.getZoomScale(t.zoom), - i = this._map._latLngToNewLayerPoint(this._bounds.getNorthWest(), t.zoom, t.center); - o.DomUtil.setTransform(this._image, i, e) }, _reset: function() { var t = this._image, - e = new o.Bounds(this._map.latLngToLayerPoint(this._bounds.getNorthWest()), this._map.latLngToLayerPoint(this._bounds.getSouthEast())), - i = e.getSize(); - o.DomUtil.setPosition(t, e.min), t.style.width = i.x + "px", t.style.height = i.y + "px" }, _updateOpacity: function() { o.DomUtil.setOpacity(this._image, this.options.opacity) } }), o.imageOverlay = function(t, e, i) { return new o.ImageOverlay(t, e, i) }, o.Icon = o.Class.extend({ initialize: function(t) { o.setOptions(this, t) }, createIcon: function(t) { return this._createIcon("icon", t) }, createShadow: function(t) { return this._createIcon("shadow", t) }, _createIcon: function(t, e) { var i = this._getIconUrl(t); if (!i) { if ("icon" === t) throw new Error("iconUrl not set in Icon options (see the docs)."); return null } var n = this._createImg(i, e && "IMG" === e.tagName ? e : null); return this._setIconStyles(n, t), n }, _setIconStyles: function(t, e) { var i = this.options, - n = o.point(i[e + "Size"]), - s = o.point("shadow" === e && i.shadowAnchor || i.iconAnchor || n && n.divideBy(2, !0)); - t.className = "leaflet-marker-" + e + " " + (i.className || ""), s && (t.style.marginLeft = -s.x + "px", t.style.marginTop = -s.y + "px"), n && (t.style.width = n.x + "px", t.style.height = n.y + "px") }, _createImg: function(t, i) { return i = i || e.createElement("img"), i.src = t, i }, _getIconUrl: function(t) { return o.Browser.retina && this.options[t + "RetinaUrl"] || this.options[t + "Url"] } }), o.icon = function(t) { return new o.Icon(t) }, o.Icon.Default = o.Icon.extend({ options: { iconSize: [25, 41], iconAnchor: [12, 41], popupAnchor: [1, -34], shadowSize: [41, 41] }, _getIconUrl: function(t) { var e = t + "Url"; if (this.options[e]) return this.options[e]; var i = o.Icon.Default.imagePath; if (!i) throw new Error("Couldn't autodetect L.Icon.Default.imagePath, set it manually."); return i + "/marker-" + t + (o.Browser.retina && "icon" === t ? "-2x" : "") + ".png" } }), o.Icon.Default.imagePath = function() { var t, i, n, o, s = e.getElementsByTagName("script"), - r = /[\/^]leaflet[\-\._]?([\w\-\._]*)\.js\??/; for (t = 0, i = s.length; i > t; t++) - if (n = s[t].src || "", n.match(r)) return o = n.split(r)[0], (o ? o + "/" : "") + "images" }(), o.Marker = o.Layer.extend({ options: { pane: "markerPane", nonBubblingEvents: ["click", "dblclick", "mouseover", "mouseout", "contextmenu"], icon: new o.Icon.Default, interactive: !0, keyboard: !0, zIndexOffset: 0, opacity: 1, riseOffset: 250 }, initialize: function(t, e) { o.setOptions(this, e), this._latlng = o.latLng(t) }, onAdd: function(t) { this._zoomAnimated = this._zoomAnimated && t.options.markerZoomAnimation, this._initIcon(), this.update() }, onRemove: function() { this.dragging && this.dragging.enabled() && (this.options.draggable = !0, this.dragging.removeHooks()), this._removeIcon(), this._removeShadow() }, getEvents: function() { var t = { zoom: this.update, viewreset: this.update }; return this._zoomAnimated && (t.zoomanim = this._animateZoom), t }, getLatLng: function() { return this._latlng }, setLatLng: function(t) { var e = this._latlng; return this._latlng = o.latLng(t), this.update(), this.fire("move", { oldLatLng: e, latlng: this._latlng }) }, setZIndexOffset: function(t) { return this.options.zIndexOffset = t, this.update() }, setIcon: function(t) { return this.options.icon = t, this._map && (this._initIcon(), this.update()), this._popup && this.bindPopup(this._popup, this._popup.options), this }, getElement: function() { return this._icon }, update: function() { if (this._icon) { var t = this._map.latLngToLayerPoint(this._latlng).round(); - this._setPos(t) } return this }, _initIcon: function() { var t = this.options, - e = "leaflet-zoom-" + (this._zoomAnimated ? "animated" : "hide"), - i = t.icon.createIcon(this._icon), - n = !1; - i !== this._icon && (this._icon && this._removeIcon(), n = !0, t.title && (i.title = t.title), t.alt && (i.alt = t.alt)), o.DomUtil.addClass(i, e), t.keyboard && (i.tabIndex = "0"), this._icon = i, t.riseOnHover && this.on({ mouseover: this._bringToFront, mouseout: this._resetZIndex }); var s = t.icon.createShadow(this._shadow), - r = !1; - s !== this._shadow && (this._removeShadow(), r = !0), s && o.DomUtil.addClass(s, e), this._shadow = s, t.opacity < 1 && this._updateOpacity(), n && (this.getPane().appendChild(this._icon), this._initInteraction()), s && r && this.getPane("shadowPane").appendChild(this._shadow) }, _removeIcon: function() { this.options.riseOnHover && this.off({ mouseover: this._bringToFront, mouseout: this._resetZIndex }), o.DomUtil.remove(this._icon), this.removeInteractiveTarget(this._icon), this._icon = null }, _removeShadow: function() { this._shadow && o.DomUtil.remove(this._shadow), this._shadow = null }, _setPos: function(t) { o.DomUtil.setPosition(this._icon, t), this._shadow && o.DomUtil.setPosition(this._shadow, t), this._zIndex = t.y + this.options.zIndexOffset, this._resetZIndex() }, _updateZIndex: function(t) { this._icon.style.zIndex = this._zIndex + t }, _animateZoom: function(t) { var e = this._map._latLngToNewLayerPoint(this._latlng, t.zoom, t.center).round(); - this._setPos(e) }, _initInteraction: function() { if (this.options.interactive && (o.DomUtil.addClass(this._icon, "leaflet-interactive"), this.addInteractiveTarget(this._icon), o.Handler.MarkerDrag)) { var t = this.options.draggable; - this.dragging && (t = this.dragging.enabled(), this.dragging.disable()), this.dragging = new o.Handler.MarkerDrag(this), t && this.dragging.enable() } }, setOpacity: function(t) { return this.options.opacity = t, this._map && this._updateOpacity(), this }, _updateOpacity: function() { var t = this.options.opacity; - o.DomUtil.setOpacity(this._icon, t), this._shadow && o.DomUtil.setOpacity(this._shadow, t) }, _bringToFront: function() { this._updateZIndex(this.options.riseOffset) }, _resetZIndex: function() { this._updateZIndex(0) } }), o.marker = function(t, e) { return new o.Marker(t, e) }, o.DivIcon = o.Icon.extend({ options: { iconSize: [12, 12], className: "leaflet-div-icon", html: !1 }, createIcon: function(t) { var i = t && "DIV" === t.tagName ? t : e.createElement("div"), - n = this.options; return i.innerHTML = n.html !== !1 ? n.html : "", n.bgPos && (i.style.backgroundPosition = -n.bgPos.x + "px " + -n.bgPos.y + "px"), this._setIconStyles(i, "icon"), i }, createShadow: function() { return null } }), o.divIcon = function(t) { return new o.DivIcon(t) }, o.Map.mergeOptions({ closePopupOnClick: !0 }), o.Popup = o.Layer.extend({ options: { pane: "popupPane", minWidth: 50, maxWidth: 300, offset: [0, 7], autoPan: !0, autoPanPadding: [5, 5], closeButton: !0, autoClose: !0, zoomAnimation: !0 }, initialize: function(t, e) { o.setOptions(this, t), this._source = e }, onAdd: function(t) { this._zoomAnimated = this._zoomAnimated && this.options.zoomAnimation, this._container || this._initLayout(), t._fadeAnimated && o.DomUtil.setOpacity(this._container, 0), clearTimeout(this._removeTimeout), this.getPane().appendChild(this._container), this.update(), t._fadeAnimated && o.DomUtil.setOpacity(this._container, 1), t.fire("popupopen", { popup: this }), this._source && this._source.fire("popupopen", { popup: this }, !0) }, openOn: function(t) { return t.openPopup(this), this }, onRemove: function(t) { t._fadeAnimated ? (o.DomUtil.setOpacity(this._container, 0), this._removeTimeout = setTimeout(o.bind(o.DomUtil.remove, o.DomUtil, this._container), 200)) : o.DomUtil.remove(this._container), t.fire("popupclose", { popup: this }), this._source && this._source.fire("popupclose", { popup: this }, !0) }, getLatLng: function() { return this._latlng }, setLatLng: function(t) { return this._latlng = o.latLng(t), this._map && (this._updatePosition(), this._adjustPan()), this }, getContent: function() { return this._content }, setContent: function(t) { return this._content = t, this.update(), this }, getElement: function() { return this._container }, update: function() { this._map && (this._container.style.visibility = "hidden", this._updateContent(), this._updateLayout(), this._updatePosition(), this._container.style.visibility = "", this._adjustPan()) }, getEvents: function() { var t = { zoom: this._updatePosition, viewreset: this._updatePosition }; return this._zoomAnimated && (t.zoomanim = this._animateZoom), ("closeOnClick" in this.options ? this.options.closeOnClick : this._map.options.closePopupOnClick) && (t.preclick = this._close), this.options.keepInView && (t.moveend = this._adjustPan), t }, isOpen: function() { return !!this._map && this._map.hasLayer(this) }, bringToFront: function() { return this._map && o.DomUtil.toFront(this._container), this }, bringToBack: function() { return this._map && o.DomUtil.toBack(this._container), this }, _close: function() { this._map && this._map.closePopup(this) }, _initLayout: function() { var t = "leaflet-popup", - e = this._container = o.DomUtil.create("div", t + " " + (this.options.className || "") + " leaflet-zoom-" + (this._zoomAnimated ? "animated" : "hide")); if (this.options.closeButton) { var i = this._closeButton = o.DomUtil.create("a", t + "-close-button", e); - i.href = "#close", i.innerHTML = "×", o.DomEvent.on(i, "click", this._onCloseButtonClick, this) } var n = this._wrapper = o.DomUtil.create("div", t + "-content-wrapper", e); - this._contentNode = o.DomUtil.create("div", t + "-content", n), o.DomEvent.disableClickPropagation(n).disableScrollPropagation(this._contentNode).on(n, "contextmenu", o.DomEvent.stopPropagation), this._tipContainer = o.DomUtil.create("div", t + "-tip-container", e), this._tip = o.DomUtil.create("div", t + "-tip", this._tipContainer) }, _updateContent: function() { if (this._content) { var t = this._contentNode, - e = "function" == typeof this._content ? this._content(this._source || this) : this._content; if ("string" == typeof e) t.innerHTML = e; - else { for (; t.hasChildNodes();) t.removeChild(t.firstChild); - t.appendChild(e) } - this.fire("contentupdate") } }, _updateLayout: function() { var t = this._contentNode, - e = t.style; - e.width = "", e.whiteSpace = "nowrap"; var i = t.offsetWidth; - i = Math.min(i, this.options.maxWidth), i = Math.max(i, this.options.minWidth), e.width = i + 1 + "px", e.whiteSpace = "", e.height = ""; var n = t.offsetHeight, - s = this.options.maxHeight, - r = "leaflet-popup-scrolled"; - s && n > s ? (e.height = s + "px", o.DomUtil.addClass(t, r)) : o.DomUtil.removeClass(t, r), this._containerWidth = this._container.offsetWidth }, _updatePosition: function() { if (this._map) { var t = this._map.latLngToLayerPoint(this._latlng), - e = o.point(this.options.offset); - this._zoomAnimated ? o.DomUtil.setPosition(this._container, t) : e = e.add(t); var i = this._containerBottom = -e.y, - n = this._containerLeft = -Math.round(this._containerWidth / 2) + e.x; - this._container.style.bottom = i + "px", this._container.style.left = n + "px" } }, _animateZoom: function(t) { var e = this._map._latLngToNewLayerPoint(this._latlng, t.zoom, t.center); - o.DomUtil.setPosition(this._container, e) }, _adjustPan: function() { if (!(!this.options.autoPan || this._map._panAnim && this._map._panAnim._inProgress)) { var t = this._map, - e = this._container.offsetHeight, - i = this._containerWidth, - n = new o.Point(this._containerLeft, -e - this._containerBottom); - this._zoomAnimated && n._add(o.DomUtil.getPosition(this._container)); var s = t.layerPointToContainerPoint(n), - r = o.point(this.options.autoPanPadding), - a = o.point(this.options.autoPanPaddingTopLeft || r), - h = o.point(this.options.autoPanPaddingBottomRight || r), - l = t.getSize(), - u = 0, - c = 0; - s.x + i + h.x > l.x && (u = s.x + i - l.x + h.x), s.x - u - a.x < 0 && (u = s.x - a.x), s.y + e + h.y > l.y && (c = s.y + e - l.y + h.y), s.y - c - a.y < 0 && (c = s.y - a.y), (u || c) && t.fire("autopanstart").panBy([u, c]) } }, _onCloseButtonClick: function(t) { this._close(), o.DomEvent.stop(t) } }), o.popup = function(t, e) { return new o.Popup(t, e) }, o.Map.include({ openPopup: function(t, e, i) { return t instanceof o.Popup || (t = new o.Popup(i).setContent(t)), e && t.setLatLng(e), this.hasLayer(t) ? this : (this._popup && this._popup.options.autoClose && this.closePopup(), this._popup = t, this.addLayer(t)) }, closePopup: function(t) { return t && t !== this._popup || (t = this._popup, this._popup = null), t && this.removeLayer(t), this } }), o.Layer.include({ bindPopup: function(t, e) { return t instanceof o.Popup ? (o.setOptions(t, e), this._popup = t, t._source = this) : ((!this._popup || e) && (this._popup = new o.Popup(e, this)), this._popup.setContent(t)), this._popupHandlersAdded || (this.on({ click: this._openPopup, remove: this.closePopup, move: this._movePopup }), this._popupHandlersAdded = !0), this._originalPopupOffset = this._popup.options.offset, this }, unbindPopup: function() { return this._popup && (this.off({ click: this._openPopup, remove: this.closePopup, move: this._movePopup }), this._popupHandlersAdded = !1, this._popup = null), this }, openPopup: function(t, e) { if (t instanceof o.Layer || (e = t, t = this), t instanceof o.FeatureGroup) - for (var i in this._layers) { t = this._layers[i]; break } - return e || (e = t.getCenter ? t.getCenter() : t.getLatLng()), this._popup && this._map && (this._popup.options.offset = this._popupAnchor(t), this._popup._source = t, this._popup.update(), this._map.openPopup(this._popup, e)), this }, closePopup: function() { return this._popup && this._popup._close(), this }, togglePopup: function(t) { return this._popup && (this._popup._map ? this.closePopup() : this.openPopup(t)), this }, isPopupOpen: function() { return this._popup.isOpen() }, setPopupContent: function(t) { return this._popup && this._popup.setContent(t), this }, getPopup: function() { return this._popup }, _openPopup: function(t) { var e = t.layer || t.target; if (this._popup && this._map) return e instanceof o.Path ? void this.openPopup(t.layer || t.target, t.latlng) : void(this._map.hasLayer(this._popup) && this._popup._source === e ? this.closePopup() : this.openPopup(e, t.latlng)) }, _popupAnchor: function(t) { var e = t._getPopupAnchor ? t._getPopupAnchor() : [0, 0], - i = this._originalPopupOffset || o.Popup.prototype.options.offset; return o.point(e).add(i) }, _movePopup: function(t) { this._popup.setLatLng(t.latlng) } }), o.Marker.include({ _getPopupAnchor: function() { return this.options.icon.options.popupAnchor || [0, 0] } }), o.LayerGroup = o.Layer.extend({ - initialize: function(t) { this._layers = {}; var e, i; if (t) - for (e = 0, i = t.length; i > e; e++) this.addLayer(t[e]) }, - addLayer: function(t) { var e = this.getLayerId(t); return this._layers[e] = t, this._map && this._map.addLayer(t), this }, - removeLayer: function(t) { - var e = t in this._layers ? t : this.getLayerId(t); - return this._map && this._layers[e] && this._map.removeLayer(this._layers[e]), - delete this._layers[e], this - }, - hasLayer: function(t) { return !!t && (t in this._layers || this.getLayerId(t) in this._layers) }, - clearLayers: function() { for (var t in this._layers) this.removeLayer(this._layers[t]); return this }, - invoke: function(t) { var e, i, n = Array.prototype.slice.call(arguments, 1); for (e in this._layers) i = this._layers[e], i[t] && i[t].apply(i, n); return this }, - onAdd: function(t) { for (var e in this._layers) t.addLayer(this._layers[e]) }, - onRemove: function(t) { for (var e in this._layers) t.removeLayer(this._layers[e]) }, - eachLayer: function(t, e) { for (var i in this._layers) t.call(e, this._layers[i]); return this }, - getLayer: function(t) { return this._layers[t] }, - getLayers: function() { var t = []; for (var e in this._layers) t.push(this._layers[e]); return t }, - setZIndex: function(t) { return this.invoke("setZIndex", t) }, - getLayerId: function(t) { return o.stamp(t) } - }), o.layerGroup = function(t) { return new o.LayerGroup(t) }, o.FeatureGroup = o.LayerGroup.extend({ addLayer: function(t) { return this.hasLayer(t) ? this : (t.addEventParent(this), o.LayerGroup.prototype.addLayer.call(this, t), this.fire("layeradd", { layer: t })) }, removeLayer: function(t) { return this.hasLayer(t) ? (t in this._layers && (t = this._layers[t]), t.removeEventParent(this), o.LayerGroup.prototype.removeLayer.call(this, t), this.fire("layerremove", { layer: t })) : this }, setStyle: function(t) { return this.invoke("setStyle", t) }, bringToFront: function() { return this.invoke("bringToFront") }, bringToBack: function() { return this.invoke("bringToBack") }, getBounds: function() { var t = new o.LatLngBounds; for (var e in this._layers) { var i = this._layers[e]; - t.extend(i.getBounds ? i.getBounds() : i.getLatLng()) } return t } }), o.featureGroup = function(t) { return new o.FeatureGroup(t) }, o.Renderer = o.Layer.extend({ options: { padding: .1 }, initialize: function(t) { o.setOptions(this, t), o.stamp(this) }, onAdd: function() { this._container || (this._initContainer(), this._zoomAnimated && o.DomUtil.addClass(this._container, "leaflet-zoom-animated")), this.getPane().appendChild(this._container), this._update() }, onRemove: function() { o.DomUtil.remove(this._container) }, getEvents: function() { var t = { viewreset: this._reset, zoomstart: this._onZoomStart, zoom: this._onZoom, moveend: this._update }; return this._zoomAnimated && (t.zoomanim = this._onAnimZoom), t }, _onAnimZoom: function(t) { this._updateTransform(t.center, t.zoom) }, _onZoom: function() { this._updateTransform(this._map.getCenter(), this._map.getZoom()) }, _onZoomStart: function() { this._update() }, _updateTransform: function(t, e) { var i = this._map.getZoomScale(e, this._zoom), - n = o.DomUtil.getPosition(this._container), - s = this._map.getSize().multiplyBy(.5 + this.options.padding), - r = this._map.project(this._center, e), - a = this._map.project(t, e), - h = a.subtract(r), - l = s.multiplyBy(-i).add(n).add(s).subtract(h); - o.DomUtil.setTransform(this._container, l, i) }, _reset: function() { this._update(), this._updateTransform(this._center, this._zoom) }, _update: function() { var t = this.options.padding, - e = this._map.getSize(), - i = this._map.containerPointToLayerPoint(e.multiplyBy(-t)).round(); - this._bounds = new o.Bounds(i, i.add(e.multiplyBy(1 + 2 * t)).round()), this._center = this._map.getCenter(), this._zoom = this._map.getZoom() } }), o.Map.include({ getRenderer: function(t) { var e = t.options.renderer || this._getPaneRenderer(t.options.pane) || this.options.renderer || this._renderer; return e || (e = this._renderer = this.options.preferCanvas && o.canvas() || o.svg()), this.hasLayer(e) || this.addLayer(e), e }, _getPaneRenderer: function(t) { if ("overlayPane" === t || t === i) return !1; var e = this._paneRenderers[t]; return e === i && (e = o.SVG && o.svg({ pane: t }) || o.Canvas && o.canvas({ pane: t }), this._paneRenderers[t] = e), e } }), o.Path = o.Layer.extend({ options: { stroke: !0, color: "#3388ff", weight: 3, opacity: 1, lineCap: "round", lineJoin: "round", fillOpacity: .2, fillRule: "evenodd", interactive: !0 }, beforeAdd: function(t) { this._renderer = t.getRenderer(this) }, onAdd: function() { this._renderer._initPath(this), this._reset(), this._renderer._addPath(this) }, onRemove: function() { this._renderer._removePath(this) }, getEvents: function() { return { zoomend: this._project, moveend: this._update, viewreset: this._reset } }, redraw: function() { return this._map && this._renderer._updatePath(this), this }, setStyle: function(t) { return o.setOptions(this, t), this._renderer && this._renderer._updateStyle(this), this }, bringToFront: function() { return this._renderer && this._renderer._bringToFront(this), this }, bringToBack: function() { return this._renderer && this._renderer._bringToBack(this), this }, getElement: function() { return this._path }, _reset: function() { this._project(), this._update() }, _clickTolerance: function() { return (this.options.stroke ? this.options.weight / 2 : 0) + (o.Browser.touch ? 10 : 0) } }), o.LineUtil = { simplify: function(t, e) { if (!e || !t.length) return t.slice(); var i = e * e; return t = this._reducePoints(t, i), t = this._simplifyDP(t, i) }, pointToSegmentDistance: function(t, e, i) { return Math.sqrt(this._sqClosestPointOnSegment(t, e, i, !0)) }, closestPointOnSegment: function(t, e, i) { return this._sqClosestPointOnSegment(t, e, i) }, _simplifyDP: function(t, e) { var n = t.length, - o = typeof Uint8Array != i + "" ? Uint8Array : Array, - s = new o(n); - s[0] = s[n - 1] = 1, this._simplifyDPStep(t, s, e, 0, n - 1); var r, a = []; for (r = 0; n > r; r++) s[r] && a.push(t[r]); return a }, _simplifyDPStep: function(t, e, i, n, o) { var s, r, a, h = 0; for (r = n + 1; o - 1 >= r; r++) a = this._sqClosestPointOnSegment(t[r], t[n], t[o], !0), a > h && (s = r, h = a); - h > i && (e[s] = 1, this._simplifyDPStep(t, e, i, n, s), this._simplifyDPStep(t, e, i, s, o)) }, _reducePoints: function(t, e) { for (var i = [t[0]], n = 1, o = 0, s = t.length; s > n; n++) this._sqDist(t[n], t[o]) > e && (i.push(t[n]), o = n); return s - 1 > o && i.push(t[s - 1]), i }, clipSegment: function(t, e, i, n, o) { var s, r, a, h = n ? this._lastCode : this._getBitCode(t, i), - l = this._getBitCode(e, i); for (this._lastCode = l;;) { if (!(h | l)) return [t, e]; if (h & l) return !1; - s = h || l, r = this._getEdgeIntersection(t, e, s, i, o), a = this._getBitCode(r, i), s === h ? (t = r, h = a) : (e = r, l = a) } }, _getEdgeIntersection: function(t, e, i, n, s) { var r, a, h = e.x - t.x, - l = e.y - t.y, - u = n.min, - c = n.max; return 8 & i ? (r = t.x + h * (c.y - t.y) / l, a = c.y) : 4 & i ? (r = t.x + h * (u.y - t.y) / l, a = u.y) : 2 & i ? (r = c.x, a = t.y + l * (c.x - t.x) / h) : 1 & i && (r = u.x, a = t.y + l * (u.x - t.x) / h), new o.Point(r, a, s) }, _getBitCode: function(t, e) { var i = 0; return t.x < e.min.x ? i |= 1 : t.x > e.max.x && (i |= 2), t.y < e.min.y ? i |= 4 : t.y > e.max.y && (i |= 8), i }, _sqDist: function(t, e) { var i = e.x - t.x, - n = e.y - t.y; return i * i + n * n }, _sqClosestPointOnSegment: function(t, e, i, n) { var s, r = e.x, - a = e.y, - h = i.x - r, - l = i.y - a, - u = h * h + l * l; return u > 0 && (s = ((t.x - r) * h + (t.y - a) * l) / u, s > 1 ? (r = i.x, a = i.y) : s > 0 && (r += h * s, a += l * s)), h = t.x - r, l = t.y - a, n ? h * h + l * l : new o.Point(r, a) } }, o.Polyline = o.Path.extend({ options: { smoothFactor: 1 }, initialize: function(t, e) { o.setOptions(this, e), this._setLatLngs(t) }, getLatLngs: function() { return this._latlngs }, setLatLngs: function(t) { return this._setLatLngs(t), this.redraw() }, isEmpty: function() { return !this._latlngs.length }, closestLayerPoint: function(t) { for (var e, i, n = 1 / 0, s = null, r = o.LineUtil._sqClosestPointOnSegment, a = 0, h = this._parts.length; h > a; a++) - for (var l = this._parts[a], u = 1, c = l.length; c > u; u++) { e = l[u - 1], i = l[u]; var d = r(t, e, i, !0); - n > d && (n = d, s = r(t, e, i)) } - return s && (s.distance = Math.sqrt(n)), s }, getCenter: function() { var t, e, i, n, o, s, r, a = this._rings[0], - h = a.length; if (!h) return null; for (t = 0, e = 0; h - 1 > t; t++) e += a[t].distanceTo(a[t + 1]) / 2; if (0 === e) return this._map.layerPointToLatLng(a[0]); for (t = 0, n = 0; h - 1 > t; t++) - if (o = a[t], s = a[t + 1], i = o.distanceTo(s), n += i, n > e) return r = (n - e) / i, this._map.layerPointToLatLng([s.x - r * (s.x - o.x), s.y - r * (s.y - o.y)]) }, getBounds: function() { return this._bounds }, addLatLng: function(t, e) { return e = e || this._defaultShape(), t = o.latLng(t), e.push(t), this._bounds.extend(t), this.redraw() }, _setLatLngs: function(t) { this._bounds = new o.LatLngBounds, this._latlngs = this._convertLatLngs(t) }, _defaultShape: function() { return o.Polyline._flat(this._latlngs) ? this._latlngs : this._latlngs[0] }, _convertLatLngs: function(t) { for (var e = [], i = o.Polyline._flat(t), n = 0, s = t.length; s > n; n++) i ? (e[n] = o.latLng(t[n]), this._bounds.extend(e[n])) : e[n] = this._convertLatLngs(t[n]); return e }, _project: function() { this._rings = [], this._projectLatlngs(this._latlngs, this._rings); var t = this._clickTolerance(), - e = new o.Point(t, -t); - this._bounds.isValid() && (this._pxBounds = new o.Bounds(this._map.latLngToLayerPoint(this._bounds.getSouthWest())._subtract(e), this._map.latLngToLayerPoint(this._bounds.getNorthEast())._add(e))) }, _projectLatlngs: function(t, e) { var i, n, s = t[0] instanceof o.LatLng, - r = t.length; if (s) { for (n = [], i = 0; r > i; i++) n[i] = this._map.latLngToLayerPoint(t[i]); - e.push(n) } else - for (i = 0; r > i; i++) this._projectLatlngs(t[i], e) }, _clipPoints: function() { var t = this._renderer._bounds; if (this._parts = [], this._pxBounds && this._pxBounds.intersects(t)) { if (this.options.noClip) return void(this._parts = this._rings); var e, i, n, s, r, a, h, l = this._parts; for (e = 0, n = 0, s = this._rings.length; s > e; e++) - for (h = this._rings[e], i = 0, r = h.length; r - 1 > i; i++) a = o.LineUtil.clipSegment(h[i], h[i + 1], t, i, !0), a && (l[n] = l[n] || [], l[n].push(a[0]), (a[1] !== h[i + 1] || i === r - 2) && (l[n].push(a[1]), n++)) } }, _simplifyPoints: function() { for (var t = this._parts, e = this.options.smoothFactor, i = 0, n = t.length; n > i; i++) t[i] = o.LineUtil.simplify(t[i], e) }, _update: function() { this._map && (this._clipPoints(), this._simplifyPoints(), this._updatePath()) }, _updatePath: function() { this._renderer._updatePoly(this) } }), o.polyline = function(t, e) { return new o.Polyline(t, e) }, o.Polyline._flat = function(t) { return !o.Util.isArray(t[0]) || "object" != typeof t[0][0] && "undefined" != typeof t[0][0] }, o.PolyUtil = {}, o.PolyUtil.clipPolygon = function(t, e, i) { var n, s, r, a, h, l, u, c, d, _ = [1, 4, 2, 8], - m = o.LineUtil; for (s = 0, u = t.length; u > s; s++) t[s]._code = m._getBitCode(t[s], e); for (a = 0; 4 > a; a++) { for (c = _[a], n = [], s = 0, u = t.length, r = u - 1; u > s; r = s++) h = t[s], l = t[r], h._code & c ? l._code & c || (d = m._getEdgeIntersection(l, h, c, e, i), d._code = m._getBitCode(d, e), n.push(d)) : (l._code & c && (d = m._getEdgeIntersection(l, h, c, e, i), d._code = m._getBitCode(d, e), n.push(d)), n.push(h)); - t = n } return t }, o.Polygon = o.Polyline.extend({ options: { fill: !0 }, isEmpty: function() { return !this._latlngs.length || !this._latlngs[0].length }, getCenter: function() { var t, e, i, n, o, s, r, a, h, l = this._rings[0], - u = l.length; if (!u) return null; for (s = r = a = 0, t = 0, e = u - 1; u > t; e = t++) i = l[t], n = l[e], o = i.y * n.x - n.y * i.x, r += (i.x + n.x) * o, a += (i.y + n.y) * o, s += 3 * o; return h = 0 === s ? l[0] : [r / s, a / s], this._map.layerPointToLatLng(h) }, _convertLatLngs: function(t) { var e = o.Polyline.prototype._convertLatLngs.call(this, t), - i = e.length; return i >= 2 && e[0] instanceof o.LatLng && e[0].equals(e[i - 1]) && e.pop(), e }, _setLatLngs: function(t) { o.Polyline.prototype._setLatLngs.call(this, t), o.Polyline._flat(this._latlngs) && (this._latlngs = [this._latlngs]) }, _defaultShape: function() { return o.Polyline._flat(this._latlngs[0]) ? this._latlngs[0] : this._latlngs[0][0] }, _clipPoints: function() { var t = this._renderer._bounds, - e = this.options.weight, - i = new o.Point(e, e); if (t = new o.Bounds(t.min.subtract(i), t.max.add(i)), this._parts = [], this._pxBounds && this._pxBounds.intersects(t)) { if (this.options.noClip) return void(this._parts = this._rings); for (var n, s = 0, r = this._rings.length; r > s; s++) n = o.PolyUtil.clipPolygon(this._rings[s], t, !0), n.length && this._parts.push(n) } }, _updatePath: function() { this._renderer._updatePoly(this, !0) } }), o.polygon = function(t, e) { return new o.Polygon(t, e) }, o.Rectangle = o.Polygon.extend({ initialize: function(t, e) { o.Polygon.prototype.initialize.call(this, this._boundsToLatLngs(t), e) }, setBounds: function(t) { return this.setLatLngs(this._boundsToLatLngs(t)) }, _boundsToLatLngs: function(t) { return t = o.latLngBounds(t), [t.getSouthWest(), t.getNorthWest(), t.getNorthEast(), t.getSouthEast()] } }), o.rectangle = function(t, e) { return new o.Rectangle(t, e) }, o.CircleMarker = o.Path.extend({ options: { fill: !0, radius: 10 }, initialize: function(t, e) { o.setOptions(this, e), this._latlng = o.latLng(t), this._radius = this.options.radius }, setLatLng: function(t) { return this._latlng = o.latLng(t), this.redraw(), this.fire("move", { latlng: this._latlng }) }, getLatLng: function() { return this._latlng }, setRadius: function(t) { return this.options.radius = this._radius = t, this.redraw() }, getRadius: function() { return this._radius }, setStyle: function(t) { var e = t && t.radius || this._radius; return o.Path.prototype.setStyle.call(this, t), this.setRadius(e), this }, _project: function() { this._point = this._map.latLngToLayerPoint(this._latlng), this._updateBounds() }, _updateBounds: function() { var t = this._radius, - e = this._radiusY || t, - i = this._clickTolerance(), - n = [t + i, e + i]; - this._pxBounds = new o.Bounds(this._point.subtract(n), this._point.add(n)) }, _update: function() { this._map && this._updatePath() }, _updatePath: function() { this._renderer._updateCircle(this) }, _empty: function() { return this._radius && !this._renderer._bounds.intersects(this._pxBounds) } }), o.circleMarker = function(t, e) { return new o.CircleMarker(t, e) }, o.Circle = o.CircleMarker.extend({ initialize: function(t, e) { o.setOptions(this, e), this._latlng = o.latLng(t), this._mRadius = this.options.radius }, setRadius: function(t) { return this._mRadius = t, this.redraw() }, getRadius: function() { return this._mRadius }, getBounds: function() { var t = [this._radius, this._radiusY || this._radius]; return new o.LatLngBounds(this._map.layerPointToLatLng(this._point.subtract(t)), this._map.layerPointToLatLng(this._point.add(t))) }, setStyle: o.Path.prototype.setStyle, _project: function() { var t = this._latlng.lng, - e = this._latlng.lat, - i = this._map, - n = i.options.crs; if (n.distance === o.CRS.Earth.distance) { var s = Math.PI / 180, - r = this._mRadius / o.CRS.Earth.R / s, - a = i.project([e + r, t]), - h = i.project([e - r, t]), - l = a.add(h).divideBy(2), - u = i.unproject(l).lat, - c = Math.acos((Math.cos(r * s) - Math.sin(e * s) * Math.sin(u * s)) / (Math.cos(e * s) * Math.cos(u * s))) / s; - this._point = l.subtract(i.getPixelOrigin()), this._radius = isNaN(c) ? 0 : Math.max(Math.round(l.x - i.project([u, t - c]).x), 1), this._radiusY = Math.max(Math.round(l.y - a.y), 1) } else { var d = n.unproject(n.project(this._latlng).subtract([this._mRadius, 0])); - this._point = i.latLngToLayerPoint(this._latlng), this._radius = this._point.x - i.latLngToLayerPoint(d).x } - this._updateBounds() } }), o.circle = function(t, e, i) { return "number" == typeof e && (e = o.extend({}, i, { radius: e })), new o.Circle(t, e) }, o.SVG = o.Renderer.extend({ _initContainer: function() { this._container = o.SVG.create("svg"), this._container.setAttribute("pointer-events", "none"), this._rootGroup = o.SVG.create("g"), this._container.appendChild(this._rootGroup) }, _update: function() { if (!this._map._animatingZoom || !this._bounds) { o.Renderer.prototype._update.call(this); var t = this._bounds, - e = t.getSize(), - i = this._container; - this._svgSize && this._svgSize.equals(e) || (this._svgSize = e, i.setAttribute("width", e.x), i.setAttribute("height", e.y)), o.DomUtil.setPosition(i, t.min), i.setAttribute("viewBox", [t.min.x, t.min.y, e.x, e.y].join(" ")) } }, _initPath: function(t) { var e = t._path = o.SVG.create("path"); - t.options.className && o.DomUtil.addClass(e, t.options.className), t.options.interactive && o.DomUtil.addClass(e, "leaflet-interactive"), this._updateStyle(t) }, _addPath: function(t) { this._rootGroup.appendChild(t._path), t.addInteractiveTarget(t._path) }, _removePath: function(t) { o.DomUtil.remove(t._path), t.removeInteractiveTarget(t._path) }, _updatePath: function(t) { t._project(), t._update() }, _updateStyle: function(t) { var e = t._path, - i = t.options; - e && (i.stroke ? (e.setAttribute("stroke", i.color), e.setAttribute("stroke-opacity", i.opacity), e.setAttribute("stroke-width", i.weight), e.setAttribute("stroke-linecap", i.lineCap), e.setAttribute("stroke-linejoin", i.lineJoin), i.dashArray ? e.setAttribute("stroke-dasharray", i.dashArray) : e.removeAttribute("stroke-dasharray"), i.dashOffset ? e.setAttribute("stroke-dashoffset", i.dashOffset) : e.removeAttribute("stroke-dashoffset")) : e.setAttribute("stroke", "none"), i.fill ? (e.setAttribute("fill", i.fillColor || i.color), e.setAttribute("fill-opacity", i.fillOpacity), e.setAttribute("fill-rule", i.fillRule || "evenodd")) : e.setAttribute("fill", "none"), e.setAttribute("pointer-events", i.pointerEvents || (i.interactive ? "visiblePainted" : "none"))) }, _updatePoly: function(t, e) { this._setPath(t, o.SVG.pointsToPath(t._parts, e)) }, _updateCircle: function(t) { var e = t._point, - i = t._radius, - n = t._radiusY || i, - o = "a" + i + "," + n + " 0 1,0 ", - s = t._empty() ? "M0 0" : "M" + (e.x - i) + "," + e.y + o + 2 * i + ",0 " + o + 2 * -i + ",0 "; - this._setPath(t, s) }, _setPath: function(t, e) { t._path.setAttribute("d", e) }, _bringToFront: function(t) { o.DomUtil.toFront(t._path) }, _bringToBack: function(t) { o.DomUtil.toBack(t._path) } }), o.extend(o.SVG, { create: function(t) { return e.createElementNS("http://www.w3.org/2000/svg", t) }, pointsToPath: function(t, e) { var i, n, s, r, a, h, l = ""; for (i = 0, s = t.length; s > i; i++) { for (a = t[i], n = 0, r = a.length; r > n; n++) h = a[n], l += (n ? "L" : "M") + h.x + " " + h.y; - l += e ? o.Browser.svg ? "z" : "x" : "" } return l || "M0 0" } }), o.Browser.svg = !(!e.createElementNS || !o.SVG.create("svg").createSVGRect), o.svg = function(t) { return o.Browser.svg || o.Browser.vml ? new o.SVG(t) : null }, o.Browser.vml = !o.Browser.svg && function() { try { var t = e.createElement("div"); - t.innerHTML = ''; var i = t.firstChild; return i.style.behavior = "url(#default#VML)", i && "object" == typeof i.adj } catch (n) { return !1 } }(), o.SVG.include(o.Browser.vml ? { _initContainer: function() { this._container = o.DomUtil.create("div", "leaflet-vml-container") }, _update: function() { this._map._animatingZoom || o.Renderer.prototype._update.call(this) }, _initPath: function(t) { var e = t._container = o.SVG.create("shape"); - o.DomUtil.addClass(e, "leaflet-vml-shape " + (this.options.className || "")), e.coordsize = "1 1", t._path = o.SVG.create("path"), e.appendChild(t._path), this._updateStyle(t) }, _addPath: function(t) { var e = t._container; - this._container.appendChild(e), t.options.interactive && t.addInteractiveTarget(e) }, _removePath: function(t) { var e = t._container; - o.DomUtil.remove(e), t.removeInteractiveTarget(e) }, _updateStyle: function(t) { var e = t._stroke, - i = t._fill, - n = t.options, - s = t._container; - s.stroked = !!n.stroke, s.filled = !!n.fill, n.stroke ? (e || (e = t._stroke = o.SVG.create("stroke")), s.appendChild(e), e.weight = n.weight + "px", e.color = n.color, e.opacity = n.opacity, n.dashArray ? e.dashStyle = o.Util.isArray(n.dashArray) ? n.dashArray.join(" ") : n.dashArray.replace(/( *, *)/g, " ") : e.dashStyle = "", e.endcap = n.lineCap.replace("butt", "flat"), e.joinstyle = n.lineJoin) : e && (s.removeChild(e), t._stroke = null), n.fill ? (i || (i = t._fill = o.SVG.create("fill")), s.appendChild(i), i.color = n.fillColor || n.color, i.opacity = n.fillOpacity) : i && (s.removeChild(i), t._fill = null) }, _updateCircle: function(t) { var e = t._point.round(), - i = Math.round(t._radius), - n = Math.round(t._radiusY || i); - this._setPath(t, t._empty() ? "M0 0" : "AL " + e.x + "," + e.y + " " + i + "," + n + " 0,23592600") }, _setPath: function(t, e) { t._path.v = e }, _bringToFront: function(t) { o.DomUtil.toFront(t._container) }, _bringToBack: function(t) { o.DomUtil.toBack(t._container) } } : {}), o.Browser.vml && (o.SVG.create = function() { try { return e.namespaces.add("lvml", "urn:schemas-microsoft-com:vml"), - function(t) { return e.createElement("') } } catch (t) { return function(t) { return e.createElement("<" + t + ' xmlns="urn:schemas-microsoft.com:vml" class="lvml">') } } }()), o.Canvas = o.Renderer.extend({ onAdd: function() { o.Renderer.prototype.onAdd.call(this), this._layers = this._layers || {}, this._draw() }, _initContainer: function() { var t = this._container = e.createElement("canvas"); - o.DomEvent.on(t, "mousemove", o.Util.throttle(this._onMouseMove, 32, this), this).on(t, "click dblclick mousedown mouseup contextmenu", this._onClick, this).on(t, "mouseout", this._handleMouseOut, this), this._ctx = t.getContext("2d") }, _update: function() { if (!this._map._animatingZoom || !this._bounds) { this._drawnLayers = {}, o.Renderer.prototype._update.call(this); var t = this._bounds, - e = this._container, - i = t.getSize(), - n = o.Browser.retina ? 2 : 1; - o.DomUtil.setPosition(e, t.min), e.width = n * i.x, e.height = n * i.y, e.style.width = i.x + "px", e.style.height = i.y + "px", o.Browser.retina && this._ctx.scale(2, 2), this._ctx.translate(-t.min.x, -t.min.y) } }, _initPath: function(t) { this._layers[o.stamp(t)] = t }, _addPath: o.Util.falseFn, _removePath: function(t) { t._removed = !0, this._requestRedraw(t) }, _updatePath: function(t) { this._redrawBounds = t._pxBounds, this._draw(!0), t._project(), t._update(), this._draw(), this._redrawBounds = null }, _updateStyle: function(t) { this._requestRedraw(t) }, _requestRedraw: function(t) { if (this._map) { var e = (t.options.weight || 0) + 1; - this._redrawBounds = this._redrawBounds || new o.Bounds, this._redrawBounds.extend(t._pxBounds.min.subtract([e, e])), this._redrawBounds.extend(t._pxBounds.max.add([e, e])), this._redrawRequest = this._redrawRequest || o.Util.requestAnimFrame(this._redraw, this) } }, _redraw: function() { this._redrawRequest = null, this._draw(!0), this._draw(), this._redrawBounds = null }, _draw: function(t) { this._clear = t; var e, i = this._redrawBounds; - this._ctx.save(), i && (this._ctx.beginPath(), this._ctx.rect(i.min.x, i.min.y, i.max.x - i.min.x, i.max.y - i.min.y), this._ctx.clip()); for (var n in this._layers) e = this._layers[n], (!i || e._pxBounds.intersects(i)) && e._updatePath(), t && e._removed && (delete e._removed, delete this._layers[n]); - this._ctx.restore() }, _updatePoly: function(t, e) { var i, n, o, s, r = t._parts, - a = r.length, - h = this._ctx; if (a) { for (this._drawnLayers[t._leaflet_id] = t, h.beginPath(), i = 0; a > i; i++) { for (n = 0, o = r[i].length; o > n; n++) s = r[i][n], h[n ? "lineTo" : "moveTo"](s.x, s.y); - e && h.closePath() } - this._fillStroke(h, t) } }, _updateCircle: function(t) { if (!t._empty()) { var e = t._point, - i = this._ctx, - n = t._radius, - o = (t._radiusY || n) / n; - 1 !== o && (i.save(), i.scale(1, o)), i.beginPath(), i.arc(e.x, e.y / o, n, 0, 2 * Math.PI, !1), 1 !== o && i.restore(), this._fillStroke(i, t) } }, _fillStroke: function(t, e) { var i = this._clear, - n = e.options; - t.globalCompositeOperation = i ? "destination-out" : "source-over", n.fill && (t.globalAlpha = i ? 1 : n.fillOpacity, t.fillStyle = n.fillColor || n.color, t.fill(n.fillRule || "evenodd")), n.stroke && 0 !== n.weight && (t.globalAlpha = i ? 1 : n.opacity, e._prevWeight = t.lineWidth = i ? e._prevWeight + 1 : n.weight, t.strokeStyle = n.color, t.lineCap = n.lineCap, t.lineJoin = n.lineJoin, t.stroke()) }, _onClick: function(t) { var e = this._map.mouseEventToLayerPoint(t), - i = []; for (var n in this._layers) this._layers[n]._containsPoint(e) && (o.DomEvent._fakeStop(t), i.push(this._layers[n])); - i.length && this._fireEvent(i, t) }, _onMouseMove: function(t) { if (this._map && !this._map.dragging._draggable._moving && !this._map._animatingZoom) { var e = this._map.mouseEventToLayerPoint(t); - this._handleMouseOut(t, e), this._handleMouseHover(t, e) } }, _handleMouseOut: function(t, e) { var i = this._hoveredLayer;!i || "mouseout" !== t.type && i._containsPoint(e) || (o.DomUtil.removeClass(this._container, "leaflet-interactive"), this._fireEvent([i], t, "mouseout"), this._hoveredLayer = null) }, _handleMouseHover: function(t, e) { var i, n; if (!this._hoveredLayer) - for (i in this._drawnLayers) - if (n = this._drawnLayers[i], n.options.interactive && n._containsPoint(e)) { o.DomUtil.addClass(this._container, "leaflet-interactive"), this._fireEvent([n], t, "mouseover"), this._hoveredLayer = n; break } - this._hoveredLayer && this._fireEvent([this._hoveredLayer], t) }, _fireEvent: function(t, e, i) { this._map._fireDOMEvent(e, i || e.type, t) }, _bringToFront: o.Util.falseFn, _bringToBack: o.Util.falseFn }), o.Browser.canvas = function() { return !!e.createElement("canvas").getContext }(), o.canvas = function(t) { return o.Browser.canvas ? new o.Canvas(t) : null }, o.Polyline.prototype._containsPoint = function(t, e) { var i, n, s, r, a, h, l = this._clickTolerance(); if (!this._pxBounds.contains(t)) return !1; for (i = 0, r = this._parts.length; r > i; i++) - for (h = this._parts[i], n = 0, a = h.length, s = a - 1; a > n; s = n++) - if ((e || 0 !== n) && o.LineUtil.pointToSegmentDistance(t, h[s], h[n]) <= l) return !0; - return !1 }, o.Polygon.prototype._containsPoint = function(t) { var e, i, n, s, r, a, h, l, u = !1; if (!this._pxBounds.contains(t)) return !1; for (s = 0, h = this._parts.length; h > s; s++) - for (e = this._parts[s], r = 0, l = e.length, a = l - 1; l > r; a = r++) i = e[r], n = e[a], i.y > t.y != n.y > t.y && t.x < (n.x - i.x) * (t.y - i.y) / (n.y - i.y) + i.x && (u = !u); return u || o.Polyline.prototype._containsPoint.call(this, t, !0) }, o.CircleMarker.prototype._containsPoint = function(t) { return t.distanceTo(this._point) <= this._radius + this._clickTolerance() }, o.GeoJSON = o.FeatureGroup.extend({ initialize: function(t, e) { o.setOptions(this, e), this._layers = {}, t && this.addData(t) }, addData: function(t) { var e, i, n, s = o.Util.isArray(t) ? t : t.features; if (s) { for (e = 0, i = s.length; i > e; e++) n = s[e], (n.geometries || n.geometry || n.features || n.coordinates) && this.addData(n); return this } var r = this.options; if (r.filter && !r.filter(t)) return this; var a = o.GeoJSON.geometryToLayer(t, r); return a ? (a.feature = o.GeoJSON.asFeature(t), a.defaultOptions = a.options, this.resetStyle(a), r.onEachFeature && r.onEachFeature(t, a), this.addLayer(a)) : this }, resetStyle: function(t) { return t.options = t.defaultOptions, this._setLayerStyle(t, this.options.style), this }, setStyle: function(t) { return this.eachLayer(function(e) { this._setLayerStyle(e, t) }, this) }, _setLayerStyle: function(t, e) { "function" == typeof e && (e = e(t.feature)), t.setStyle && t.setStyle(e) } }), o.extend(o.GeoJSON, { geometryToLayer: function(t, e) { var i, n, s, r, a = "Feature" === t.type ? t.geometry : t, - h = a ? a.coordinates : null, - l = [], - u = e && e.pointToLayer, - c = e && e.coordsToLatLng || this.coordsToLatLng; if (!h && !a) return null; switch (a.type) { - case "Point": - return i = c(h), u ? u(t, i) : new o.Marker(i); - case "MultiPoint": - for (s = 0, r = h.length; r > s; s++) i = c(h[s]), l.push(u ? u(t, i) : new o.Marker(i)); return new o.FeatureGroup(l); - case "LineString": - case "MultiLineString": - return n = this.coordsToLatLngs(h, "LineString" === a.type ? 0 : 1, c), new o.Polyline(n, e); - case "Polygon": - case "MultiPolygon": - return n = this.coordsToLatLngs(h, "Polygon" === a.type ? 1 : 2, c), new o.Polygon(n, e); - case "GeometryCollection": - for (s = 0, r = a.geometries.length; r > s; s++) { var d = this.geometryToLayer({ geometry: a.geometries[s], type: "Feature", properties: t.properties }, e); - d && l.push(d) } return new o.FeatureGroup(l); - default: - throw new Error("Invalid GeoJSON object.") } }, coordsToLatLng: function(t) { return new o.LatLng(t[1], t[0], t[2]) }, coordsToLatLngs: function(t, e, i) { for (var n, o = [], s = 0, r = t.length; r > s; s++) n = e ? this.coordsToLatLngs(t[s], e - 1, i) : (i || this.coordsToLatLng)(t[s]), o.push(n); return o }, latLngToCoords: function(t) { return t.alt !== i ? [t.lng, t.lat, t.alt] : [t.lng, t.lat] }, latLngsToCoords: function(t, e, i) { for (var n = [], s = 0, r = t.length; r > s; s++) n.push(e ? o.GeoJSON.latLngsToCoords(t[s], e - 1, i) : o.GeoJSON.latLngToCoords(t[s])); return !e && i && n.push(n[0]), n }, getFeature: function(t, e) { return t.feature ? o.extend({}, t.feature, { geometry: e }) : o.GeoJSON.asFeature(e) }, asFeature: function(t) { return "Feature" === t.type ? t : { type: "Feature", properties: {}, geometry: t } } }); - var r = { toGeoJSON: function() { return o.GeoJSON.getFeature(this, { type: "Point", coordinates: o.GeoJSON.latLngToCoords(this.getLatLng()) }) } }; - o.Marker.include(r), o.Circle.include(r), o.CircleMarker.include(r), o.Polyline.prototype.toGeoJSON = function() { var t = !o.Polyline._flat(this._latlngs), - e = o.GeoJSON.latLngsToCoords(this._latlngs, t ? 1 : 0); return o.GeoJSON.getFeature(this, { type: (t ? "Multi" : "") + "LineString", coordinates: e }) }, o.Polygon.prototype.toGeoJSON = function() { var t = !o.Polyline._flat(this._latlngs), - e = t && !o.Polyline._flat(this._latlngs[0]), - i = o.GeoJSON.latLngsToCoords(this._latlngs, e ? 2 : t ? 1 : 0, !0); return t || (i = [i]), o.GeoJSON.getFeature(this, { type: (e ? "Multi" : "") + "Polygon", coordinates: i }) }, o.LayerGroup.include({ toMultiPoint: function() { var t = []; return this.eachLayer(function(e) { t.push(e.toGeoJSON().geometry.coordinates) }), o.GeoJSON.getFeature(this, { type: "MultiPoint", coordinates: t }) }, toGeoJSON: function() { var t = this.feature && this.feature.geometry && this.feature.geometry.type; if ("MultiPoint" === t) return this.toMultiPoint(); var e = "GeometryCollection" === t, - i = []; return this.eachLayer(function(t) { if (t.toGeoJSON) { var n = t.toGeoJSON(); - i.push(e ? n.geometry : o.GeoJSON.asFeature(n)) } }), e ? o.GeoJSON.getFeature(this, { geometries: i, type: "GeometryCollection" }) : { type: "FeatureCollection", features: i } } }), o.geoJson = function(t, e) { return new o.GeoJSON(t, e) }; - var a = "_leaflet_events"; - o.DomEvent = { on: function(t, e, i, n) { if ("object" == typeof e) - for (var s in e) this._on(t, s, e[s], i); - else { e = o.Util.splitWords(e); for (var r = 0, a = e.length; a > r; r++) this._on(t, e[r], i, n) } return this }, off: function(t, e, i, n) { if ("object" == typeof e) - for (var s in e) this._off(t, s, e[s], i); - else { e = o.Util.splitWords(e); for (var r = 0, a = e.length; a > r; r++) this._off(t, e[r], i, n) } return this }, _on: function(e, i, n, s) { var r = i + o.stamp(n) + (s ? "_" + o.stamp(s) : ""); if (e[a] && e[a][r]) return this; var h = function(i) { return n.call(s || e, i || t.event) }, - l = h; return o.Browser.pointer && 0 === i.indexOf("touch") ? this.addPointerListener(e, i, h, r) : o.Browser.touch && "dblclick" === i && this.addDoubleTapListener ? this.addDoubleTapListener(e, h, r) : "addEventListener" in e ? "mousewheel" === i ? (e.addEventListener("DOMMouseScroll", h, !1), e.addEventListener(i, h, !1)) : "mouseenter" === i || "mouseleave" === i ? (h = function(i) { i = i || t.event, o.DomEvent._isExternalTarget(e, i) && l(i) }, e.addEventListener("mouseenter" === i ? "mouseover" : "mouseout", h, !1)) : ("click" === i && o.Browser.android && (h = function(t) { return o.DomEvent._filterClick(t, l) }), e.addEventListener(i, h, !1)) : "attachEvent" in e && e.attachEvent("on" + i, h), e[a] = e[a] || {}, e[a][r] = h, this }, _off: function(t, e, i, n) { var s = e + o.stamp(i) + (n ? "_" + o.stamp(n) : ""), - r = t[a] && t[a][s]; return r ? (o.Browser.pointer && 0 === e.indexOf("touch") ? this.removePointerListener(t, e, s) : o.Browser.touch && "dblclick" === e && this.removeDoubleTapListener ? this.removeDoubleTapListener(t, s) : "removeEventListener" in t ? "mousewheel" === e ? (t.removeEventListener("DOMMouseScroll", r, !1), t.removeEventListener(e, r, !1)) : t.removeEventListener("mouseenter" === e ? "mouseover" : "mouseleave" === e ? "mouseout" : e, r, !1) : "detachEvent" in t && t.detachEvent("on" + e, r), t[a][s] = null, this) : this }, stopPropagation: function(t) { return t.stopPropagation ? t.stopPropagation() : t.originalEvent ? t.originalEvent._stopped = !0 : t.cancelBubble = !0, o.DomEvent._skipped(t), this }, disableScrollPropagation: function(t) { return o.DomEvent.on(t, "mousewheel MozMousePixelScroll", o.DomEvent.stopPropagation) }, disableClickPropagation: function(t) { var e = o.DomEvent.stopPropagation; return o.DomEvent.on(t, o.Draggable.START.join(" "), e), o.DomEvent.on(t, { click: o.DomEvent._fakeStop, dblclick: e }) }, preventDefault: function(t) { return t.preventDefault ? t.preventDefault() : t.returnValue = !1, this }, stop: function(t) { return o.DomEvent.preventDefault(t).stopPropagation(t) }, getMousePosition: function(t, e) { if (!e) return new o.Point(t.clientX, t.clientY); var i = e.getBoundingClientRect(); return new o.Point(t.clientX - i.left - e.clientLeft, t.clientY - i.top - e.clientTop) }, getWheelDelta: function(t) { var e = 0; return t.wheelDelta && (e = t.wheelDelta / 120), t.detail && (e = -t.detail / 3), e }, _skipEvents: {}, _fakeStop: function(t) { o.DomEvent._skipEvents[t.type] = !0 }, _skipped: function(t) { var e = this._skipEvents[t.type]; return this._skipEvents[t.type] = !1, e }, _isExternalTarget: function(t, e) { var i = e.relatedTarget; if (!i) return !0; try { for (; i && i !== t;) i = i.parentNode } catch (n) { return !1 } return i !== t }, _filterClick: function(t, e) { var i = t.timeStamp || t.originalEvent.timeStamp, - n = o.DomEvent._lastClick && i - o.DomEvent._lastClick; return n && n > 100 && 500 > n || t.target._simulatedClick && !t._simulated ? void o.DomEvent.stop(t) : (o.DomEvent._lastClick = i, void e(t)) } }, o.DomEvent.addListener = o.DomEvent.on, o.DomEvent.removeListener = o.DomEvent.off, o.Draggable = o.Evented.extend({ - statics: { START: o.Browser.touch ? ["touchstart", "mousedown"] : ["mousedown"], END: { mousedown: "mouseup", touchstart: "touchend", pointerdown: "touchend", MSPointerDown: "touchend" }, MOVE: { mousedown: "mousemove", touchstart: "touchmove", pointerdown: "touchmove", MSPointerDown: "touchmove" } }, - initialize: function(t, e, i) { this._element = t, this._dragStartTarget = e || t, this._preventOutline = i }, - enable: function() { this._enabled || (o.DomEvent.on(this._dragStartTarget, o.Draggable.START.join(" "), this._onDown, this), this._enabled = !0) }, - disable: function() { this._enabled && (o.DomEvent.off(this._dragStartTarget, o.Draggable.START.join(" "), this._onDown, this), this._enabled = !1, this._moved = !1) }, - _onDown: function(t) { if (this._moved = !1, !o.DomUtil.hasClass(this._element, "leaflet-zoom-anim") && !(o.Draggable._dragging || t.shiftKey || 1 !== t.which && 1 !== t.button && !t.touches) && this._enabled && (o.Draggable._dragging = !0, this._preventOutline && o.DomUtil.preventOutline(this._element), o.DomUtil.disableImageDrag(), o.DomUtil.disableTextSelection(), !this._moving)) { this.fire("down"); var i = t.touches ? t.touches[0] : t; - this._startPoint = new o.Point(i.clientX, i.clientY), this._startPos = this._newPos = o.DomUtil.getPosition(this._element), o.DomEvent.on(e, o.Draggable.MOVE[t.type], this._onMove, this).on(e, o.Draggable.END[t.type], this._onUp, this) } }, - _onMove: function(t) { - if (t.touches && t.touches.length > 1) return void(this._moved = !0); - var i = t.touches && 1 === t.touches.length ? t.touches[0] : t, - n = new o.Point(i.clientX, i.clientY), - s = n.subtract(this._startPoint); - (s.x || s.y) && (o.Browser.touch && Math.abs(s.x) + Math.abs(s.y) < 3 || (o.DomEvent.preventDefault(t), this._moved || (this.fire("dragstart"), this._moved = !0, this._startPos = o.DomUtil.getPosition(this._element).subtract(s), o.DomUtil.addClass(e.body, "leaflet-dragging"), this._lastTarget = t.target || t.srcElement, o.DomUtil.addClass(this._lastTarget, "leaflet-drag-target")), - this._newPos = this._startPos.add(s), this._moving = !0, o.Util.cancelAnimFrame(this._animRequest), this._lastEvent = t, this._animRequest = o.Util.requestAnimFrame(this._updatePosition, this, !0))) - }, - _updatePosition: function() { var t = { originalEvent: this._lastEvent }; - this.fire("predrag", t), o.DomUtil.setPosition(this._element, this._newPos), this.fire("drag", t) }, - _onUp: function() { o.DomUtil.removeClass(e.body, "leaflet-dragging"), this._lastTarget && (o.DomUtil.removeClass(this._lastTarget, "leaflet-drag-target"), this._lastTarget = null); for (var t in o.Draggable.MOVE) o.DomEvent.off(e, o.Draggable.MOVE[t], this._onMove, this).off(e, o.Draggable.END[t], this._onUp, this); - o.DomUtil.enableImageDrag(), o.DomUtil.enableTextSelection(), this._moved && this._moving && (o.Util.cancelAnimFrame(this._animRequest), this.fire("dragend", { distance: this._newPos.distanceTo(this._startPos) })), this._moving = !1, o.Draggable._dragging = !1 } - }), o.Handler = o.Class.extend({ initialize: function(t) { this._map = t }, enable: function() { this._enabled || (this._enabled = !0, this.addHooks()) }, disable: function() { this._enabled && (this._enabled = !1, this.removeHooks()) }, enabled: function() { return !!this._enabled } }), o.Map.mergeOptions({ dragging: !0, inertia: !o.Browser.android23, inertiaDeceleration: 3400, inertiaMaxSpeed: 1 / 0, easeLinearity: .2, worldCopyJump: !1 }), o.Map.Drag = o.Handler.extend({ addHooks: function() { if (!this._draggable) { var t = this._map; - this._draggable = new o.Draggable(t._mapPane, t._container), this._draggable.on({ down: this._onDown, dragstart: this._onDragStart, drag: this._onDrag, dragend: this._onDragEnd }, this), this._draggable.on("predrag", this._onPreDragLimit, this), t.options.worldCopyJump && (this._draggable.on("predrag", this._onPreDragWrap, this), t.on("zoomend", this._onZoomEnd, this), t.whenReady(this._onZoomEnd, this)) } - o.DomUtil.addClass(this._map._container, "leaflet-grab"), this._draggable.enable() }, removeHooks: function() { o.DomUtil.removeClass(this._map._container, "leaflet-grab"), this._draggable.disable() }, moved: function() { return this._draggable && this._draggable._moved }, _onDown: function() { this._map.stop() }, _onDragStart: function() { var t = this._map; if (this._map.options.maxBounds && this._map.options.maxBoundsViscosity) { var e = o.latLngBounds(this._map.options.maxBounds); - this._offsetLimit = o.bounds(this._map.latLngToContainerPoint(e.getNorthWest()).multiplyBy(-1), this._map.latLngToContainerPoint(e.getSouthEast()).multiplyBy(-1).add(this._map.getSize())), this._viscosity = Math.min(1, Math.max(0, this._map.options.maxBoundsViscosity)) } else this._offsetLimit = null; - t.fire("movestart").fire("dragstart"), t.options.inertia && (this._positions = [], this._times = []) }, _onDrag: function(t) { if (this._map.options.inertia) { var e = this._lastTime = +new Date, - i = this._lastPos = this._draggable._absPos || this._draggable._newPos; - this._positions.push(i), this._times.push(e), e - this._times[0] > 50 && (this._positions.shift(), this._times.shift()) } - this._map.fire("move", t).fire("drag", t) }, _onZoomEnd: function() { var t = this._map.getSize().divideBy(2), - e = this._map.latLngToLayerPoint([0, 0]); - this._initialWorldOffset = e.subtract(t).x, this._worldWidth = this._map.getPixelWorldBounds().getSize().x }, _viscousLimit: function(t, e) { return t - (t - e) * this._viscosity }, _onPreDragLimit: function() { if (this._viscosity && this._offsetLimit) { var t = this._draggable._newPos.subtract(this._draggable._startPos), - e = this._offsetLimit; - t.x < e.min.x && (t.x = this._viscousLimit(t.x, e.min.x)), t.y < e.min.y && (t.y = this._viscousLimit(t.y, e.min.y)), t.x > e.max.x && (t.x = this._viscousLimit(t.x, e.max.x)), t.y > e.max.y && (t.y = this._viscousLimit(t.y, e.max.y)), this._draggable._newPos = this._draggable._startPos.add(t) } }, _onPreDragWrap: function() { var t = this._worldWidth, - e = Math.round(t / 2), - i = this._initialWorldOffset, - n = this._draggable._newPos.x, - o = (n - e + i) % t + e - i, - s = (n + e + i) % t - e - i, - r = Math.abs(o + i) < Math.abs(s + i) ? o : s; - this._draggable._absPos = this._draggable._newPos.clone(), this._draggable._newPos.x = r }, _onDragEnd: function(t) { var e = this._map, - i = e.options, - n = !i.inertia || this._times.length < 2; if (e.fire("dragend", t), n) e.fire("moveend"); - else { var s = this._lastPos.subtract(this._positions[0]), - r = (this._lastTime - this._times[0]) / 1e3, - a = i.easeLinearity, - h = s.multiplyBy(a / r), - l = h.distanceTo([0, 0]), - u = Math.min(i.inertiaMaxSpeed, l), - c = h.multiplyBy(u / l), - d = u / (i.inertiaDeceleration * a), - _ = c.multiplyBy(-d / 2).round(); - _.x || _.y ? (_ = e._limitOffset(_, e.options.maxBounds), o.Util.requestAnimFrame(function() { e.panBy(_, { duration: d, easeLinearity: a, noMoveStart: !0, animate: !0 }) })) : e.fire("moveend") } } }), o.Map.addInitHook("addHandler", "dragging", o.Map.Drag), o.Map.mergeOptions({ doubleClickZoom: !0 }), o.Map.DoubleClickZoom = o.Handler.extend({ addHooks: function() { this._map.on("dblclick", this._onDoubleClick, this) }, removeHooks: function() { this._map.off("dblclick", this._onDoubleClick, this) }, _onDoubleClick: function(t) { var e = this._map, - i = e.getZoom(), - n = t.originalEvent.shiftKey ? Math.ceil(i) - 1 : Math.floor(i) + 1; "center" === e.options.doubleClickZoom ? e.setZoom(n) : e.setZoomAround(t.containerPoint, n) } }), o.Map.addInitHook("addHandler", "doubleClickZoom", o.Map.DoubleClickZoom), o.Map.mergeOptions({ scrollWheelZoom: !0, wheelDebounceTime: 40 }), o.Map.ScrollWheelZoom = o.Handler.extend({ addHooks: function() { o.DomEvent.on(this._map._container, { mousewheel: this._onWheelScroll, MozMousePixelScroll: o.DomEvent.preventDefault }, this), this._delta = 0 }, removeHooks: function() { o.DomEvent.off(this._map._container, { mousewheel: this._onWheelScroll, MozMousePixelScroll: o.DomEvent.preventDefault }, this) }, _onWheelScroll: function(t) { var e = o.DomEvent.getWheelDelta(t), - i = this._map.options.wheelDebounceTime; - this._delta += e, this._lastMousePos = this._map.mouseEventToContainerPoint(t), this._startTime || (this._startTime = +new Date); var n = Math.max(i - (+new Date - this._startTime), 0); - clearTimeout(this._timer), this._timer = setTimeout(o.bind(this._performZoom, this), n), o.DomEvent.stop(t) }, _performZoom: function() { var t = this._map, - e = this._delta, - i = t.getZoom(); - t.stop(), e = e > 0 ? Math.ceil(e) : Math.floor(e), e = Math.max(Math.min(e, 4), -4), e = t._limitZoom(i + e) - i, this._delta = 0, this._startTime = null, e && ("center" === t.options.scrollWheelZoom ? t.setZoom(i + e) : t.setZoomAround(this._lastMousePos, i + e)) } }), o.Map.addInitHook("addHandler", "scrollWheelZoom", o.Map.ScrollWheelZoom), o.extend(o.DomEvent, { _touchstart: o.Browser.msPointer ? "MSPointerDown" : o.Browser.pointer ? "pointerdown" : "touchstart", _touchend: o.Browser.msPointer ? "MSPointerUp" : o.Browser.pointer ? "pointerup" : "touchend", addDoubleTapListener: function(t, e, i) { - function n(t) { var e; if (e = o.Browser.pointer ? o.DomEvent._pointersCount : t.touches.length, !(e > 1)) { var i = Date.now(), - n = i - (r || i); - a = t.touches ? t.touches[0] : t, h = n > 0 && l >= n, r = i } } + function i(e) { + var i = +new Date(), + o = Math.max(0, 16 - (i - n)); + return (n = i + o), t.setTimeout(e, o); + } + var n = 0, + s = t.requestAnimationFrame || e("RequestAnimationFrame") || i, + r = + t.cancelAnimationFrame || + e("CancelAnimationFrame") || + e("CancelRequestAnimationFrame") || + function (e) { + t.clearTimeout(e); + }; + (o.Util.requestAnimFrame = function (e, n, r) { + return r && s === i ? void e.call(n) : s.call(t, o.bind(e, n)); + }), + (o.Util.cancelAnimFrame = function (e) { + e && r.call(t, e); + }); + })(), + (o.extend = o.Util.extend), + (o.bind = o.Util.bind), + (o.stamp = o.Util.stamp), + (o.setOptions = o.Util.setOptions), + (o.Class = function () {}), + (o.Class.extend = function (t) { + var e = function () { + this.initialize && this.initialize.apply(this, arguments), this.callInitHooks(); + }, + i = (e.__super__ = this.prototype), + n = o.Util.create(i); + (n.constructor = e), (e.prototype = n); + for (var s in this) this.hasOwnProperty(s) && "prototype" !== s && (e[s] = this[s]); + return ( + t.statics && (o.extend(e, t.statics), delete t.statics), + t.includes && (o.Util.extend.apply(null, [n].concat(t.includes)), delete t.includes), + n.options && (t.options = o.Util.extend(o.Util.create(n.options), t.options)), + o.extend(n, t), + (n._initHooks = []), + (n.callInitHooks = function () { + if (!this._initHooksCalled) { + i.callInitHooks && i.callInitHooks.call(this), (this._initHooksCalled = !0); + for (var t = 0, e = n._initHooks.length; e > t; t++) n._initHooks[t].call(this); + } + }), + e + ); + }), + (o.Class.include = function (t) { + o.extend(this.prototype, t); + }), + (o.Class.mergeOptions = function (t) { + o.extend(this.prototype.options, t); + }), + (o.Class.addInitHook = function (t) { + var e = Array.prototype.slice.call(arguments, 1), + i = + "function" == typeof t + ? t + : function () { + this[t].apply(this, e); + }; + (this.prototype._initHooks = this.prototype._initHooks || []), this.prototype._initHooks.push(i); + }), + (o.Evented = o.Class.extend({ + on: function (t, e, i) { + if ("object" == typeof t) for (var n in t) this._on(n, t[n], e); + else { + t = o.Util.splitWords(t); + for (var s = 0, r = t.length; r > s; s++) this._on(t[s], e, i); + } + return this; + }, + off: function (t, e, i) { + if (t) + if ("object" == typeof t) for (var n in t) this._off(n, t[n], e); + else { + t = o.Util.splitWords(t); + for (var s = 0, r = t.length; r > s; s++) this._off(t[s], e, i); + } + else delete this._events; + return this; + }, + _on: function (t, e, i) { + var n = (this._events = this._events || {}), + s = i && i !== this && o.stamp(i); + if (s) { + var r = t + "_idx", + a = t + "_len", + h = (n[r] = n[r] || {}), + l = o.stamp(e) + "_" + s; + h[l] || ((h[l] = { fn: e, ctx: i }), (n[a] = (n[a] || 0) + 1)); + } else (n[t] = n[t] || []), n[t].push({ fn: e }); + }, + _off: function (t, e, i) { + var n = this._events, + s = t + "_idx", + r = t + "_len"; + if (n) { + if (!e) return delete n[t], delete n[s], void delete n[r]; + var a, + h, + l, + u, + c, + d = i && i !== this && o.stamp(i); + if (d) + (c = o.stamp(e) + "_" + d), + (a = n[s]), + a && a[c] && ((u = a[c]), delete a[c], n[r]--); + else if ((a = n[t])) + for (h = 0, l = a.length; l > h; h++) + if (a[h].fn === e) { + (u = a[h]), a.splice(h, 1); + break; + } + u && (u.fn = o.Util.falseFn); + } + }, + fire: function (t, e, i) { + if (!this.listens(t, i)) return this; + var n = o.Util.extend({}, e, { type: t, target: this }), + s = this._events; + if (s) { + var r, + a, + h, + l, + u = s[t + "_idx"]; + if (s[t]) for (h = s[t].slice(), r = 0, a = h.length; a > r; r++) h[r].fn.call(this, n); + for (l in u) u[l].fn.call(u[l].ctx, n); + } + return i && this._propagateEvent(n), this; + }, + listens: function (t, e) { + var i = this._events; + if (i && (i[t] || i[t + "_len"])) return !0; + if (e) for (var n in this._eventParents) if (this._eventParents[n].listens(t, e)) return !0; + return !1; + }, + once: function (t, e, i) { + if ("object" == typeof t) { + for (var n in t) this.once(n, t[n], e); + return this; + } + var s = o.bind(function () { + this.off(t, e, i).off(t, s, i); + }, this); + return this.on(t, e, i).on(t, s, i); + }, + addEventParent: function (t) { + return ( + (this._eventParents = this._eventParents || {}), + (this._eventParents[o.stamp(t)] = t), + this + ); + }, + removeEventParent: function (t) { + return this._eventParents && delete this._eventParents[o.stamp(t)], this; + }, + _propagateEvent: function (t) { + for (var e in this._eventParents) + this._eventParents[e].fire(t.type, o.extend({ layer: t.target }, t), !0); + }, + })); + var s = o.Evented.prototype; + (s.addEventListener = s.on), + (s.removeEventListener = s.clearAllEventListeners = s.off), + (s.addOneTimeEventListener = s.once), + (s.fireEvent = s.fire), + (s.hasEventListeners = s.listens), + (o.Mixin = { Events: s }), + (function () { + var i = navigator.userAgent.toLowerCase(), + n = e.documentElement, + s = "ActiveXObject" in t, + r = -1 !== i.indexOf("webkit"), + a = -1 !== i.indexOf("phantom"), + h = -1 !== i.search("android [23]"), + l = -1 !== i.indexOf("chrome"), + u = -1 !== i.indexOf("gecko") && !r && !t.opera && !s, + c = "undefined" != typeof orientation || -1 !== i.indexOf("mobile"), + d = !t.PointerEvent && t.MSPointerEvent, + _ = (t.PointerEvent && navigator.pointerEnabled) || d, + m = s && "transition" in n.style, + p = "WebKitCSSMatrix" in t && "m11" in new t.WebKitCSSMatrix() && !h, + f = "MozPerspective" in n.style, + g = "OTransition" in n.style, + v = + !t.L_NO_TOUCH && + !a && + (_ || "ontouchstart" in t || (t.DocumentTouch && e instanceof t.DocumentTouch)); + o.Browser = { + ie: s, + ielt9: s && !e.addEventListener, + webkit: r, + gecko: u, + android: -1 !== i.indexOf("android"), + android23: h, + chrome: l, + safari: !l && -1 !== i.indexOf("safari"), + ie3d: m, + webkit3d: p, + gecko3d: f, + opera12: g, + any3d: !t.L_DISABLE_3D && (m || p || f) && !g && !a, + mobile: c, + mobileWebkit: c && r, + mobileWebkit3d: c && p, + mobileOpera: c && t.opera, + mobileGecko: c && u, + touch: !!v, + msPointer: !!d, + pointer: !!_, + retina: (t.devicePixelRatio || t.screen.deviceXDPI / t.screen.logicalXDPI) > 1, + }; + })(), + (o.Point = function (t, e, i) { + (this.x = i ? Math.round(t) : t), (this.y = i ? Math.round(e) : e); + }), + (o.Point.prototype = { + clone: function () { + return new o.Point(this.x, this.y); + }, + add: function (t) { + return this.clone()._add(o.point(t)); + }, + _add: function (t) { + return (this.x += t.x), (this.y += t.y), this; + }, + subtract: function (t) { + return this.clone()._subtract(o.point(t)); + }, + _subtract: function (t) { + return (this.x -= t.x), (this.y -= t.y), this; + }, + divideBy: function (t) { + return this.clone()._divideBy(t); + }, + _divideBy: function (t) { + return (this.x /= t), (this.y /= t), this; + }, + multiplyBy: function (t) { + return this.clone()._multiplyBy(t); + }, + _multiplyBy: function (t) { + return (this.x *= t), (this.y *= t), this; + }, + scaleBy: function (t) { + return new o.Point(this.x * t.x, this.y * t.y); + }, + unscaleBy: function (t) { + return new o.Point(this.x / t.x, this.y / t.y); + }, + round: function () { + return this.clone()._round(); + }, + _round: function () { + return (this.x = Math.round(this.x)), (this.y = Math.round(this.y)), this; + }, + floor: function () { + return this.clone()._floor(); + }, + _floor: function () { + return (this.x = Math.floor(this.x)), (this.y = Math.floor(this.y)), this; + }, + ceil: function () { + return this.clone()._ceil(); + }, + _ceil: function () { + return (this.x = Math.ceil(this.x)), (this.y = Math.ceil(this.y)), this; + }, + distanceTo: function (t) { + t = o.point(t); + var e = t.x - this.x, + i = t.y - this.y; + return Math.sqrt(e * e + i * i); + }, + equals: function (t) { + return (t = o.point(t)), t.x === this.x && t.y === this.y; + }, + contains: function (t) { + return ( + (t = o.point(t)), Math.abs(t.x) <= Math.abs(this.x) && Math.abs(t.y) <= Math.abs(this.y) + ); + }, + toString: function () { + return "Point(" + o.Util.formatNum(this.x) + ", " + o.Util.formatNum(this.y) + ")"; + }, + }), + (o.point = function (t, e, n) { + return t instanceof o.Point + ? t + : o.Util.isArray(t) + ? new o.Point(t[0], t[1]) + : t === i || null === t + ? t + : new o.Point(t, e, n); + }), + (o.Bounds = function (t, e) { + if (t) for (var i = e ? [t, e] : t, n = 0, o = i.length; o > n; n++) this.extend(i[n]); + }), + (o.Bounds.prototype = { + extend: function (t) { + return ( + (t = o.point(t)), + this.min || this.max + ? ((this.min.x = Math.min(t.x, this.min.x)), + (this.max.x = Math.max(t.x, this.max.x)), + (this.min.y = Math.min(t.y, this.min.y)), + (this.max.y = Math.max(t.y, this.max.y))) + : ((this.min = t.clone()), (this.max = t.clone())), + this + ); + }, + getCenter: function (t) { + return new o.Point((this.min.x + this.max.x) / 2, (this.min.y + this.max.y) / 2, t); + }, + getBottomLeft: function () { + return new o.Point(this.min.x, this.max.y); + }, + getTopRight: function () { + return new o.Point(this.max.x, this.min.y); + }, + getSize: function () { + return this.max.subtract(this.min); + }, + contains: function (t) { + var e, i; + return ( + (t = "number" == typeof t[0] || t instanceof o.Point ? o.point(t) : o.bounds(t)), + t instanceof o.Bounds ? ((e = t.min), (i = t.max)) : (e = i = t), + e.x >= this.min.x && i.x <= this.max.x && e.y >= this.min.y && i.y <= this.max.y + ); + }, + intersects: function (t) { + t = o.bounds(t); + var e = this.min, + i = this.max, + n = t.min, + s = t.max, + r = s.x >= e.x && n.x <= i.x, + a = s.y >= e.y && n.y <= i.y; + return r && a; + }, + overlaps: function (t) { + t = o.bounds(t); + var e = this.min, + i = this.max, + n = t.min, + s = t.max, + r = s.x > e.x && n.x < i.x, + a = s.y > e.y && n.y < i.y; + return r && a; + }, + isValid: function () { + return !(!this.min || !this.max); + }, + }), + (o.bounds = function (t, e) { + return !t || t instanceof o.Bounds ? t : new o.Bounds(t, e); + }), + (o.Transformation = function (t, e, i, n) { + (this._a = t), (this._b = e), (this._c = i), (this._d = n); + }), + (o.Transformation.prototype = { + transform: function (t, e) { + return this._transform(t.clone(), e); + }, + _transform: function (t, e) { + return ( + (e = e || 1), + (t.x = e * (this._a * t.x + this._b)), + (t.y = e * (this._c * t.y + this._d)), + t + ); + }, + untransform: function (t, e) { + return ( + (e = e || 1), new o.Point((t.x / e - this._b) / this._a, (t.y / e - this._d) / this._c) + ); + }, + }), + (o.DomUtil = { + get: function (t) { + return "string" == typeof t ? e.getElementById(t) : t; + }, + getStyle: function (t, i) { + var n = t.style[i] || (t.currentStyle && t.currentStyle[i]); + if ((!n || "auto" === n) && e.defaultView) { + var o = e.defaultView.getComputedStyle(t, null); + n = o ? o[i] : null; + } + return "auto" === n ? null : n; + }, + create: function (t, i, n) { + var o = e.createElement(t); + return (o.className = i), n && n.appendChild(o), o; + }, + remove: function (t) { + var e = t.parentNode; + e && e.removeChild(t); + }, + empty: function (t) { + for (; t.firstChild; ) t.removeChild(t.firstChild); + }, + toFront: function (t) { + t.parentNode.appendChild(t); + }, + toBack: function (t) { + var e = t.parentNode; + e.insertBefore(t, e.firstChild); + }, + hasClass: function (t, e) { + if (t.classList !== i) return t.classList.contains(e); + var n = o.DomUtil.getClass(t); + return n.length > 0 && new RegExp("(^|\\s)" + e + "(\\s|$)").test(n); + }, + addClass: function (t, e) { + if (t.classList !== i) + for (var n = o.Util.splitWords(e), s = 0, r = n.length; r > s; s++) t.classList.add(n[s]); + else if (!o.DomUtil.hasClass(t, e)) { + var a = o.DomUtil.getClass(t); + o.DomUtil.setClass(t, (a ? a + " " : "") + e); + } + }, + removeClass: function (t, e) { + t.classList !== i + ? t.classList.remove(e) + : o.DomUtil.setClass( + t, + o.Util.trim((" " + o.DomUtil.getClass(t) + " ").replace(" " + e + " ", " ")) + ); + }, + setClass: function (t, e) { + t.className.baseVal === i ? (t.className = e) : (t.className.baseVal = e); + }, + getClass: function (t) { + return t.className.baseVal === i ? t.className : t.className.baseVal; + }, + setOpacity: function (t, e) { + "opacity" in t.style + ? (t.style.opacity = e) + : "filter" in t.style && o.DomUtil._setOpacityIE(t, e); + }, + _setOpacityIE: function (t, e) { + var i = !1, + n = "DXImageTransform.Microsoft.Alpha"; + try { + i = t.filters.item(n); + } catch (o) { + if (1 === e) return; + } + (e = Math.round(100 * e)), + i + ? ((i.Enabled = 100 !== e), (i.Opacity = e)) + : (t.style.filter += " progid:" + n + "(opacity=" + e + ")"); + }, + testProp: function (t) { + for (var i = e.documentElement.style, n = 0; n < t.length; n++) if (t[n] in i) return t[n]; + return !1; + }, + setTransform: function (t, e, i) { + var n = e || new o.Point(0, 0); + t.style[o.DomUtil.TRANSFORM] = + (o.Browser.ie3d + ? "translate(" + n.x + "px," + n.y + "px)" + : "translate3d(" + n.x + "px," + n.y + "px,0)") + (i ? " scale(" + i + ")" : ""); + }, + setPosition: function (t, e) { + (t._leaflet_pos = e), + o.Browser.any3d + ? o.DomUtil.setTransform(t, e) + : ((t.style.left = e.x + "px"), (t.style.top = e.y + "px")); + }, + getPosition: function (t) { + return t._leaflet_pos; + }, + }), + (function () { + o.DomUtil.TRANSFORM = o.DomUtil.testProp([ + "transform", + "WebkitTransform", + "OTransform", + "MozTransform", + "msTransform", + ]); + var i = (o.DomUtil.TRANSITION = o.DomUtil.testProp([ + "webkitTransition", + "transition", + "OTransition", + "MozTransition", + "msTransition", + ])); + if ( + ((o.DomUtil.TRANSITION_END = + "webkitTransition" === i || "OTransition" === i ? i + "End" : "transitionend"), + "onselectstart" in e) + ) + (o.DomUtil.disableTextSelection = function () { + o.DomEvent.on(t, "selectstart", o.DomEvent.preventDefault); + }), + (o.DomUtil.enableTextSelection = function () { + o.DomEvent.off(t, "selectstart", o.DomEvent.preventDefault); + }); + else { + var n = o.DomUtil.testProp([ + "userSelect", + "WebkitUserSelect", + "OUserSelect", + "MozUserSelect", + "msUserSelect", + ]); + (o.DomUtil.disableTextSelection = function () { + if (n) { + var t = e.documentElement.style; + (this._userSelect = t[n]), (t[n] = "none"); + } + }), + (o.DomUtil.enableTextSelection = function () { + n && ((e.documentElement.style[n] = this._userSelect), delete this._userSelect); + }); + } + (o.DomUtil.disableImageDrag = function () { + o.DomEvent.on(t, "dragstart", o.DomEvent.preventDefault); + }), + (o.DomUtil.enableImageDrag = function () { + o.DomEvent.off(t, "dragstart", o.DomEvent.preventDefault); + }), + (o.DomUtil.preventOutline = function (e) { + for (; -1 === e.tabIndex; ) e = e.parentNode; + e && + e.style && + (o.DomUtil.restoreOutline(), + (this._outlineElement = e), + (this._outlineStyle = e.style.outline), + (e.style.outline = "none"), + o.DomEvent.on(t, "keydown", o.DomUtil.restoreOutline, this)); + }), + (o.DomUtil.restoreOutline = function () { + this._outlineElement && + ((this._outlineElement.style.outline = this._outlineStyle), + delete this._outlineElement, + delete this._outlineStyle, + o.DomEvent.off(t, "keydown", o.DomUtil.restoreOutline, this)); + }); + })(), + (o.LatLng = function (t, e, n) { + if (isNaN(t) || isNaN(e)) throw new Error("Invalid LatLng object: (" + t + ", " + e + ")"); + (this.lat = +t), (this.lng = +e), n !== i && (this.alt = +n); + }), + (o.LatLng.prototype = { + equals: function (t, e) { + if (!t) return !1; + t = o.latLng(t); + var n = Math.max(Math.abs(this.lat - t.lat), Math.abs(this.lng - t.lng)); + return (e === i ? 1e-9 : e) >= n; + }, + toString: function (t) { + return "LatLng(" + o.Util.formatNum(this.lat, t) + ", " + o.Util.formatNum(this.lng, t) + ")"; + }, + distanceTo: function (t) { + return o.CRS.Earth.distance(this, o.latLng(t)); + }, + wrap: function () { + return o.CRS.Earth.wrapLatLng(this); + }, + toBounds: function (t) { + var e = (180 * t) / 40075017, + i = e / Math.cos((Math.PI / 180) * this.lat); + return o.latLngBounds([this.lat - e, this.lng - i], [this.lat + e, this.lng + i]); + }, + clone: function () { + return new o.LatLng(this.lat, this.lng, this.alt); + }, + }), + (o.latLng = function (t, e, n) { + return t instanceof o.LatLng + ? t + : o.Util.isArray(t) && "object" != typeof t[0] + ? 3 === t.length + ? new o.LatLng(t[0], t[1], t[2]) + : 2 === t.length + ? new o.LatLng(t[0], t[1]) + : null + : t === i || null === t + ? t + : "object" == typeof t && "lat" in t + ? new o.LatLng(t.lat, "lng" in t ? t.lng : t.lon, t.alt) + : e === i + ? null + : new o.LatLng(t, e, n); + }), + (o.LatLngBounds = function (t, e) { + if (t) for (var i = e ? [t, e] : t, n = 0, o = i.length; o > n; n++) this.extend(i[n]); + }), + (o.LatLngBounds.prototype = { + extend: function (t) { + var e, + i, + n = this._southWest, + s = this._northEast; + if (t instanceof o.LatLng) (e = t), (i = t); + else { + if (!(t instanceof o.LatLngBounds)) + return t ? this.extend(o.latLng(t) || o.latLngBounds(t)) : this; + if (((e = t._southWest), (i = t._northEast), !e || !i)) return this; + } + return ( + n || s + ? ((n.lat = Math.min(e.lat, n.lat)), + (n.lng = Math.min(e.lng, n.lng)), + (s.lat = Math.max(i.lat, s.lat)), + (s.lng = Math.max(i.lng, s.lng))) + : ((this._southWest = new o.LatLng(e.lat, e.lng)), + (this._northEast = new o.LatLng(i.lat, i.lng))), + this + ); + }, + pad: function (t) { + var e = this._southWest, + i = this._northEast, + n = Math.abs(e.lat - i.lat) * t, + s = Math.abs(e.lng - i.lng) * t; + return new o.LatLngBounds( + new o.LatLng(e.lat - n, e.lng - s), + new o.LatLng(i.lat + n, i.lng + s) + ); + }, + getCenter: function () { + return new o.LatLng( + (this._southWest.lat + this._northEast.lat) / 2, + (this._southWest.lng + this._northEast.lng) / 2 + ); + }, + getSouthWest: function () { + return this._southWest; + }, + getNorthEast: function () { + return this._northEast; + }, + getNorthWest: function () { + return new o.LatLng(this.getNorth(), this.getWest()); + }, + getSouthEast: function () { + return new o.LatLng(this.getSouth(), this.getEast()); + }, + getWest: function () { + return this._southWest.lng; + }, + getSouth: function () { + return this._southWest.lat; + }, + getEast: function () { + return this._northEast.lng; + }, + getNorth: function () { + return this._northEast.lat; + }, + contains: function (t) { + t = "number" == typeof t[0] || t instanceof o.LatLng ? o.latLng(t) : o.latLngBounds(t); + var e, + i, + n = this._southWest, + s = this._northEast; + return ( + t instanceof o.LatLngBounds + ? ((e = t.getSouthWest()), (i = t.getNorthEast())) + : (e = i = t), + e.lat >= n.lat && i.lat <= s.lat && e.lng >= n.lng && i.lng <= s.lng + ); + }, + intersects: function (t) { + t = o.latLngBounds(t); + var e = this._southWest, + i = this._northEast, + n = t.getSouthWest(), + s = t.getNorthEast(), + r = s.lat >= e.lat && n.lat <= i.lat, + a = s.lng >= e.lng && n.lng <= i.lng; + return r && a; + }, + overlaps: function (t) { + t = o.latLngBounds(t); + var e = this._southWest, + i = this._northEast, + n = t.getSouthWest(), + s = t.getNorthEast(), + r = s.lat > e.lat && n.lat < i.lat, + a = s.lng > e.lng && n.lng < i.lng; + return r && a; + }, + toBBoxString: function () { + return [this.getWest(), this.getSouth(), this.getEast(), this.getNorth()].join(","); + }, + equals: function (t) { + return t + ? ((t = o.latLngBounds(t)), + this._southWest.equals(t.getSouthWest()) && this._northEast.equals(t.getNorthEast())) + : !1; + }, + isValid: function () { + return !(!this._southWest || !this._northEast); + }, + }), + (o.latLngBounds = function (t, e) { + return !t || t instanceof o.LatLngBounds ? t : new o.LatLngBounds(t, e); + }), + (o.Projection = {}), + (o.Projection.LonLat = { + project: function (t) { + return new o.Point(t.lng, t.lat); + }, + unproject: function (t) { + return new o.LatLng(t.y, t.x); + }, + bounds: o.bounds([-180, -90], [180, 90]), + }), + (o.Projection.SphericalMercator = { + R: 6378137, + MAX_LATITUDE: 85.0511287798, + project: function (t) { + var e = Math.PI / 180, + i = this.MAX_LATITUDE, + n = Math.max(Math.min(i, t.lat), -i), + s = Math.sin(n * e); + return new o.Point(this.R * t.lng * e, (this.R * Math.log((1 + s) / (1 - s))) / 2); + }, + unproject: function (t) { + var e = 180 / Math.PI; + return new o.LatLng( + (2 * Math.atan(Math.exp(t.y / this.R)) - Math.PI / 2) * e, + (t.x * e) / this.R + ); + }, + bounds: (function () { + var t = 6378137 * Math.PI; + return o.bounds([-t, -t], [t, t]); + })(), + }), + (o.CRS = { + latLngToPoint: function (t, e) { + var i = this.projection.project(t), + n = this.scale(e); + return this.transformation._transform(i, n); + }, + pointToLatLng: function (t, e) { + var i = this.scale(e), + n = this.transformation.untransform(t, i); + return this.projection.unproject(n); + }, + project: function (t) { + return this.projection.project(t); + }, + unproject: function (t) { + return this.projection.unproject(t); + }, + scale: function (t) { + return 256 * Math.pow(2, t); + }, + zoom: function (t) { + return Math.log(t / 256) / Math.LN2; + }, + getProjectedBounds: function (t) { + if (this.infinite) return null; + var e = this.projection.bounds, + i = this.scale(t), + n = this.transformation.transform(e.min, i), + s = this.transformation.transform(e.max, i); + return o.bounds(n, s); + }, + wrapLatLng: function (t) { + var e = this.wrapLng ? o.Util.wrapNum(t.lng, this.wrapLng, !0) : t.lng, + i = this.wrapLat ? o.Util.wrapNum(t.lat, this.wrapLat, !0) : t.lat, + n = t.alt; + return o.latLng(i, e, n); + }, + }), + (o.CRS.Simple = o.extend({}, o.CRS, { + projection: o.Projection.LonLat, + transformation: new o.Transformation(1, 0, -1, 0), + scale: function (t) { + return Math.pow(2, t); + }, + zoom: function (t) { + return Math.log(t) / Math.LN2; + }, + distance: function (t, e) { + var i = e.lng - t.lng, + n = e.lat - t.lat; + return Math.sqrt(i * i + n * n); + }, + infinite: !0, + })), + (o.CRS.Earth = o.extend({}, o.CRS, { + wrapLng: [-180, 180], + R: 6378137, + distance: function (t, e) { + var i = Math.PI / 180, + n = t.lat * i, + o = e.lat * i, + s = Math.sin(n) * Math.sin(o) + Math.cos(n) * Math.cos(o) * Math.cos((e.lng - t.lng) * i); + return this.R * Math.acos(Math.min(s, 1)); + }, + })), + (o.CRS.EPSG3857 = o.extend({}, o.CRS.Earth, { + code: "EPSG:3857", + projection: o.Projection.SphericalMercator, + transformation: (function () { + var t = 0.5 / (Math.PI * o.Projection.SphericalMercator.R); + return new o.Transformation(t, 0.5, -t, 0.5); + })(), + })), + (o.CRS.EPSG900913 = o.extend({}, o.CRS.EPSG3857, { code: "EPSG:900913" })), + (o.CRS.EPSG4326 = o.extend({}, o.CRS.Earth, { + code: "EPSG:4326", + projection: o.Projection.LonLat, + transformation: new o.Transformation(1 / 180, 1, -1 / 180, 0.5), + })), + (o.Map = o.Evented.extend({ + options: { + crs: o.CRS.EPSG3857, + fadeAnimation: !0, + trackResize: !0, + markerZoomAnimation: !0, + maxBoundsViscosity: 0, + transform3DLimit: 8388608, + }, + initialize: function (t, e) { + (e = o.setOptions(this, e)), + this._initContainer(t), + this._initLayout(), + (this._onResize = o.bind(this._onResize, this)), + this._initEvents(), + e.maxBounds && this.setMaxBounds(e.maxBounds), + e.zoom !== i && (this._zoom = this._limitZoom(e.zoom)), + e.center && e.zoom !== i && this.setView(o.latLng(e.center), e.zoom, { reset: !0 }), + (this._handlers = []), + (this._layers = {}), + (this._zoomBoundLayers = {}), + (this._sizeChanged = !0), + this.callInitHooks(), + this._addLayers(this.options.layers); + }, + setView: function (t, e) { + return (e = e === i ? this.getZoom() : e), this._resetView(o.latLng(t), e), this; + }, + setZoom: function (t, e) { + return this._loaded + ? this.setView(this.getCenter(), t, { zoom: e }) + : ((this._zoom = t), this); + }, + zoomIn: function (t, e) { + return this.setZoom(this._zoom + (t || 1), e); + }, + zoomOut: function (t, e) { + return this.setZoom(this._zoom - (t || 1), e); + }, + setZoomAround: function (t, e, i) { + var n = this.getZoomScale(e), + s = this.getSize().divideBy(2), + r = t instanceof o.Point ? t : this.latLngToContainerPoint(t), + a = r.subtract(s).multiplyBy(1 - 1 / n), + h = this.containerPointToLatLng(s.add(a)); + return this.setView(h, e, { zoom: i }); + }, + _getBoundsCenterZoom: function (t, e) { + (e = e || {}), (t = t.getBounds ? t.getBounds() : o.latLngBounds(t)); + var i = o.point(e.paddingTopLeft || e.padding || [0, 0]), + n = o.point(e.paddingBottomRight || e.padding || [0, 0]), + s = this.getBoundsZoom(t, !1, i.add(n)); + s = e.maxZoom ? Math.min(e.maxZoom, s) : s; + var r = n.subtract(i).divideBy(2), + a = this.project(t.getSouthWest(), s), + h = this.project(t.getNorthEast(), s), + l = this.unproject(a.add(h).divideBy(2).add(r), s); + return { center: l, zoom: s }; + }, + fitBounds: function (t, e) { + var i = this._getBoundsCenterZoom(t, e); + return this.setView(i.center, i.zoom, e); + }, + fitWorld: function (t) { + return this.fitBounds( + [ + [-90, -180], + [90, 180], + ], + t + ); + }, + panTo: function (t, e) { + return this.setView(t, this._zoom, { pan: e }); + }, + panBy: function (t) { + return ( + this.fire("movestart"), + this._rawPanBy(o.point(t)), + this.fire("move"), + this.fire("moveend") + ); + }, + setMaxBounds: function (t) { + return (t = o.latLngBounds(t)) + ? (this.options.maxBounds && this.off("moveend", this._panInsideMaxBounds), + (this.options.maxBounds = t), + this._loaded && this._panInsideMaxBounds(), + this.on("moveend", this._panInsideMaxBounds)) + : this.off("moveend", this._panInsideMaxBounds); + }, + setMinZoom: function (t) { + return ( + (this.options.minZoom = t), + this._loaded && this.getZoom() < this.options.minZoom ? this.setZoom(t) : this + ); + }, + setMaxZoom: function (t) { + return ( + (this.options.maxZoom = t), + this._loaded && this.getZoom() > this.options.maxZoom ? this.setZoom(t) : this + ); + }, + panInsideBounds: function (t, e) { + this._enforcingBounds = !0; + var i = this.getCenter(), + n = this._limitCenter(i, this._zoom, o.latLngBounds(t)); + return i.equals(n) ? this : (this.panTo(n, e), (this._enforcingBounds = !1), this); + }, + invalidateSize: function (t) { + if (!this._loaded) return this; + t = o.extend({ animate: !1, pan: !0 }, t === !0 ? { animate: !0 } : t); + var e = this.getSize(); + (this._sizeChanged = !0), (this._lastCenter = null); + var i = this.getSize(), + n = e.divideBy(2).round(), + s = i.divideBy(2).round(), + r = n.subtract(s); + return r.x || r.y + ? (t.animate && t.pan + ? this.panBy(r) + : (t.pan && this._rawPanBy(r), + this.fire("move"), + t.debounceMoveend + ? (clearTimeout(this._sizeTimer), + (this._sizeTimer = setTimeout(o.bind(this.fire, this, "moveend"), 200))) + : this.fire("moveend")), + this.fire("resize", { oldSize: e, newSize: i })) + : this; + }, + stop: function () { + return o.Util.cancelAnimFrame(this._flyToFrame), this._panAnim && this._panAnim.stop(), this; + }, + addHandler: function (t, e) { + if (!e) return this; + var i = (this[t] = new e(this)); + return this._handlers.push(i), this.options[t] && i.enable(), this; + }, + remove: function () { + this._initEvents(!0); + try { + delete this._container._leaflet; + } catch (t) { + this._container._leaflet = i; + } + o.DomUtil.remove(this._mapPane), + this._clearControlPos && this._clearControlPos(), + this._clearHandlers(), + this._loaded && this.fire("unload"); + for (var e in this._layers) this._layers[e].remove(); + return this; + }, + createPane: function (t, e) { + var i = "leaflet-pane" + (t ? " leaflet-" + t.replace("Pane", "") + "-pane" : ""), + n = o.DomUtil.create("div", i, e || this._mapPane); + return t && (this._panes[t] = n), n; + }, + getCenter: function () { + return ( + this._checkIfLoaded(), + this._lastCenter && !this._moved() + ? this._lastCenter + : this.layerPointToLatLng(this._getCenterLayerPoint()) + ); + }, + getZoom: function () { + return this._zoom; + }, + getBounds: function () { + var t = this.getPixelBounds(), + e = this.unproject(t.getBottomLeft()), + i = this.unproject(t.getTopRight()); + return new o.LatLngBounds(e, i); + }, + getMinZoom: function () { + return this.options.minZoom === i ? this._layersMinZoom || 0 : this.options.minZoom; + }, + getMaxZoom: function () { + return this.options.maxZoom === i + ? this._layersMaxZoom === i + ? 1 / 0 + : this._layersMaxZoom + : this.options.maxZoom; + }, + getBoundsZoom: function (t, e, i) { + t = o.latLngBounds(t); + var n, + s = this.getMinZoom() - (e ? 1 : 0), + r = this.getMaxZoom(), + a = this.getSize(), + h = t.getNorthWest(), + l = t.getSouthEast(), + u = !0; + i = o.point(i || [0, 0]); + do + s++, + (n = this.project(l, s).subtract(this.project(h, s)).add(i).floor()), + (u = e ? n.x < a.x || n.y < a.y : a.contains(n)); + while (u && r >= s); + return u && e ? null : e ? s : s - 1; + }, + getSize: function () { + return ( + (!this._size || this._sizeChanged) && + ((this._size = new o.Point( + this._container.clientWidth, + this._container.clientHeight + )), + (this._sizeChanged = !1)), + this._size.clone() + ); + }, + getPixelBounds: function (t, e) { + var i = this._getTopLeftPoint(t, e); + return new o.Bounds(i, i.add(this.getSize())); + }, + getPixelOrigin: function () { + return this._checkIfLoaded(), this._pixelOrigin; + }, + getPixelWorldBounds: function (t) { + return this.options.crs.getProjectedBounds(t === i ? this.getZoom() : t); + }, + getPane: function (t) { + return "string" == typeof t ? this._panes[t] : t; + }, + getPanes: function () { + return this._panes; + }, + getContainer: function () { + return this._container; + }, + getZoomScale: function (t, e) { + var n = this.options.crs; + return (e = e === i ? this._zoom : e), n.scale(t) / n.scale(e); + }, + getScaleZoom: function (t, e) { + var n = this.options.crs; + return (e = e === i ? this._zoom : e), n.zoom(t * n.scale(e)); + }, + project: function (t, e) { + return (e = e === i ? this._zoom : e), this.options.crs.latLngToPoint(o.latLng(t), e); + }, + unproject: function (t, e) { + return (e = e === i ? this._zoom : e), this.options.crs.pointToLatLng(o.point(t), e); + }, + layerPointToLatLng: function (t) { + var e = o.point(t).add(this.getPixelOrigin()); + return this.unproject(e); + }, + latLngToLayerPoint: function (t) { + var e = this.project(o.latLng(t))._round(); + return e._subtract(this.getPixelOrigin()); + }, + wrapLatLng: function (t) { + return this.options.crs.wrapLatLng(o.latLng(t)); + }, + distance: function (t, e) { + return this.options.crs.distance(o.latLng(t), o.latLng(e)); + }, + containerPointToLayerPoint: function (t) { + return o.point(t).subtract(this._getMapPanePos()); + }, + layerPointToContainerPoint: function (t) { + return o.point(t).add(this._getMapPanePos()); + }, + containerPointToLatLng: function (t) { + var e = this.containerPointToLayerPoint(o.point(t)); + return this.layerPointToLatLng(e); + }, + latLngToContainerPoint: function (t) { + return this.layerPointToContainerPoint(this.latLngToLayerPoint(o.latLng(t))); + }, + mouseEventToContainerPoint: function (t) { + return o.DomEvent.getMousePosition(t, this._container); + }, + mouseEventToLayerPoint: function (t) { + return this.containerPointToLayerPoint(this.mouseEventToContainerPoint(t)); + }, + mouseEventToLatLng: function (t) { + return this.layerPointToLatLng(this.mouseEventToLayerPoint(t)); + }, + _initContainer: function (t) { + var e = (this._container = o.DomUtil.get(t)); + if (!e) throw new Error("Map container not found."); + if (e._leaflet) throw new Error("Map container is already initialized."); + o.DomEvent.addListener(e, "scroll", this._onScroll, this), (e._leaflet = !0); + }, + _initLayout: function () { + var t = this._container; + (this._fadeAnimated = this.options.fadeAnimation && o.Browser.any3d), + o.DomUtil.addClass( + t, + "leaflet-container" + + (o.Browser.touch ? " leaflet-touch" : "") + + (o.Browser.retina ? " leaflet-retina" : "") + + (o.Browser.ielt9 ? " leaflet-oldie" : "") + + (o.Browser.safari ? " leaflet-safari" : "") + + (this._fadeAnimated ? " leaflet-fade-anim" : "") + ); + var e = o.DomUtil.getStyle(t, "position"); + "absolute" !== e && "relative" !== e && "fixed" !== e && (t.style.position = "relative"), + this._initPanes(), + this._initControlPos && this._initControlPos(); + }, + _initPanes: function () { + var t = (this._panes = {}); + (this._paneRenderers = {}), + (this._mapPane = this.createPane("mapPane", this._container)), + o.DomUtil.setPosition(this._mapPane, new o.Point(0, 0)), + this.createPane("tilePane"), + this.createPane("shadowPane"), + this.createPane("overlayPane"), + this.createPane("markerPane"), + this.createPane("popupPane"), + this.options.markerZoomAnimation || + (o.DomUtil.addClass(t.markerPane, "leaflet-zoom-hide"), + o.DomUtil.addClass(t.shadowPane, "leaflet-zoom-hide")); + }, + _resetView: function (t, e) { + o.DomUtil.setPosition(this._mapPane, new o.Point(0, 0)); + var i = !this._loaded; + (this._loaded = !0), (e = this._limitZoom(e)); + var n = this._zoom !== e; + this._moveStart(n)._move(t, e)._moveEnd(n), this.fire("viewreset"), i && this.fire("load"); + }, + _moveStart: function (t) { + return t && this.fire("zoomstart"), this.fire("movestart"); + }, + _move: function (t, e, n) { + e === i && (e = this._zoom); + var o = this._zoom !== e; + return ( + (this._zoom = e), + (this._lastCenter = t), + (this._pixelOrigin = this._getNewPixelOrigin(t)), + o && this.fire("zoom", n), + this.fire("move", n) + ); + }, + _moveEnd: function (t) { + return t && this.fire("zoomend"), this.fire("moveend"); + }, + _rawPanBy: function (t) { + o.DomUtil.setPosition(this._mapPane, this._getMapPanePos().subtract(t)); + }, + _getZoomSpan: function () { + return this.getMaxZoom() - this.getMinZoom(); + }, + _panInsideMaxBounds: function () { + this._enforcingBounds || this.panInsideBounds(this.options.maxBounds); + }, + _checkIfLoaded: function () { + if (!this._loaded) throw new Error("Set map center and zoom first."); + }, + _initEvents: function (e) { + if (o.DomEvent) { + (this._targets = {}), (this._targets[o.stamp(this._container)] = this); + var i = e ? "off" : "on"; + o.DomEvent[i]( + this._container, + "click dblclick mousedown mouseup mouseover mouseout mousemove contextmenu keypress", + this._handleDOMEvent, + this + ), + this.options.trackResize && o.DomEvent[i](t, "resize", this._onResize, this), + o.Browser.any3d && + this.options.transform3DLimit && + this[i]("moveend", this._onMoveEnd); + } + }, + _onResize: function () { + o.Util.cancelAnimFrame(this._resizeRequest), + (this._resizeRequest = o.Util.requestAnimFrame(function () { + this.invalidateSize({ debounceMoveend: !0 }); + }, this)); + }, + _onScroll: function () { + (this._container.scrollTop = 0), (this._container.scrollLeft = 0); + }, + _onMoveEnd: function () { + var t = this._getMapPanePos(); + Math.max(Math.abs(t.x), Math.abs(t.y)) >= this.options.transform3DLimit && + this._resetView(this.getCenter(), this.getZoom()); + }, + _findEventTargets: function (t, e) { + for ( + var i, n = [], s = "mouseout" === e || "mouseover" === e, r = t.target || t.srcElement; + r; - function s() { if (h && !a.cancelBubble) { if (o.Browser.pointer) { var t, i, n = {}; for (i in a) t = a[i], n[i] = t && t.bind ? t.bind(a) : t; - a = n } - a.type = "dblclick", e(a), r = null } } var r, a, h = !1, - l = 250, - u = "_leaflet_", - c = this._touchstart, - d = this._touchend; return t[u + c + i] = n, t[u + d + i] = s, t.addEventListener(c, n, !1), t.addEventListener(d, s, !1), this }, removeDoubleTapListener: function(t, e) { var i = "_leaflet_", - n = t[i + this._touchend + e]; return t.removeEventListener(this._touchstart, t[i + this._touchstart + e], !1), t.removeEventListener(this._touchend, n, !1), this } }), o.extend(o.DomEvent, { POINTER_DOWN: o.Browser.msPointer ? "MSPointerDown" : "pointerdown", POINTER_MOVE: o.Browser.msPointer ? "MSPointerMove" : "pointermove", POINTER_UP: o.Browser.msPointer ? "MSPointerUp" : "pointerup", POINTER_CANCEL: o.Browser.msPointer ? "MSPointerCancel" : "pointercancel", _pointers: {}, _pointersCount: 0, addPointerListener: function(t, e, i, n) { return "touchstart" === e ? this._addPointerStart(t, i, n) : "touchmove" === e ? this._addPointerMove(t, i, n) : "touchend" === e && this._addPointerEnd(t, i, n), this }, removePointerListener: function(t, e, i) { var n = t["_leaflet_" + e + i]; return "touchstart" === e ? t.removeEventListener(this.POINTER_DOWN, n, !1) : "touchmove" === e ? t.removeEventListener(this.POINTER_MOVE, n, !1) : "touchend" === e && (t.removeEventListener(this.POINTER_UP, n, !1), t.removeEventListener(this.POINTER_CANCEL, n, !1)), this }, _addPointerStart: function(t, i, n) { var s = o.bind(function(t) { "mouse" !== t.pointerType && t.pointerType !== t.MSPOINTER_TYPE_MOUSE && o.DomEvent.preventDefault(t), this._handlePointer(t, i) }, this); if (t["_leaflet_touchstart" + n] = s, t.addEventListener(this.POINTER_DOWN, s, !1), !this._pointerDocListener) { var r = o.bind(this._globalPointerUp, this); - e.documentElement.addEventListener(this.POINTER_DOWN, o.bind(this._globalPointerDown, this), !0), e.documentElement.addEventListener(this.POINTER_MOVE, o.bind(this._globalPointerMove, this), !0), e.documentElement.addEventListener(this.POINTER_UP, r, !0), e.documentElement.addEventListener(this.POINTER_CANCEL, r, !0), this._pointerDocListener = !0 } }, _globalPointerDown: function(t) { this._pointers[t.pointerId] = t, this._pointersCount++ }, _globalPointerMove: function(t) { this._pointers[t.pointerId] && (this._pointers[t.pointerId] = t) }, _globalPointerUp: function(t) { delete this._pointers[t.pointerId], this._pointersCount-- }, _handlePointer: function(t, e) { t.touches = []; for (var i in this._pointers) t.touches.push(this._pointers[i]); - t.changedTouches = [t], e(t) }, _addPointerMove: function(t, e, i) { var n = o.bind(function(t) { - (t.pointerType !== t.MSPOINTER_TYPE_MOUSE && "mouse" !== t.pointerType || 0 !== t.buttons) && this._handlePointer(t, e) }, this); - t["_leaflet_touchmove" + i] = n, t.addEventListener(this.POINTER_MOVE, n, !1) }, _addPointerEnd: function(t, e, i) { var n = o.bind(function(t) { this._handlePointer(t, e) }, this); - t["_leaflet_touchend" + i] = n, t.addEventListener(this.POINTER_UP, n, !1), t.addEventListener(this.POINTER_CANCEL, n, !1) } }), o.Map.mergeOptions({ touchZoom: o.Browser.touch && !o.Browser.android23, bounceAtZoomLimits: !0 }), o.Map.TouchZoom = o.Handler.extend({ addHooks: function() { o.DomEvent.on(this._map._container, "touchstart", this._onTouchStart, this) }, removeHooks: function() { o.DomEvent.off(this._map._container, "touchstart", this._onTouchStart, this) }, _onTouchStart: function(t) { var i = this._map; if (t.touches && 2 === t.touches.length && !i._animatingZoom && !this._zooming) { var n = i.mouseEventToContainerPoint(t.touches[0]), - s = i.mouseEventToContainerPoint(t.touches[1]); - this._centerPoint = i.getSize()._divideBy(2), this._startLatLng = i.containerPointToLatLng(this._centerPoint), "center" !== i.options.touchZoom && (this._pinchStartLatLng = i.containerPointToLatLng(n.add(s)._divideBy(2))), this._startDist = n.distanceTo(s), this._startZoom = i.getZoom(), this._moved = !1, this._zooming = !0, i.stop(), o.DomEvent.on(e, "touchmove", this._onTouchMove, this).on(e, "touchend", this._onTouchEnd, this), o.DomEvent.preventDefault(t) } }, _onTouchMove: function(t) { if (t.touches && 2 === t.touches.length && this._zooming) { var e = this._map, - i = e.mouseEventToContainerPoint(t.touches[0]), - n = e.mouseEventToContainerPoint(t.touches[1]), - s = i.distanceTo(n) / this._startDist; if (this._zoom = e.getScaleZoom(s, this._startZoom), "center" === e.options.touchZoom) { if (this._center = this._startLatLng, 1 === s) return } else { var r = i._add(n)._divideBy(2)._subtract(this._centerPoint); if (1 === s && 0 === r.x && 0 === r.y) return; - this._center = e.unproject(e.project(this._pinchStartLatLng).subtract(r)) } if (e.options.bounceAtZoomLimits || !(this._zoom <= e.getMinZoom() && 1 > s || this._zoom >= e.getMaxZoom() && s > 1)) { this._moved || (e._moveStart(!0), this._moved = !0), o.Util.cancelAnimFrame(this._animRequest); var a = o.bind(e._move, e, this._center, this._zoom, { pinch: !0, round: !1 }); - this._animRequest = o.Util.requestAnimFrame(a, this, !0), o.DomEvent.preventDefault(t) } } }, _onTouchEnd: function() { if (!this._moved || !this._zooming) return void(this._zooming = !1); - this._zooming = !1, o.Util.cancelAnimFrame(this._animRequest), o.DomEvent.off(e, "touchmove", this._onTouchMove).off(e, "touchend", this._onTouchEnd); var t = this._zoom; - t = this._map._limitZoom(t - this._startZoom > 0 ? Math.ceil(t) : Math.floor(t)), this._map._animateZoom(this._center, t, !0, !0) } }), o.Map.addInitHook("addHandler", "touchZoom", o.Map.TouchZoom), o.Map.mergeOptions({ tap: !0, tapTolerance: 15 }), o.Map.Tap = o.Handler.extend({ addHooks: function() { o.DomEvent.on(this._map._container, "touchstart", this._onDown, this) }, removeHooks: function() { o.DomEvent.off(this._map._container, "touchstart", this._onDown, this) }, _onDown: function(t) { if (t.touches) { if (o.DomEvent.preventDefault(t), this._fireClick = !0, t.touches.length > 1) return this._fireClick = !1, void clearTimeout(this._holdTimeout); var i = t.touches[0], - n = i.target; - this._startPos = this._newPos = new o.Point(i.clientX, i.clientY), n.tagName && "a" === n.tagName.toLowerCase() && o.DomUtil.addClass(n, "leaflet-active"), this._holdTimeout = setTimeout(o.bind(function() { this._isTapValid() && (this._fireClick = !1, this._onUp(), this._simulateEvent("contextmenu", i)) }, this), 1e3), this._simulateEvent("mousedown", i), o.DomEvent.on(e, { touchmove: this._onMove, touchend: this._onUp }, this) } }, _onUp: function(t) { if (clearTimeout(this._holdTimeout), o.DomEvent.off(e, { touchmove: this._onMove, touchend: this._onUp }, this), this._fireClick && t && t.changedTouches) { var i = t.changedTouches[0], - n = i.target; - n && n.tagName && "a" === n.tagName.toLowerCase() && o.DomUtil.removeClass(n, "leaflet-active"), this._simulateEvent("mouseup", i), this._isTapValid() && this._simulateEvent("click", i) } }, _isTapValid: function() { return this._newPos.distanceTo(this._startPos) <= this._map.options.tapTolerance }, _onMove: function(t) { var e = t.touches[0]; - this._newPos = new o.Point(e.clientX, e.clientY), this._simulateEvent("mousemove", e) }, _simulateEvent: function(i, n) { var o = e.createEvent("MouseEvents"); - o._simulated = !0, n.target._simulatedClick = !0, o.initMouseEvent(i, !0, !0, t, 1, n.screenX, n.screenY, n.clientX, n.clientY, !1, !1, !1, !1, 0, null), n.target.dispatchEvent(o) } }), o.Browser.touch && !o.Browser.pointer && o.Map.addInitHook("addHandler", "tap", o.Map.Tap), o.Map.mergeOptions({ boxZoom: !0 }), o.Map.BoxZoom = o.Handler.extend({ initialize: function(t) { this._map = t, this._container = t._container, this._pane = t._panes.overlayPane }, addHooks: function() { o.DomEvent.on(this._container, "mousedown", this._onMouseDown, this) }, removeHooks: function() { o.DomEvent.off(this._container, "mousedown", this._onMouseDown, this) }, moved: function() { return this._moved }, _resetState: function() { this._moved = !1 }, _onMouseDown: function(t) { return !t.shiftKey || 1 !== t.which && 1 !== t.button ? !1 : (this._resetState(), o.DomUtil.disableTextSelection(), o.DomUtil.disableImageDrag(), this._startPoint = this._map.mouseEventToContainerPoint(t), void o.DomEvent.on(e, { contextmenu: o.DomEvent.stop, mousemove: this._onMouseMove, mouseup: this._onMouseUp, keydown: this._onKeyDown }, this)) }, _onMouseMove: function(t) { this._moved || (this._moved = !0, this._box = o.DomUtil.create("div", "leaflet-zoom-box", this._container), o.DomUtil.addClass(this._container, "leaflet-crosshair"), this._map.fire("boxzoomstart")), this._point = this._map.mouseEventToContainerPoint(t); var e = new o.Bounds(this._point, this._startPoint), - i = e.getSize(); - o.DomUtil.setPosition(this._box, e.min), this._box.style.width = i.x + "px", this._box.style.height = i.y + "px" }, _finish: function() { this._moved && (o.DomUtil.remove(this._box), o.DomUtil.removeClass(this._container, "leaflet-crosshair")), o.DomUtil.enableTextSelection(), o.DomUtil.enableImageDrag(), o.DomEvent.off(e, { contextmenu: o.DomEvent.stop, mousemove: this._onMouseMove, mouseup: this._onMouseUp, keydown: this._onKeyDown }, this) }, _onMouseUp: function(t) { if ((1 === t.which || 1 === t.button) && (this._finish(), this._moved)) { setTimeout(o.bind(this._resetState, this), 0); var e = new o.LatLngBounds(this._map.containerPointToLatLng(this._startPoint), this._map.containerPointToLatLng(this._point)); - this._map.fitBounds(e).fire("boxzoomend", { boxZoomBounds: e }) } }, _onKeyDown: function(t) { 27 === t.keyCode && this._finish() } }), o.Map.addInitHook("addHandler", "boxZoom", o.Map.BoxZoom), o.Map.mergeOptions({ keyboard: !0, keyboardPanOffset: 80, keyboardZoomOffset: 1 }), o.Map.Keyboard = o.Handler.extend({ keyCodes: { left: [37], right: [39], down: [40], up: [38], zoomIn: [187, 107, 61, 171], zoomOut: [189, 109, 54, 173] }, initialize: function(t) { this._map = t, this._setPanOffset(t.options.keyboardPanOffset), this._setZoomOffset(t.options.keyboardZoomOffset) }, addHooks: function() { var t = this._map._container; - t.tabIndex <= 0 && (t.tabIndex = "0"), o.DomEvent.on(t, { focus: this._onFocus, blur: this._onBlur, mousedown: this._onMouseDown }, this), this._map.on({ focus: this._addHooks, blur: this._removeHooks }, this) }, removeHooks: function() { this._removeHooks(), o.DomEvent.off(this._map._container, { focus: this._onFocus, blur: this._onBlur, mousedown: this._onMouseDown }, this), this._map.off({ focus: this._addHooks, blur: this._removeHooks }, this) }, _onMouseDown: function() { if (!this._focused) { var i = e.body, - n = e.documentElement, - o = i.scrollTop || n.scrollTop, - s = i.scrollLeft || n.scrollLeft; - this._map._container.focus(), t.scrollTo(s, o) } }, _onFocus: function() { this._focused = !0, this._map.fire("focus") }, _onBlur: function() { this._focused = !1, this._map.fire("blur") }, _setPanOffset: function(t) { var e, i, n = this._panKeys = {}, - o = this.keyCodes; for (e = 0, i = o.left.length; i > e; e++) n[o.left[e]] = [-1 * t, 0]; for (e = 0, i = o.right.length; i > e; e++) n[o.right[e]] = [t, 0]; for (e = 0, i = o.down.length; i > e; e++) n[o.down[e]] = [0, t]; for (e = 0, i = o.up.length; i > e; e++) n[o.up[e]] = [0, -1 * t] }, _setZoomOffset: function(t) { var e, i, n = this._zoomKeys = {}, - o = this.keyCodes; for (e = 0, i = o.zoomIn.length; i > e; e++) n[o.zoomIn[e]] = t; for (e = 0, i = o.zoomOut.length; i > e; e++) n[o.zoomOut[e]] = -t }, _addHooks: function() { o.DomEvent.on(e, "keydown", this._onKeyDown, this) }, _removeHooks: function() { o.DomEvent.off(e, "keydown", this._onKeyDown, this) }, _onKeyDown: function(t) { if (!(t.altKey || t.ctrlKey || t.metaKey)) { var e, i = t.keyCode, - n = this._map; if (i in this._panKeys) { if (n._panAnim && n._panAnim._inProgress) return; - e = this._panKeys[i], t.shiftKey && (e = o.point(e).multiplyBy(3)), n.panBy(e), n.options.maxBounds && n.panInsideBounds(n.options.maxBounds) } else if (i in this._zoomKeys) n.setZoom(n.getZoom() + (t.shiftKey ? 3 : 1) * this._zoomKeys[i]); - else { if (27 !== i) return; - n.closePopup() } - o.DomEvent.stop(t) } } }), o.Map.addInitHook("addHandler", "keyboard", o.Map.Keyboard), o.Handler.MarkerDrag = o.Handler.extend({ initialize: function(t) { this._marker = t }, addHooks: function() { var t = this._marker._icon; - this._draggable || (this._draggable = new o.Draggable(t, t, !0)), this._draggable.on({ dragstart: this._onDragStart, drag: this._onDrag, dragend: this._onDragEnd }, this).enable(), o.DomUtil.addClass(t, "leaflet-marker-draggable") }, removeHooks: function() { this._draggable.off({ dragstart: this._onDragStart, drag: this._onDrag, dragend: this._onDragEnd }, this).disable(), this._marker._icon && o.DomUtil.removeClass(this._marker._icon, "leaflet-marker-draggable") }, moved: function() { return this._draggable && this._draggable._moved }, _onDragStart: function() { this._marker.closePopup().fire("movestart").fire("dragstart") }, _onDrag: function(t) { var e = this._marker, - i = e._shadow, - n = o.DomUtil.getPosition(e._icon), - s = e._map.layerPointToLatLng(n); - i && o.DomUtil.setPosition(i, n), e._latlng = s, t.latlng = s, e.fire("move", t).fire("drag", t) }, _onDragEnd: function(t) { this._marker.fire("moveend").fire("dragend", t) } }), o.Control = o.Class.extend({ options: { position: "topright" }, initialize: function(t) { o.setOptions(this, t) }, getPosition: function() { return this.options.position }, setPosition: function(t) { var e = this._map; return e && e.removeControl(this), this.options.position = t, e && e.addControl(this), this }, getContainer: function() { return this._container }, addTo: function(t) { this.remove(), this._map = t; var e = this._container = this.onAdd(t), - i = this.getPosition(), - n = t._controlCorners[i]; return o.DomUtil.addClass(e, "leaflet-control"), -1 !== i.indexOf("bottom") ? n.insertBefore(e, n.firstChild) : n.appendChild(e), this }, remove: function() { return this._map ? (o.DomUtil.remove(this._container), this.onRemove && this.onRemove(this._map), this._map = null, this) : this }, _refocusOnMap: function(t) { this._map && t && t.screenX > 0 && t.screenY > 0 && this._map.getContainer().focus() } }), o.control = function(t) { return new o.Control(t) }, o.Map.include({ addControl: function(t) { return t.addTo(this), this }, removeControl: function(t) { return t.remove(), this }, _initControlPos: function() { - function t(t, s) { var r = i + t + " " + i + s; - e[t + s] = o.DomUtil.create("div", r, n) } var e = this._controlCorners = {}, - i = "leaflet-", - n = this._controlContainer = o.DomUtil.create("div", i + "control-container", this._container); - t("top", "left"), t("top", "right"), t("bottom", "left"), t("bottom", "right") }, _clearControlPos: function() { o.DomUtil.remove(this._controlContainer) } }), o.Control.Zoom = o.Control.extend({ options: { position: "topleft", zoomInText: "+", zoomInTitle: "Zoom in", zoomOutText: "-", zoomOutTitle: "Zoom out" }, onAdd: function(t) { var e = "leaflet-control-zoom", - i = o.DomUtil.create("div", e + " leaflet-bar"), - n = this.options; return this._zoomInButton = this._createButton(n.zoomInText, n.zoomInTitle, e + "-in", i, this._zoomIn), this._zoomOutButton = this._createButton(n.zoomOutText, n.zoomOutTitle, e + "-out", i, this._zoomOut), this._updateDisabled(), t.on("zoomend zoomlevelschange", this._updateDisabled, this), i }, onRemove: function(t) { t.off("zoomend zoomlevelschange", this._updateDisabled, this) }, disable: function() { return this._disabled = !0, this._updateDisabled(), this }, enable: function() { return this._disabled = !1, this._updateDisabled(), this }, _zoomIn: function(t) { this._disabled || this._map.zoomIn(t.shiftKey ? 3 : 1) }, _zoomOut: function(t) { this._disabled || this._map.zoomOut(t.shiftKey ? 3 : 1) }, _createButton: function(t, e, i, n, s) { var r = o.DomUtil.create("a", i, n); return r.innerHTML = t, r.href = "#", r.title = e, o.DomEvent.on(r, "mousedown dblclick", o.DomEvent.stopPropagation).on(r, "click", o.DomEvent.stop).on(r, "click", s, this).on(r, "click", this._refocusOnMap, this), r }, _updateDisabled: function() { var t = this._map, - e = "leaflet-disabled"; - o.DomUtil.removeClass(this._zoomInButton, e), o.DomUtil.removeClass(this._zoomOutButton, e), (this._disabled || t._zoom === t.getMinZoom()) && o.DomUtil.addClass(this._zoomOutButton, e), (this._disabled || t._zoom === t.getMaxZoom()) && o.DomUtil.addClass(this._zoomInButton, e) } }), o.Map.mergeOptions({ zoomControl: !0 }), o.Map.addInitHook(function() { this.options.zoomControl && (this.zoomControl = new o.Control.Zoom, this.addControl(this.zoomControl)) }), o.control.zoom = function(t) { return new o.Control.Zoom(t) }, o.Control.Attribution = o.Control.extend({ options: { position: "bottomright", prefix: 'Leaflet' }, initialize: function(t) { o.setOptions(this, t), this._attributions = {} }, onAdd: function(t) { this._container = o.DomUtil.create("div", "leaflet-control-attribution"), o.DomEvent && o.DomEvent.disableClickPropagation(this._container); for (var e in t._layers) t._layers[e].getAttribution && this.addAttribution(t._layers[e].getAttribution()); return this._update(), this._container }, setPrefix: function(t) { return this.options.prefix = t, this._update(), this }, addAttribution: function(t) { return t ? (this._attributions[t] || (this._attributions[t] = 0), this._attributions[t]++, this._update(), this) : this }, removeAttribution: function(t) { return t ? (this._attributions[t] && (this._attributions[t]--, this._update()), this) : this }, _update: function() { if (this._map) { var t = []; for (var e in this._attributions) this._attributions[e] && t.push(e); var i = []; - this.options.prefix && i.push(this.options.prefix), t.length && i.push(t.join(", ")), this._container.innerHTML = i.join(" | ") } } }), o.Map.mergeOptions({ attributionControl: !0 }), o.Map.addInitHook(function() { this.options.attributionControl && (this.attributionControl = (new o.Control.Attribution).addTo(this)) }), o.control.attribution = function(t) { return new o.Control.Attribution(t) }, o.Control.Scale = o.Control.extend({ options: { position: "bottomleft", maxWidth: 100, metric: !0, imperial: !0 }, onAdd: function(t) { var e = "leaflet-control-scale", - i = o.DomUtil.create("div", e), - n = this.options; return this._addScales(n, e + "-line", i), t.on(n.updateWhenIdle ? "moveend" : "move", this._update, this), t.whenReady(this._update, this), i }, onRemove: function(t) { t.off(this.options.updateWhenIdle ? "moveend" : "move", this._update, this) }, _addScales: function(t, e, i) { t.metric && (this._mScale = o.DomUtil.create("div", e, i)), t.imperial && (this._iScale = o.DomUtil.create("div", e, i)) }, _update: function() { var t = this._map, - e = t.getSize().y / 2, - i = t.distance(t.containerPointToLatLng([0, e]), t.containerPointToLatLng([this.options.maxWidth, e])); - this._updateScales(i) }, _updateScales: function(t) { this.options.metric && t && this._updateMetric(t), this.options.imperial && t && this._updateImperial(t) }, _updateMetric: function(t) { var e = this._getRoundNum(t), - i = 1e3 > e ? e + " m" : e / 1e3 + " km"; - this._updateScale(this._mScale, i, e / t) }, _updateImperial: function(t) { var e, i, n, o = 3.2808399 * t; - o > 5280 ? (e = o / 5280, i = this._getRoundNum(e), this._updateScale(this._iScale, i + " mi", i / e)) : (n = this._getRoundNum(o), this._updateScale(this._iScale, n + " ft", n / o)) }, _updateScale: function(t, e, i) { t.style.width = Math.round(this.options.maxWidth * i) + "px", t.innerHTML = e }, _getRoundNum: function(t) { var e = Math.pow(10, (Math.floor(t) + "").length - 1), - i = t / e; return i = i >= 10 ? 10 : i >= 5 ? 5 : i >= 3 ? 3 : i >= 2 ? 2 : 1, e * i } }), o.control.scale = function(t) { return new o.Control.Scale(t) }, o.Control.Layers = o.Control.extend({ options: { collapsed: !0, position: "topright", autoZIndex: !0, hideSingleBase: !1 }, initialize: function(t, e, i) { o.setOptions(this, i), this._layers = {}, this._lastZIndex = 0, this._handlingClick = !1; for (var n in t) this._addLayer(t[n], n); for (n in e) this._addLayer(e[n], n, !0) }, onAdd: function(t) { return this._initLayout(), this._update(), this._map = t, t.on("zoomend", this._checkDisabledLayers, this), this._container }, onRemove: function() { this._map.off("zoomend", this._checkDisabledLayers, this) }, addBaseLayer: function(t, e) { return this._addLayer(t, e), this._update() }, addOverlay: function(t, e) { return this._addLayer(t, e, !0), this._update() }, removeLayer: function(t) { return t.off("add remove", this._onLayerChange, this), delete this._layers[o.stamp(t)], this._update() }, _initLayout: function() { var t = "leaflet-control-layers", - e = this._container = o.DomUtil.create("div", t); - e.setAttribute("aria-haspopup", !0), o.DomEvent.disableClickPropagation(e), o.Browser.touch || o.DomEvent.disableScrollPropagation(e); var i = this._form = o.DomUtil.create("form", t + "-list"); if (this.options.collapsed) { o.Browser.android || o.DomEvent.on(e, { mouseenter: this._expand, mouseleave: this._collapse }, this); var n = this._layersLink = o.DomUtil.create("a", t + "-toggle", e); - n.href = "#", n.title = "Layers", o.Browser.touch ? o.DomEvent.on(n, "click", o.DomEvent.stop).on(n, "click", this._expand, this) : o.DomEvent.on(n, "focus", this._expand, this), o.DomEvent.on(i, "click", function() { setTimeout(o.bind(this._onInputClick, this), 0) }, this), this._map.on("click", this._collapse, this) } else this._expand(); - this._baseLayersList = o.DomUtil.create("div", t + "-base", i), this._separator = o.DomUtil.create("div", t + "-separator", i), this._overlaysList = o.DomUtil.create("div", t + "-overlays", i), e.appendChild(i) }, _addLayer: function(t, e, i) { t.on("add remove", this._onLayerChange, this); var n = o.stamp(t); - this._layers[n] = { layer: t, name: e, overlay: i }, this.options.autoZIndex && t.setZIndex && (this._lastZIndex++, t.setZIndex(this._lastZIndex)) }, _update: function() { if (!this._container) return this; - o.DomUtil.empty(this._baseLayersList), o.DomUtil.empty(this._overlaysList); var t, e, i, n, s = 0; for (i in this._layers) n = this._layers[i], this._addItem(n), e = e || n.overlay, t = t || !n.overlay, s += n.overlay ? 0 : 1; return this.options.hideSingleBase && (t = t && s > 1, this._baseLayersList.style.display = t ? "" : "none"), this._separator.style.display = e && t ? "" : "none", this }, _onLayerChange: function(t) { this._handlingClick || this._update(); var e = this._layers[o.stamp(t.target)], - i = e.overlay ? "add" === t.type ? "overlayadd" : "overlayremove" : "add" === t.type ? "baselayerchange" : null; - i && this._map.fire(i, e) }, _createRadioElement: function(t, i) { var n = '", - o = e.createElement("div"); return o.innerHTML = n, o.firstChild }, _addItem: function(t) { var i, n = e.createElement("label"), - s = this._map.hasLayer(t.layer); - t.overlay ? (i = e.createElement("input"), i.type = "checkbox", i.className = "leaflet-control-layers-selector", i.defaultChecked = s) : i = this._createRadioElement("leaflet-base-layers", s), i.layerId = o.stamp(t.layer), o.DomEvent.on(i, "click", this._onInputClick, this); var r = e.createElement("span"); - r.innerHTML = " " + t.name; var a = e.createElement("div"); - n.appendChild(a), a.appendChild(i), a.appendChild(r); var h = t.overlay ? this._overlaysList : this._baseLayersList; return h.appendChild(n), this._checkDisabledLayers(), n }, _onInputClick: function() { var t, e, i, n = this._form.getElementsByTagName("input"), - o = [], - s = []; - this._handlingClick = !0; for (var r = n.length - 1; r >= 0; r--) t = n[r], e = this._layers[t.layerId].layer, i = this._map.hasLayer(e), t.checked && !i ? o.push(e) : !t.checked && i && s.push(e); for (r = 0; r < s.length; r++) this._map.removeLayer(s[r]); for (r = 0; r < o.length; r++) this._map.addLayer(o[r]); - this._handlingClick = !1, this._refocusOnMap() }, _expand: function() { o.DomUtil.addClass(this._container, "leaflet-control-layers-expanded"), this._form.style.height = null; var t = this._map._size.y - (this._container.offsetTop + 50); - t < this._form.clientHeight ? (o.DomUtil.addClass(this._form, "leaflet-control-layers-scrollbar"), this._form.style.height = t + "px") : o.DomUtil.removeClass(this._form, "leaflet-control-layers-scrollbar"), this._checkDisabledLayers() }, _collapse: function() { o.DomUtil.removeClass(this._container, "leaflet-control-layers-expanded") }, _checkDisabledLayers: function() { for (var t, e, n = this._form.getElementsByTagName("input"), o = this._map.getZoom(), s = n.length - 1; s >= 0; s--) t = n[s], e = this._layers[t.layerId].layer, t.disabled = e.options.minZoom !== i && o < e.options.minZoom || e.options.maxZoom !== i && o > e.options.maxZoom } }), o.control.layers = function(t, e, i) { return new o.Control.Layers(t, e, i) }, o.PosAnimation = o.Evented.extend({ run: function(t, e, i, n) { this.stop(), this._el = t, this._inProgress = !0, this._duration = i || .25, this._easeOutPower = 1 / Math.max(n || .5, .2), this._startPos = o.DomUtil.getPosition(t), this._offset = e.subtract(this._startPos), this._startTime = +new Date, this.fire("start"), this._animate() }, stop: function() { this._inProgress && (this._step(!0), this._complete()) }, _animate: function() { this._animId = o.Util.requestAnimFrame(this._animate, this), this._step() }, _step: function(t) { var e = +new Date - this._startTime, - i = 1e3 * this._duration; - i > e ? this._runFrame(this._easeOut(e / i), t) : (this._runFrame(1), this._complete()) }, _runFrame: function(t, e) { var i = this._startPos.add(this._offset.multiplyBy(t)); - e && i._round(), o.DomUtil.setPosition(this._el, i), this.fire("step") }, _complete: function() { o.Util.cancelAnimFrame(this._animId), this._inProgress = !1, this.fire("end") }, _easeOut: function(t) { return 1 - Math.pow(1 - t, this._easeOutPower) } }), o.Map.include({ setView: function(t, e, n) { if (e = e === i ? this._zoom : this._limitZoom(e), t = this._limitCenter(o.latLng(t), e, this.options.maxBounds), n = n || {}, this.stop(), this._loaded && !n.reset && n !== !0) { n.animate !== i && (n.zoom = o.extend({ animate: n.animate }, n.zoom), n.pan = o.extend({ animate: n.animate, duration: n.duration }, n.pan)); var s = this._zoom !== e ? this._tryAnimatedZoom && this._tryAnimatedZoom(t, e, n.zoom) : this._tryAnimatedPan(t, n.pan); if (s) return clearTimeout(this._sizeTimer), this } return this._resetView(t, e), this }, panBy: function(t, e) { if (t = o.point(t).round(), e = e || {}, !t.x && !t.y) return this.fire("moveend"); if (e.animate !== !0 && !this.getSize().contains(t)) return this._resetView(this.unproject(this.project(this.getCenter()).add(t)), this.getZoom()), this; if (this._panAnim || (this._panAnim = new o.PosAnimation, this._panAnim.on({ step: this._onPanTransitionStep, end: this._onPanTransitionEnd }, this)), e.noMoveStart || this.fire("movestart"), e.animate !== !1) { o.DomUtil.addClass(this._mapPane, "leaflet-pan-anim"); var i = this._getMapPanePos().subtract(t); - this._panAnim.run(this._mapPane, i, e.duration || .25, e.easeLinearity) } else this._rawPanBy(t), this.fire("move").fire("moveend"); return this }, _onPanTransitionStep: function() { this.fire("move") }, _onPanTransitionEnd: function() { o.DomUtil.removeClass(this._mapPane, "leaflet-pan-anim"), this.fire("moveend") }, _tryAnimatedPan: function(t, e) { var i = this._getCenterOffset(t)._floor(); return (e && e.animate) === !0 || this.getSize().contains(i) ? (this.panBy(i, e), !0) : !1 } }), o.Map.mergeOptions({ zoomAnimation: !0, zoomAnimationThreshold: 4 }); - var h = o.DomUtil.TRANSITION && o.Browser.any3d && !o.Browser.mobileOpera; - h && o.Map.addInitHook(function() { this._zoomAnimated = this.options.zoomAnimation, this._zoomAnimated && (this._createAnimProxy(), o.DomEvent.on(this._proxy, o.DomUtil.TRANSITION_END, this._catchTransitionEnd, this)) }), o.Map.include(h ? { - _createAnimProxy: function() { - var t = this._proxy = o.DomUtil.create("div", "leaflet-proxy leaflet-zoom-animated"); - this._panes.mapPane.appendChild(t), this.on("zoomanim", function(e) { var i = o.DomUtil.TRANSFORM, - n = t.style[i]; - o.DomUtil.setTransform(t, this.project(e.center, e.zoom), this.getZoomScale(e.zoom, 1)), n === t.style[i] && this._animatingZoom && this._onZoomTransitionEnd() }, this), this.on("load moveend", function() { - var e = this.getCenter(), - i = this.getZoom(); - o.DomUtil.setTransform(t, this.project(e, i), this.getZoomScale(i, 1)) - }, this) - }, - _catchTransitionEnd: function(t) { this._animatingZoom && t.propertyName.indexOf("transform") >= 0 && this._onZoomTransitionEnd() }, - _nothingToAnimate: function() { return !this._container.getElementsByClassName("leaflet-zoom-animated").length }, - _tryAnimatedZoom: function(t, e, i) { if (this._animatingZoom) return !0; if (i = i || {}, !this._zoomAnimated || i.animate === !1 || this._nothingToAnimate() || Math.abs(e - this._zoom) > this.options.zoomAnimationThreshold) return !1; var n = this.getZoomScale(e), - s = this._getCenterOffset(t)._divideBy(1 - 1 / n); return i.animate === !0 || this.getSize().contains(s) ? (o.Util.requestAnimFrame(function() { this._moveStart(!0)._animateZoom(t, e, !0) }, this), !0) : !1 }, - _animateZoom: function(t, e, i, n) { i && (this._animatingZoom = !0, this._animateToCenter = t, this._animateToZoom = e, o.DomUtil.addClass(this._mapPane, "leaflet-zoom-anim")), this.fire("zoomanim", { center: t, zoom: e, noUpdate: n }), setTimeout(o.bind(this._onZoomTransitionEnd, this), 250) }, - _onZoomTransitionEnd: function() { this._animatingZoom && (o.DomUtil.removeClass(this._mapPane, "leaflet-zoom-anim"), o.Util.requestAnimFrame(function() { this._animatingZoom = !1, this._move(this._animateToCenter, this._animateToZoom)._moveEnd(!0) }, this)) } - } : {}), o.Map.include({ flyTo: function(t, e, n) { - function s(t) { var e = (v * v - g * g + (t ? -1 : 1) * L * L * y * y) / (2 * (t ? v : g) * L * y); return Math.log(Math.sqrt(e * e + 1) - e) } + ) { + if (((i = this._targets[o.stamp(r)]), i && i.listens(e, !0))) { + if (s && !o.DomEvent._isExternalTarget(r, t)) break; + if ((n.push(i), s)) break; + } + if (r === this._container) break; + r = r.parentNode; + } + return n.length || s || !o.DomEvent._isExternalTarget(r, t) || (n = [this]), n; + }, + _handleDOMEvent: function (t) { + if (this._loaded && !o.DomEvent._skipped(t)) { + var e = "keypress" === t.type && 13 === t.keyCode ? "click" : t.type; + if ("click" === t.type) { + var i = o.Util.extend({}, t); + (i.type = "preclick"), this._handleDOMEvent(i); + } + "mousedown" === e && o.DomUtil.preventOutline(t.target || t.srcElement), + this._fireDOMEvent(t, e); + } + }, + _fireDOMEvent: function (t, e, i) { + if (!t._stopped && ((i = (i || []).concat(this._findEventTargets(t, e))), i.length)) { + var n = i[0]; + if ( + ("contextmenu" === e && n.listens(e, !0) && o.DomEvent.preventDefault(t), + ("click" !== t.type && "preclick" !== t.type) || + t._simulated || + !this._draggableMoved(n)) + ) { + var s = { originalEvent: t }; + if ("keypress" !== t.type) { + var r = n instanceof o.Marker; + (s.containerPoint = r + ? this.latLngToContainerPoint(n.getLatLng()) + : this.mouseEventToContainerPoint(t)), + (s.layerPoint = this.containerPointToLayerPoint(s.containerPoint)), + (s.latlng = r ? n.getLatLng() : this.layerPointToLatLng(s.layerPoint)); + } + for (var a = 0; a < i.length; a++) + if ( + (i[a].fire(e, s, !0), + s.originalEvent._stopped || + (i[a].options.nonBubblingEvents && + -1 !== o.Util.indexOf(i[a].options.nonBubblingEvents, e))) + ) + return; + } + } + }, + _draggableMoved: function (t) { + return ( + (t = t.options.draggable ? t : this), + (t.dragging && t.dragging.moved()) || (this.boxZoom && this.boxZoom.moved()) + ); + }, + _clearHandlers: function () { + for (var t = 0, e = this._handlers.length; e > t; t++) this._handlers[t].disable(); + }, + whenReady: function (t, e) { + return this._loaded ? t.call(e || this, { target: this }) : this.on("load", t, e), this; + }, + _getMapPanePos: function () { + return o.DomUtil.getPosition(this._mapPane) || new o.Point(0, 0); + }, + _moved: function () { + var t = this._getMapPanePos(); + return t && !t.equals([0, 0]); + }, + _getTopLeftPoint: function (t, e) { + var n = t && e !== i ? this._getNewPixelOrigin(t, e) : this.getPixelOrigin(); + return n.subtract(this._getMapPanePos()); + }, + _getNewPixelOrigin: function (t, e) { + var i = this.getSize()._divideBy(2); + return this.project(t, e)._subtract(i)._add(this._getMapPanePos())._round(); + }, + _latLngToNewLayerPoint: function (t, e, i) { + var n = this._getNewPixelOrigin(i, e); + return this.project(t, e)._subtract(n); + }, + _getCenterLayerPoint: function () { + return this.containerPointToLayerPoint(this.getSize()._divideBy(2)); + }, + _getCenterOffset: function (t) { + return this.latLngToLayerPoint(t).subtract(this._getCenterLayerPoint()); + }, + _limitCenter: function (t, e, i) { + if (!i) return t; + var n = this.project(t, e), + s = this.getSize().divideBy(2), + r = new o.Bounds(n.subtract(s), n.add(s)), + a = this._getBoundsOffset(r, i, e); + return this.unproject(n.add(a), e); + }, + _limitOffset: function (t, e) { + if (!e) return t; + var i = this.getPixelBounds(), + n = new o.Bounds(i.min.add(t), i.max.add(t)); + return t.add(this._getBoundsOffset(n, e)); + }, + _getBoundsOffset: function (t, e, i) { + var n = this.project(e.getNorthWest(), i).subtract(t.min), + s = this.project(e.getSouthEast(), i).subtract(t.max), + r = this._rebound(n.x, -s.x), + a = this._rebound(n.y, -s.y); + return new o.Point(r, a); + }, + _rebound: function (t, e) { + return t + e > 0 + ? Math.round(t - e) / 2 + : Math.max(0, Math.ceil(t)) - Math.max(0, Math.floor(e)); + }, + _limitZoom: function (t) { + var e = this.getMinZoom(), + i = this.getMaxZoom(); + return o.Browser.any3d || (t = Math.round(t)), Math.max(e, Math.min(i, t)); + }, + })), + (o.map = function (t, e) { + return new o.Map(t, e); + }), + (o.Layer = o.Evented.extend({ + options: { pane: "overlayPane", nonBubblingEvents: [] }, + addTo: function (t) { + return t.addLayer(this), this; + }, + remove: function () { + return this.removeFrom(this._map || this._mapToAdd); + }, + removeFrom: function (t) { + return t && t.removeLayer(this), this; + }, + getPane: function (t) { + return this._map.getPane(t ? this.options[t] || t : this.options.pane); + }, + addInteractiveTarget: function (t) { + return (this._map._targets[o.stamp(t)] = this), this; + }, + removeInteractiveTarget: function (t) { + return delete this._map._targets[o.stamp(t)], this; + }, + _layerAdd: function (t) { + var e = t.target; + e.hasLayer(this) && + ((this._map = e), + (this._zoomAnimated = e._zoomAnimated), + this.getEvents && e.on(this.getEvents(), this), + this.onAdd(e), + this.getAttribution && + this._map.attributionControl && + this._map.attributionControl.addAttribution(this.getAttribution()), + this.fire("add"), + e.fire("layeradd", { layer: this })); + }, + })), + o.Map.include({ + addLayer: function (t) { + var e = o.stamp(t); + return this._layers[e] + ? t + : ((this._layers[e] = t), + (t._mapToAdd = this), + t.beforeAdd && t.beforeAdd(this), + this.whenReady(t._layerAdd, t), + this); + }, + removeLayer: function (t) { + var e = o.stamp(t); + return this._layers[e] + ? (this._loaded && t.onRemove(this), + t.getAttribution && + this.attributionControl && + this.attributionControl.removeAttribution(t.getAttribution()), + t.getEvents && this.off(t.getEvents(), t), + delete this._layers[e], + this._loaded && (this.fire("layerremove", { layer: t }), t.fire("remove")), + (t._map = t._mapToAdd = null), + this) + : this; + }, + hasLayer: function (t) { + return !!t && o.stamp(t) in this._layers; + }, + eachLayer: function (t, e) { + for (var i in this._layers) t.call(e, this._layers[i]); + return this; + }, + _addLayers: function (t) { + t = t ? (o.Util.isArray(t) ? t : [t]) : []; + for (var e = 0, i = t.length; i > e; e++) this.addLayer(t[e]); + }, + _addZoomLimit: function (t) { + (isNaN(t.options.maxZoom) || !isNaN(t.options.minZoom)) && + ((this._zoomBoundLayers[o.stamp(t)] = t), this._updateZoomLevels()); + }, + _removeZoomLimit: function (t) { + var e = o.stamp(t); + this._zoomBoundLayers[e] && (delete this._zoomBoundLayers[e], this._updateZoomLevels()); + }, + _updateZoomLevels: function () { + var t = 1 / 0, + e = -(1 / 0), + n = this._getZoomSpan(); + for (var o in this._zoomBoundLayers) { + var s = this._zoomBoundLayers[o].options; + (t = s.minZoom === i ? t : Math.min(t, s.minZoom)), + (e = s.maxZoom === i ? e : Math.max(e, s.maxZoom)); + } + (this._layersMaxZoom = e === -(1 / 0) ? i : e), + (this._layersMinZoom = t === 1 / 0 ? i : t), + n !== this._getZoomSpan() && this.fire("zoomlevelschange"); + }, + }), + (o.Projection.Mercator = { + R: 6378137, + R_MINOR: 6356752.314245179, + bounds: o.bounds([-20037508.34279, -15496570.73972], [20037508.34279, 18764656.23138]), + project: function (t) { + var e = Math.PI / 180, + i = this.R, + n = t.lat * e, + s = this.R_MINOR / i, + r = Math.sqrt(1 - s * s), + a = r * Math.sin(n), + h = Math.tan(Math.PI / 4 - n / 2) / Math.pow((1 - a) / (1 + a), r / 2); + return (n = -i * Math.log(Math.max(h, 1e-10))), new o.Point(t.lng * e * i, n); + }, + unproject: function (t) { + for ( + var e, + i = 180 / Math.PI, + n = this.R, + s = this.R_MINOR / n, + r = Math.sqrt(1 - s * s), + a = Math.exp(-t.y / n), + h = Math.PI / 2 - 2 * Math.atan(a), + l = 0, + u = 0.1; + 15 > l && Math.abs(u) > 1e-7; + l++ + ) + (e = r * Math.sin(h)), + (e = Math.pow((1 - e) / (1 + e), r / 2)), + (u = Math.PI / 2 - 2 * Math.atan(a * e) - h), + (h += u); + return new o.LatLng(h * i, (t.x * i) / n); + }, + }), + (o.CRS.EPSG3395 = o.extend({}, o.CRS.Earth, { + code: "EPSG:3395", + projection: o.Projection.Mercator, + transformation: (function () { + var t = 0.5 / (Math.PI * o.Projection.Mercator.R); + return new o.Transformation(t, 0.5, -t, 0.5); + })(), + })), + (o.GridLayer = o.Layer.extend({ + options: { + pane: "tilePane", + tileSize: 256, + opacity: 1, + zIndex: 1, + updateWhenIdle: o.Browser.mobile, + updateInterval: 200, + attribution: null, + bounds: null, + minZoom: 0, + }, + initialize: function (t) { + t = o.setOptions(this, t); + }, + onAdd: function () { + this._initContainer(), + (this._levels = {}), + (this._tiles = {}), + this._resetView(), + this._update(); + }, + beforeAdd: function (t) { + t._addZoomLimit(this); + }, + onRemove: function (t) { + o.DomUtil.remove(this._container), + t._removeZoomLimit(this), + (this._container = null), + (this._tileZoom = null); + }, + bringToFront: function () { + return this._map && (o.DomUtil.toFront(this._container), this._setAutoZIndex(Math.max)), this; + }, + bringToBack: function () { + return this._map && (o.DomUtil.toBack(this._container), this._setAutoZIndex(Math.min)), this; + }, + getAttribution: function () { + return this.options.attribution; + }, + getContainer: function () { + return this._container; + }, + setOpacity: function (t) { + return (this.options.opacity = t), this._updateOpacity(), this; + }, + setZIndex: function (t) { + return (this.options.zIndex = t), this._updateZIndex(), this; + }, + isLoading: function () { + return this._loading; + }, + redraw: function () { + return this._map && (this._removeAllTiles(), this._update()), this; + }, + getEvents: function () { + var t = { viewreset: this._resetAll, zoom: this._resetView, moveend: this._onMoveEnd }; + return ( + this.options.updateWhenIdle || + (this._onMove || + (this._onMove = o.Util.throttle( + this._onMoveEnd, + this.options.updateInterval, + this + )), + (t.move = this._onMove)), + this._zoomAnimated && (t.zoomanim = this._animateZoom), + t + ); + }, + createTile: function () { + return e.createElement("div"); + }, + getTileSize: function () { + var t = this.options.tileSize; + return t instanceof o.Point ? t : new o.Point(t, t); + }, + _updateZIndex: function () { + this._container && + this.options.zIndex !== i && + null !== this.options.zIndex && + (this._container.style.zIndex = this.options.zIndex); + }, + _setAutoZIndex: function (t) { + for ( + var e, i = this.getPane().children, n = -t(-(1 / 0), 1 / 0), o = 0, s = i.length; + s > o; + o++ + ) + (e = i[o].style.zIndex), i[o] !== this._container && e && (n = t(n, +e)); + isFinite(n) && ((this.options.zIndex = n + t(-1, 1)), this._updateZIndex()); + }, + _updateOpacity: function () { + if (this._map && !o.Browser.ielt9 && this._map._fadeAnimated) { + o.DomUtil.setOpacity(this._container, this.options.opacity); + var t = +new Date(), + e = !1, + i = !1; + for (var n in this._tiles) { + var s = this._tiles[n]; + if (s.current && s.loaded) { + var r = Math.min(1, (t - s.loaded) / 200); + o.DomUtil.setOpacity(s.el, r), + 1 > r ? (e = !0) : (s.active && (i = !0), (s.active = !0)); + } + } + i && !this._noPrune && this._pruneTiles(), + e && + (o.Util.cancelAnimFrame(this._fadeFrame), + (this._fadeFrame = o.Util.requestAnimFrame(this._updateOpacity, this))); + } + }, + _initContainer: function () { + this._container || + ((this._container = o.DomUtil.create("div", "leaflet-layer")), + this._updateZIndex(), + this.options.opacity < 1 && this._updateOpacity(), + this.getPane().appendChild(this._container)); + }, + _updateLevels: function () { + var t = this._tileZoom, + e = this.options.maxZoom; + for (var i in this._levels) + this._levels[i].el.children.length || i === t + ? (this._levels[i].el.style.zIndex = e - Math.abs(t - i)) + : (o.DomUtil.remove(this._levels[i].el), delete this._levels[i]); + var n = this._levels[t], + s = this._map; + return ( + n || + ((n = this._levels[t] = {}), + (n.el = o.DomUtil.create( + "div", + "leaflet-tile-container leaflet-zoom-animated", + this._container + )), + (n.el.style.zIndex = e), + (n.origin = s.project(s.unproject(s.getPixelOrigin()), t).round()), + (n.zoom = t), + this._setZoomTransform(n, s.getCenter(), s.getZoom()), + o.Util.falseFn(n.el.offsetWidth)), + (this._level = n), + n + ); + }, + _pruneTiles: function () { + var t, + e, + i = this._map.getZoom(); + if (i > this.options.maxZoom || i < this.options.minZoom) return this._removeAllTiles(); + for (t in this._tiles) (e = this._tiles[t]), (e.retain = e.current); + for (t in this._tiles) + if (((e = this._tiles[t]), e.current && !e.active)) { + var n = e.coords; + this._retainParent(n.x, n.y, n.z, n.z - 5) || + this._retainChildren(n.x, n.y, n.z, n.z + 2); + } + for (t in this._tiles) this._tiles[t].retain || this._removeTile(t); + }, + _removeAllTiles: function () { + for (var t in this._tiles) this._removeTile(t); + }, + _resetAll: function () { + for (var t in this._levels) o.DomUtil.remove(this._levels[t].el), delete this._levels[t]; + this._removeAllTiles(), (this._tileZoom = null), this._resetView(); + }, + _retainParent: function (t, e, i, n) { + var o = Math.floor(t / 2), + s = Math.floor(e / 2), + r = i - 1, + a = o + ":" + s + ":" + r, + h = this._tiles[a]; + return h && h.active + ? ((h.retain = !0), !0) + : (h && h.loaded && (h.retain = !0), r > n ? this._retainParent(o, s, r, n) : !1); + }, + _retainChildren: function (t, e, i, n) { + for (var o = 2 * t; 2 * t + 2 > o; o++) + for (var s = 2 * e; 2 * e + 2 > s; s++) { + var r = o + ":" + s + ":" + (i + 1), + a = this._tiles[r]; + a && a.active + ? (a.retain = !0) + : (a && a.loaded && (a.retain = !0), + n > i + 1 && this._retainChildren(o, s, i + 1, n)); + } + }, + _resetView: function (t) { + var e = t && (t.pinch || t.flyTo); + this._setView(this._map.getCenter(), this._map.getZoom(), e, e); + }, + _animateZoom: function (t) { + this._setView(t.center, t.zoom, !0, t.noUpdate); + }, + _setView: function (t, e, n, o) { + var s = Math.round(e); + ((this.options.maxZoom !== i && s > this.options.maxZoom) || + (this.options.minZoom !== i && s < this.options.minZoom)) && + (s = i); + var r = s !== this._tileZoom; + (!o || r) && + ((this._tileZoom = s), + this._abortLoading && this._abortLoading(), + this._updateLevels(), + this._resetGrid(), + s !== i && this._update(t), + n || this._pruneTiles(), + (this._noPrune = !!n)), + this._setZoomTransforms(t, e); + }, + _setZoomTransforms: function (t, e) { + for (var i in this._levels) this._setZoomTransform(this._levels[i], t, e); + }, + _setZoomTransform: function (t, e, i) { + var n = this._map.getZoomScale(i, t.zoom), + s = t.origin.multiplyBy(n).subtract(this._map._getNewPixelOrigin(e, i)).round(); + o.Browser.any3d ? o.DomUtil.setTransform(t.el, s, n) : o.DomUtil.setPosition(t.el, s); + }, + _resetGrid: function () { + var t = this._map, + e = t.options.crs, + i = (this._tileSize = this.getTileSize()), + n = this._tileZoom, + o = this._map.getPixelWorldBounds(this._tileZoom); + o && (this._globalTileRange = this._pxBoundsToTileRange(o)), + (this._wrapX = e.wrapLng && + !this.options.noWrap && [ + Math.floor(t.project([0, e.wrapLng[0]], n).x / i.x), + Math.ceil(t.project([0, e.wrapLng[1]], n).x / i.y), + ]), + (this._wrapY = e.wrapLat && + !this.options.noWrap && [ + Math.floor(t.project([e.wrapLat[0], 0], n).y / i.x), + Math.ceil(t.project([e.wrapLat[1], 0], n).y / i.y), + ]); + }, + _onMoveEnd: function () { + this._map && !this._map._animatingZoom && this._resetView(); + }, + _getTiledPixelBounds: function (t, e, i) { + var n = this._map, + s = n.getZoomScale(e, i), + r = n.project(t, i).floor(), + a = n.getSize().divideBy(2 * s); + return new o.Bounds(r.subtract(a), r.add(a)); + }, + _update: function (t) { + var n = this._map; + if (n) { + var s = n.getZoom(); + if ((t === i && (t = n.getCenter()), this._tileZoom !== i)) { + var r = this._getTiledPixelBounds(t, s, this._tileZoom), + a = this._pxBoundsToTileRange(r), + h = a.getCenter(), + l = []; + for (var u in this._tiles) this._tiles[u].current = !1; + if (Math.abs(s - this._tileZoom) > 1) return void this._setView(t, s); + for (var c = a.min.y; c <= a.max.y; c++) + for (var d = a.min.x; d <= a.max.x; d++) { + var _ = new o.Point(d, c); + if (((_.z = this._tileZoom), this._isValidTile(_))) { + var m = this._tiles[this._tileCoordsToKey(_)]; + m ? (m.current = !0) : l.push(_); + } + } + if ( + (l.sort(function (t, e) { + return t.distanceTo(h) - e.distanceTo(h); + }), + 0 !== l.length) + ) { + this._loading || ((this._loading = !0), this.fire("loading")); + var p = e.createDocumentFragment(); + for (d = 0; d < l.length; d++) this._addTile(l[d], p); + this._level.el.appendChild(p); + } + } + } + }, + _isValidTile: function (t) { + var e = this._map.options.crs; + if (!e.infinite) { + var i = this._globalTileRange; + if ( + (!e.wrapLng && (t.x < i.min.x || t.x > i.max.x)) || + (!e.wrapLat && (t.y < i.min.y || t.y > i.max.y)) + ) + return !1; + } + if (!this.options.bounds) return !0; + var n = this._tileCoordsToBounds(t); + return o.latLngBounds(this.options.bounds).overlaps(n); + }, + _keyToBounds: function (t) { + return this._tileCoordsToBounds(this._keyToTileCoords(t)); + }, + _tileCoordsToBounds: function (t) { + var e = this._map, + i = this.getTileSize(), + n = t.scaleBy(i), + s = n.add(i), + r = e.wrapLatLng(e.unproject(n, t.z)), + a = e.wrapLatLng(e.unproject(s, t.z)); + return new o.LatLngBounds(r, a); + }, + _tileCoordsToKey: function (t) { + return t.x + ":" + t.y + ":" + t.z; + }, + _keyToTileCoords: function (t) { + var e = t.split(":"), + i = new o.Point(+e[0], +e[1]); + return (i.z = +e[2]), i; + }, + _removeTile: function (t) { + var e = this._tiles[t]; + e && + (o.DomUtil.remove(e.el), + delete this._tiles[t], + this.fire("tileunload", { tile: e.el, coords: this._keyToTileCoords(t) })); + }, + _initTile: function (t) { + o.DomUtil.addClass(t, "leaflet-tile"); + var e = this.getTileSize(); + (t.style.width = e.x + "px"), + (t.style.height = e.y + "px"), + (t.onselectstart = o.Util.falseFn), + (t.onmousemove = o.Util.falseFn), + o.Browser.ielt9 && + this.options.opacity < 1 && + o.DomUtil.setOpacity(t, this.options.opacity), + o.Browser.android && + !o.Browser.android23 && + (t.style.WebkitBackfaceVisibility = "hidden"); + }, + _addTile: function (t, e) { + var i = this._getTilePos(t), + n = this._tileCoordsToKey(t), + s = this.createTile(this._wrapCoords(t), o.bind(this._tileReady, this, t)); + this._initTile(s), + this.createTile.length < 2 && + o.Util.requestAnimFrame(o.bind(this._tileReady, this, t, null, s)), + o.DomUtil.setPosition(s, i), + (this._tiles[n] = { el: s, coords: t, current: !0 }), + e.appendChild(s), + this.fire("tileloadstart", { tile: s, coords: t }); + }, + _tileReady: function (t, e, i) { + if (this._map) { + e && this.fire("tileerror", { error: e, tile: i, coords: t }); + var n = this._tileCoordsToKey(t); + (i = this._tiles[n]), + i && + ((i.loaded = +new Date()), + this._map._fadeAnimated + ? (o.DomUtil.setOpacity(i.el, 0), + o.Util.cancelAnimFrame(this._fadeFrame), + (this._fadeFrame = o.Util.requestAnimFrame(this._updateOpacity, this))) + : ((i.active = !0), this._pruneTiles()), + o.DomUtil.addClass(i.el, "leaflet-tile-loaded"), + this.fire("tileload", { tile: i.el, coords: t }), + this._noTilesToLoad() && ((this._loading = !1), this.fire("load"))); + } + }, + _getTilePos: function (t) { + return t.scaleBy(this.getTileSize()).subtract(this._level.origin); + }, + _wrapCoords: function (t) { + var e = new o.Point( + this._wrapX ? o.Util.wrapNum(t.x, this._wrapX) : t.x, + this._wrapY ? o.Util.wrapNum(t.y, this._wrapY) : t.y + ); + return (e.z = t.z), e; + }, + _pxBoundsToTileRange: function (t) { + var e = this.getTileSize(); + return new o.Bounds(t.min.unscaleBy(e).floor(), t.max.unscaleBy(e).ceil().subtract([1, 1])); + }, + _noTilesToLoad: function () { + for (var t in this._tiles) if (!this._tiles[t].loaded) return !1; + return !0; + }, + })), + (o.gridLayer = function (t) { + return new o.GridLayer(t); + }), + (o.TileLayer = o.GridLayer.extend({ + options: { + maxZoom: 18, + subdomains: "abc", + errorTileUrl: "", + zoomOffset: 0, + maxNativeZoom: null, + tms: !1, + zoomReverse: !1, + detectRetina: !1, + crossOrigin: !1, + }, + initialize: function (t, e) { + (this._url = t), + (e = o.setOptions(this, e)), + e.detectRetina && + o.Browser.retina && + e.maxZoom > 0 && + ((e.tileSize = Math.floor(e.tileSize / 2)), + e.zoomOffset++, + (e.minZoom = Math.max(0, e.minZoom)), + e.maxZoom--), + "string" == typeof e.subdomains && (e.subdomains = e.subdomains.split("")), + o.Browser.android || this.on("tileunload", this._onTileRemove); + }, + setUrl: function (t, e) { + return (this._url = t), e || this.redraw(), this; + }, + createTile: function (t, i) { + var n = e.createElement("img"); + return ( + o.DomEvent.on(n, "load", o.bind(this._tileOnLoad, this, i, n)), + o.DomEvent.on(n, "error", o.bind(this._tileOnError, this, i, n)), + this.options.crossOrigin && (n.crossOrigin = ""), + (n.alt = ""), + (n.src = this.getTileUrl(t)), + n + ); + }, + getTileUrl: function (t) { + return o.Util.template( + this._url, + o.extend( + { + r: + this.options.detectRetina && o.Browser.retina && this.options.maxZoom > 0 + ? "@2x" + : "", + s: this._getSubdomain(t), + x: t.x, + y: this.options.tms ? this._globalTileRange.max.y - t.y : t.y, + z: this._getZoomForUrl(), + }, + this.options + ) + ); + }, + _tileOnLoad: function (t, e) { + o.Browser.ielt9 ? setTimeout(o.bind(t, this, null, e), 0) : t(null, e); + }, + _tileOnError: function (t, e, i) { + var n = this.options.errorTileUrl; + n && (e.src = n), t(i, e); + }, + getTileSize: function () { + var t = this._map, + e = o.GridLayer.prototype.getTileSize.call(this), + i = this._tileZoom + this.options.zoomOffset, + n = this.options.maxNativeZoom; + return null !== n && i > n ? e.divideBy(t.getZoomScale(n, i)).round() : e; + }, + _onTileRemove: function (t) { + t.tile.onload = null; + }, + _getZoomForUrl: function () { + var t = this.options, + e = this._tileZoom; + return ( + t.zoomReverse && (e = t.maxZoom - e), + (e += t.zoomOffset), + null !== t.maxNativeZoom ? Math.min(e, t.maxNativeZoom) : e + ); + }, + _getSubdomain: function (t) { + var e = Math.abs(t.x + t.y) % this.options.subdomains.length; + return this.options.subdomains[e]; + }, + _abortLoading: function () { + var t, e; + for (t in this._tiles) + this._tiles[t].coords.z !== this._tileZoom && + ((e = this._tiles[t].el), + (e.onload = o.Util.falseFn), + (e.onerror = o.Util.falseFn), + e.complete || ((e.src = o.Util.emptyImageUrl), o.DomUtil.remove(e))); + }, + })), + (o.tileLayer = function (t, e) { + return new o.TileLayer(t, e); + }), + (o.TileLayer.WMS = o.TileLayer.extend({ + defaultWmsParams: { + service: "WMS", + request: "GetMap", + version: "1.1.1", + layers: "", + styles: "", + format: "image/jpeg", + transparent: !1, + }, + options: { crs: null, uppercase: !1 }, + initialize: function (t, e) { + this._url = t; + var i = o.extend({}, this.defaultWmsParams); + for (var n in e) n in this.options || (i[n] = e[n]); + (e = o.setOptions(this, e)), + (i.width = i.height = e.tileSize * (e.detectRetina && o.Browser.retina ? 2 : 1)), + (this.wmsParams = i); + }, + onAdd: function (t) { + (this._crs = this.options.crs || t.options.crs), + (this._wmsVersion = parseFloat(this.wmsParams.version)); + var e = this._wmsVersion >= 1.3 ? "crs" : "srs"; + (this.wmsParams[e] = this._crs.code), o.TileLayer.prototype.onAdd.call(this, t); + }, + getTileUrl: function (t) { + var e = this._tileCoordsToBounds(t), + i = this._crs.project(e.getNorthWest()), + n = this._crs.project(e.getSouthEast()), + s = ( + this._wmsVersion >= 1.3 && this._crs === o.CRS.EPSG4326 + ? [n.y, i.x, i.y, n.x] + : [i.x, n.y, n.x, i.y] + ).join(","), + r = o.TileLayer.prototype.getTileUrl.call(this, t); + return ( + r + + o.Util.getParamString(this.wmsParams, r, this.options.uppercase) + + (this.options.uppercase ? "&BBOX=" : "&bbox=") + + s + ); + }, + setParams: function (t, e) { + return o.extend(this.wmsParams, t), e || this.redraw(), this; + }, + })), + (o.tileLayer.wms = function (t, e) { + return new o.TileLayer.WMS(t, e); + }), + (o.ImageOverlay = o.Layer.extend({ + options: { opacity: 1, alt: "", interactive: !1 }, + initialize: function (t, e, i) { + (this._url = t), (this._bounds = o.latLngBounds(e)), o.setOptions(this, i); + }, + onAdd: function () { + this._image || (this._initImage(), this.options.opacity < 1 && this._updateOpacity()), + this.options.interactive && + (o.DomUtil.addClass(this._image, "leaflet-interactive"), + this.addInteractiveTarget(this._image)), + this.getPane().appendChild(this._image), + this._reset(); + }, + onRemove: function () { + o.DomUtil.remove(this._image), + this.options.interactive && this.removeInteractiveTarget(this._image); + }, + setOpacity: function (t) { + return (this.options.opacity = t), this._image && this._updateOpacity(), this; + }, + setStyle: function (t) { + return t.opacity && this.setOpacity(t.opacity), this; + }, + bringToFront: function () { + return this._map && o.DomUtil.toFront(this._image), this; + }, + bringToBack: function () { + return this._map && o.DomUtil.toBack(this._image), this; + }, + setUrl: function (t) { + return (this._url = t), this._image && (this._image.src = t), this; + }, + setBounds: function (t) { + return (this._bounds = t), this._map && this._reset(), this; + }, + getAttribution: function () { + return this.options.attribution; + }, + getEvents: function () { + var t = { zoom: this._reset, viewreset: this._reset }; + return this._zoomAnimated && (t.zoomanim = this._animateZoom), t; + }, + getBounds: function () { + return this._bounds; + }, + getElement: function () { + return this._image; + }, + _initImage: function () { + var t = (this._image = o.DomUtil.create( + "img", + "leaflet-image-layer " + (this._zoomAnimated ? "leaflet-zoom-animated" : "") + )); + (t.onselectstart = o.Util.falseFn), + (t.onmousemove = o.Util.falseFn), + (t.onload = o.bind(this.fire, this, "load")), + this.options.crossOrigin && (t.crossOrigin = ""), + (t.src = this._url), + (t.alt = this.options.alt); + }, + _animateZoom: function (t) { + var e = this._map.getZoomScale(t.zoom), + i = this._map._latLngToNewLayerPoint(this._bounds.getNorthWest(), t.zoom, t.center); + o.DomUtil.setTransform(this._image, i, e); + }, + _reset: function () { + var t = this._image, + e = new o.Bounds( + this._map.latLngToLayerPoint(this._bounds.getNorthWest()), + this._map.latLngToLayerPoint(this._bounds.getSouthEast()) + ), + i = e.getSize(); + o.DomUtil.setPosition(t, e.min), (t.style.width = i.x + "px"), (t.style.height = i.y + "px"); + }, + _updateOpacity: function () { + o.DomUtil.setOpacity(this._image, this.options.opacity); + }, + })), + (o.imageOverlay = function (t, e, i) { + return new o.ImageOverlay(t, e, i); + }), + (o.Icon = o.Class.extend({ + initialize: function (t) { + o.setOptions(this, t); + }, + createIcon: function (t) { + return this._createIcon("icon", t); + }, + createShadow: function (t) { + return this._createIcon("shadow", t); + }, + _createIcon: function (t, e) { + var i = this._getIconUrl(t); + if (!i) { + if ("icon" === t) throw new Error("iconUrl not set in Icon options (see the docs)."); + return null; + } + var n = this._createImg(i, e && "IMG" === e.tagName ? e : null); + return this._setIconStyles(n, t), n; + }, + _setIconStyles: function (t, e) { + var i = this.options, + n = o.point(i[e + "Size"]), + s = o.point( + ("shadow" === e && i.shadowAnchor) || i.iconAnchor || (n && n.divideBy(2, !0)) + ); + (t.className = "leaflet-marker-" + e + " " + (i.className || "")), + s && ((t.style.marginLeft = -s.x + "px"), (t.style.marginTop = -s.y + "px")), + n && ((t.style.width = n.x + "px"), (t.style.height = n.y + "px")); + }, + _createImg: function (t, i) { + return (i = i || e.createElement("img")), (i.src = t), i; + }, + _getIconUrl: function (t) { + return (o.Browser.retina && this.options[t + "RetinaUrl"]) || this.options[t + "Url"]; + }, + })), + (o.icon = function (t) { + return new o.Icon(t); + }), + (o.Icon.Default = o.Icon.extend({ + options: { + iconSize: [25, 41], + iconAnchor: [12, 41], + popupAnchor: [1, -34], + shadowSize: [41, 41], + }, + _getIconUrl: function (t) { + var e = t + "Url"; + if (this.options[e]) return this.options[e]; + var i = o.Icon.Default.imagePath; + if (!i) throw new Error("Couldn't autodetect L.Icon.Default.imagePath, set it manually."); + return i + "/marker-" + t + (o.Browser.retina && "icon" === t ? "-2x" : "") + ".png"; + }, + })), + (o.Icon.Default.imagePath = (function () { + var t, + i, + n, + o, + s = e.getElementsByTagName("script"), + r = /[\/^]leaflet[\-\._]?([\w\-\._]*)\.js\??/; + for (t = 0, i = s.length; i > t; t++) + if (((n = s[t].src || ""), n.match(r))) + return (o = n.split(r)[0]), (o ? o + "/" : "") + "images"; + })()), + (o.Marker = o.Layer.extend({ + options: { + pane: "markerPane", + nonBubblingEvents: ["click", "dblclick", "mouseover", "mouseout", "contextmenu"], + icon: new o.Icon.Default(), + interactive: !0, + keyboard: !0, + zIndexOffset: 0, + opacity: 1, + riseOffset: 250, + }, + initialize: function (t, e) { + o.setOptions(this, e), (this._latlng = o.latLng(t)); + }, + onAdd: function (t) { + (this._zoomAnimated = this._zoomAnimated && t.options.markerZoomAnimation), + this._initIcon(), + this.update(); + }, + onRemove: function () { + this.dragging && + this.dragging.enabled() && + ((this.options.draggable = !0), this.dragging.removeHooks()), + this._removeIcon(), + this._removeShadow(); + }, + getEvents: function () { + var t = { zoom: this.update, viewreset: this.update }; + return this._zoomAnimated && (t.zoomanim = this._animateZoom), t; + }, + getLatLng: function () { + return this._latlng; + }, + setLatLng: function (t) { + var e = this._latlng; + return ( + (this._latlng = o.latLng(t)), + this.update(), + this.fire("move", { oldLatLng: e, latlng: this._latlng }) + ); + }, + setZIndexOffset: function (t) { + return (this.options.zIndexOffset = t), this.update(); + }, + setIcon: function (t) { + return ( + (this.options.icon = t), + this._map && (this._initIcon(), this.update()), + this._popup && this.bindPopup(this._popup, this._popup.options), + this + ); + }, + getElement: function () { + return this._icon; + }, + update: function () { + if (this._icon) { + var t = this._map.latLngToLayerPoint(this._latlng).round(); + this._setPos(t); + } + return this; + }, + _initIcon: function () { + var t = this.options, + e = "leaflet-zoom-" + (this._zoomAnimated ? "animated" : "hide"), + i = t.icon.createIcon(this._icon), + n = !1; + i !== this._icon && + (this._icon && this._removeIcon(), + (n = !0), + t.title && (i.title = t.title), + t.alt && (i.alt = t.alt)), + o.DomUtil.addClass(i, e), + t.keyboard && (i.tabIndex = "0"), + (this._icon = i), + t.riseOnHover && this.on({ mouseover: this._bringToFront, mouseout: this._resetZIndex }); + var s = t.icon.createShadow(this._shadow), + r = !1; + s !== this._shadow && (this._removeShadow(), (r = !0)), + s && o.DomUtil.addClass(s, e), + (this._shadow = s), + t.opacity < 1 && this._updateOpacity(), + n && (this.getPane().appendChild(this._icon), this._initInteraction()), + s && r && this.getPane("shadowPane").appendChild(this._shadow); + }, + _removeIcon: function () { + this.options.riseOnHover && + this.off({ mouseover: this._bringToFront, mouseout: this._resetZIndex }), + o.DomUtil.remove(this._icon), + this.removeInteractiveTarget(this._icon), + (this._icon = null); + }, + _removeShadow: function () { + this._shadow && o.DomUtil.remove(this._shadow), (this._shadow = null); + }, + _setPos: function (t) { + o.DomUtil.setPosition(this._icon, t), + this._shadow && o.DomUtil.setPosition(this._shadow, t), + (this._zIndex = t.y + this.options.zIndexOffset), + this._resetZIndex(); + }, + _updateZIndex: function (t) { + this._icon.style.zIndex = this._zIndex + t; + }, + _animateZoom: function (t) { + var e = this._map._latLngToNewLayerPoint(this._latlng, t.zoom, t.center).round(); + this._setPos(e); + }, + _initInteraction: function () { + if ( + this.options.interactive && + (o.DomUtil.addClass(this._icon, "leaflet-interactive"), + this.addInteractiveTarget(this._icon), + o.Handler.MarkerDrag) + ) { + var t = this.options.draggable; + this.dragging && ((t = this.dragging.enabled()), this.dragging.disable()), + (this.dragging = new o.Handler.MarkerDrag(this)), + t && this.dragging.enable(); + } + }, + setOpacity: function (t) { + return (this.options.opacity = t), this._map && this._updateOpacity(), this; + }, + _updateOpacity: function () { + var t = this.options.opacity; + o.DomUtil.setOpacity(this._icon, t), this._shadow && o.DomUtil.setOpacity(this._shadow, t); + }, + _bringToFront: function () { + this._updateZIndex(this.options.riseOffset); + }, + _resetZIndex: function () { + this._updateZIndex(0); + }, + })), + (o.marker = function (t, e) { + return new o.Marker(t, e); + }), + (o.DivIcon = o.Icon.extend({ + options: { iconSize: [12, 12], className: "leaflet-div-icon", html: !1 }, + createIcon: function (t) { + var i = t && "DIV" === t.tagName ? t : e.createElement("div"), + n = this.options; + return ( + (i.innerHTML = n.html !== !1 ? n.html : ""), + n.bgPos && (i.style.backgroundPosition = -n.bgPos.x + "px " + -n.bgPos.y + "px"), + this._setIconStyles(i, "icon"), + i + ); + }, + createShadow: function () { + return null; + }, + })), + (o.divIcon = function (t) { + return new o.DivIcon(t); + }), + o.Map.mergeOptions({ closePopupOnClick: !0 }), + (o.Popup = o.Layer.extend({ + options: { + pane: "popupPane", + minWidth: 50, + maxWidth: 300, + offset: [0, 7], + autoPan: !0, + autoPanPadding: [5, 5], + closeButton: !0, + autoClose: !0, + zoomAnimation: !0, + }, + initialize: function (t, e) { + o.setOptions(this, t), (this._source = e); + }, + onAdd: function (t) { + (this._zoomAnimated = this._zoomAnimated && this.options.zoomAnimation), + this._container || this._initLayout(), + t._fadeAnimated && o.DomUtil.setOpacity(this._container, 0), + clearTimeout(this._removeTimeout), + this.getPane().appendChild(this._container), + this.update(), + t._fadeAnimated && o.DomUtil.setOpacity(this._container, 1), + t.fire("popupopen", { popup: this }), + this._source && this._source.fire("popupopen", { popup: this }, !0); + }, + openOn: function (t) { + return t.openPopup(this), this; + }, + onRemove: function (t) { + t._fadeAnimated + ? (o.DomUtil.setOpacity(this._container, 0), + (this._removeTimeout = setTimeout( + o.bind(o.DomUtil.remove, o.DomUtil, this._container), + 200 + ))) + : o.DomUtil.remove(this._container), + t.fire("popupclose", { popup: this }), + this._source && this._source.fire("popupclose", { popup: this }, !0); + }, + getLatLng: function () { + return this._latlng; + }, + setLatLng: function (t) { + return ( + (this._latlng = o.latLng(t)), + this._map && (this._updatePosition(), this._adjustPan()), + this + ); + }, + getContent: function () { + return this._content; + }, + setContent: function (t) { + return (this._content = t), this.update(), this; + }, + getElement: function () { + return this._container; + }, + update: function () { + this._map && + ((this._container.style.visibility = "hidden"), + this._updateContent(), + this._updateLayout(), + this._updatePosition(), + (this._container.style.visibility = ""), + this._adjustPan()); + }, + getEvents: function () { + var t = { zoom: this._updatePosition, viewreset: this._updatePosition }; + return ( + this._zoomAnimated && (t.zoomanim = this._animateZoom), + ("closeOnClick" in this.options + ? this.options.closeOnClick + : this._map.options.closePopupOnClick) && (t.preclick = this._close), + this.options.keepInView && (t.moveend = this._adjustPan), + t + ); + }, + isOpen: function () { + return !!this._map && this._map.hasLayer(this); + }, + bringToFront: function () { + return this._map && o.DomUtil.toFront(this._container), this; + }, + bringToBack: function () { + return this._map && o.DomUtil.toBack(this._container), this; + }, + _close: function () { + this._map && this._map.closePopup(this); + }, + _initLayout: function () { + var t = "leaflet-popup", + e = (this._container = o.DomUtil.create( + "div", + t + + " " + + (this.options.className || "") + + " leaflet-zoom-" + + (this._zoomAnimated ? "animated" : "hide") + )); + if (this.options.closeButton) { + var i = (this._closeButton = o.DomUtil.create("a", t + "-close-button", e)); + (i.href = "#close"), + (i.innerHTML = "×"), + o.DomEvent.on(i, "click", this._onCloseButtonClick, this); + } + var n = (this._wrapper = o.DomUtil.create("div", t + "-content-wrapper", e)); + (this._contentNode = o.DomUtil.create("div", t + "-content", n)), + o.DomEvent.disableClickPropagation(n) + .disableScrollPropagation(this._contentNode) + .on(n, "contextmenu", o.DomEvent.stopPropagation), + (this._tipContainer = o.DomUtil.create("div", t + "-tip-container", e)), + (this._tip = o.DomUtil.create("div", t + "-tip", this._tipContainer)); + }, + _updateContent: function () { + if (this._content) { + var t = this._contentNode, + e = + "function" == typeof this._content + ? this._content(this._source || this) + : this._content; + if ("string" == typeof e) t.innerHTML = e; + else { + for (; t.hasChildNodes(); ) t.removeChild(t.firstChild); + t.appendChild(e); + } + this.fire("contentupdate"); + } + }, + _updateLayout: function () { + var t = this._contentNode, + e = t.style; + (e.width = ""), (e.whiteSpace = "nowrap"); + var i = t.offsetWidth; + (i = Math.min(i, this.options.maxWidth)), + (i = Math.max(i, this.options.minWidth)), + (e.width = i + 1 + "px"), + (e.whiteSpace = ""), + (e.height = ""); + var n = t.offsetHeight, + s = this.options.maxHeight, + r = "leaflet-popup-scrolled"; + s && n > s ? ((e.height = s + "px"), o.DomUtil.addClass(t, r)) : o.DomUtil.removeClass(t, r), + (this._containerWidth = this._container.offsetWidth); + }, + _updatePosition: function () { + if (this._map) { + var t = this._map.latLngToLayerPoint(this._latlng), + e = o.point(this.options.offset); + this._zoomAnimated ? o.DomUtil.setPosition(this._container, t) : (e = e.add(t)); + var i = (this._containerBottom = -e.y), + n = (this._containerLeft = -Math.round(this._containerWidth / 2) + e.x); + (this._container.style.bottom = i + "px"), (this._container.style.left = n + "px"); + } + }, + _animateZoom: function (t) { + var e = this._map._latLngToNewLayerPoint(this._latlng, t.zoom, t.center); + o.DomUtil.setPosition(this._container, e); + }, + _adjustPan: function () { + if (!(!this.options.autoPan || (this._map._panAnim && this._map._panAnim._inProgress))) { + var t = this._map, + e = this._container.offsetHeight, + i = this._containerWidth, + n = new o.Point(this._containerLeft, -e - this._containerBottom); + this._zoomAnimated && n._add(o.DomUtil.getPosition(this._container)); + var s = t.layerPointToContainerPoint(n), + r = o.point(this.options.autoPanPadding), + a = o.point(this.options.autoPanPaddingTopLeft || r), + h = o.point(this.options.autoPanPaddingBottomRight || r), + l = t.getSize(), + u = 0, + c = 0; + s.x + i + h.x > l.x && (u = s.x + i - l.x + h.x), + s.x - u - a.x < 0 && (u = s.x - a.x), + s.y + e + h.y > l.y && (c = s.y + e - l.y + h.y), + s.y - c - a.y < 0 && (c = s.y - a.y), + (u || c) && t.fire("autopanstart").panBy([u, c]); + } + }, + _onCloseButtonClick: function (t) { + this._close(), o.DomEvent.stop(t); + }, + })), + (o.popup = function (t, e) { + return new o.Popup(t, e); + }), + o.Map.include({ + openPopup: function (t, e, i) { + return ( + t instanceof o.Popup || (t = new o.Popup(i).setContent(t)), + e && t.setLatLng(e), + this.hasLayer(t) + ? this + : (this._popup && this._popup.options.autoClose && this.closePopup(), + (this._popup = t), + this.addLayer(t)) + ); + }, + closePopup: function (t) { + return ( + (t && t !== this._popup) || ((t = this._popup), (this._popup = null)), + t && this.removeLayer(t), + this + ); + }, + }), + o.Layer.include({ + bindPopup: function (t, e) { + return ( + t instanceof o.Popup + ? (o.setOptions(t, e), (this._popup = t), (t._source = this)) + : ((!this._popup || e) && (this._popup = new o.Popup(e, this)), + this._popup.setContent(t)), + this._popupHandlersAdded || + (this.on({ click: this._openPopup, remove: this.closePopup, move: this._movePopup }), + (this._popupHandlersAdded = !0)), + (this._originalPopupOffset = this._popup.options.offset), + this + ); + }, + unbindPopup: function () { + return ( + this._popup && + (this.off({ click: this._openPopup, remove: this.closePopup, move: this._movePopup }), + (this._popupHandlersAdded = !1), + (this._popup = null)), + this + ); + }, + openPopup: function (t, e) { + if ((t instanceof o.Layer || ((e = t), (t = this)), t instanceof o.FeatureGroup)) + for (var i in this._layers) { + t = this._layers[i]; + break; + } + return ( + e || (e = t.getCenter ? t.getCenter() : t.getLatLng()), + this._popup && + this._map && + ((this._popup.options.offset = this._popupAnchor(t)), + (this._popup._source = t), + this._popup.update(), + this._map.openPopup(this._popup, e)), + this + ); + }, + closePopup: function () { + return this._popup && this._popup._close(), this; + }, + togglePopup: function (t) { + return this._popup && (this._popup._map ? this.closePopup() : this.openPopup(t)), this; + }, + isPopupOpen: function () { + return this._popup.isOpen(); + }, + setPopupContent: function (t) { + return this._popup && this._popup.setContent(t), this; + }, + getPopup: function () { + return this._popup; + }, + _openPopup: function (t) { + var e = t.layer || t.target; + if (this._popup && this._map) + return e instanceof o.Path + ? void this.openPopup(t.layer || t.target, t.latlng) + : void (this._map.hasLayer(this._popup) && this._popup._source === e + ? this.closePopup() + : this.openPopup(e, t.latlng)); + }, + _popupAnchor: function (t) { + var e = t._getPopupAnchor ? t._getPopupAnchor() : [0, 0], + i = this._originalPopupOffset || o.Popup.prototype.options.offset; + return o.point(e).add(i); + }, + _movePopup: function (t) { + this._popup.setLatLng(t.latlng); + }, + }), + o.Marker.include({ + _getPopupAnchor: function () { + return this.options.icon.options.popupAnchor || [0, 0]; + }, + }), + (o.LayerGroup = o.Layer.extend({ + initialize: function (t) { + this._layers = {}; + var e, i; + if (t) for (e = 0, i = t.length; i > e; e++) this.addLayer(t[e]); + }, + addLayer: function (t) { + var e = this.getLayerId(t); + return (this._layers[e] = t), this._map && this._map.addLayer(t), this; + }, + removeLayer: function (t) { + var e = t in this._layers ? t : this.getLayerId(t); + return ( + this._map && this._layers[e] && this._map.removeLayer(this._layers[e]), + delete this._layers[e], + this + ); + }, + hasLayer: function (t) { + return !!t && (t in this._layers || this.getLayerId(t) in this._layers); + }, + clearLayers: function () { + for (var t in this._layers) this.removeLayer(this._layers[t]); + return this; + }, + invoke: function (t) { + var e, + i, + n = Array.prototype.slice.call(arguments, 1); + for (e in this._layers) (i = this._layers[e]), i[t] && i[t].apply(i, n); + return this; + }, + onAdd: function (t) { + for (var e in this._layers) t.addLayer(this._layers[e]); + }, + onRemove: function (t) { + for (var e in this._layers) t.removeLayer(this._layers[e]); + }, + eachLayer: function (t, e) { + for (var i in this._layers) t.call(e, this._layers[i]); + return this; + }, + getLayer: function (t) { + return this._layers[t]; + }, + getLayers: function () { + var t = []; + for (var e in this._layers) t.push(this._layers[e]); + return t; + }, + setZIndex: function (t) { + return this.invoke("setZIndex", t); + }, + getLayerId: function (t) { + return o.stamp(t); + }, + })), + (o.layerGroup = function (t) { + return new o.LayerGroup(t); + }), + (o.FeatureGroup = o.LayerGroup.extend({ + addLayer: function (t) { + return this.hasLayer(t) + ? this + : (t.addEventParent(this), + o.LayerGroup.prototype.addLayer.call(this, t), + this.fire("layeradd", { layer: t })); + }, + removeLayer: function (t) { + return this.hasLayer(t) + ? (t in this._layers && (t = this._layers[t]), + t.removeEventParent(this), + o.LayerGroup.prototype.removeLayer.call(this, t), + this.fire("layerremove", { layer: t })) + : this; + }, + setStyle: function (t) { + return this.invoke("setStyle", t); + }, + bringToFront: function () { + return this.invoke("bringToFront"); + }, + bringToBack: function () { + return this.invoke("bringToBack"); + }, + getBounds: function () { + var t = new o.LatLngBounds(); + for (var e in this._layers) { + var i = this._layers[e]; + t.extend(i.getBounds ? i.getBounds() : i.getLatLng()); + } + return t; + }, + })), + (o.featureGroup = function (t) { + return new o.FeatureGroup(t); + }), + (o.Renderer = o.Layer.extend({ + options: { padding: 0.1 }, + initialize: function (t) { + o.setOptions(this, t), o.stamp(this); + }, + onAdd: function () { + this._container || + (this._initContainer(), + this._zoomAnimated && o.DomUtil.addClass(this._container, "leaflet-zoom-animated")), + this.getPane().appendChild(this._container), + this._update(); + }, + onRemove: function () { + o.DomUtil.remove(this._container); + }, + getEvents: function () { + var t = { + viewreset: this._reset, + zoomstart: this._onZoomStart, + zoom: this._onZoom, + moveend: this._update, + }; + return this._zoomAnimated && (t.zoomanim = this._onAnimZoom), t; + }, + _onAnimZoom: function (t) { + this._updateTransform(t.center, t.zoom); + }, + _onZoom: function () { + this._updateTransform(this._map.getCenter(), this._map.getZoom()); + }, + _onZoomStart: function () { + this._update(); + }, + _updateTransform: function (t, e) { + var i = this._map.getZoomScale(e, this._zoom), + n = o.DomUtil.getPosition(this._container), + s = this._map.getSize().multiplyBy(0.5 + this.options.padding), + r = this._map.project(this._center, e), + a = this._map.project(t, e), + h = a.subtract(r), + l = s.multiplyBy(-i).add(n).add(s).subtract(h); + o.DomUtil.setTransform(this._container, l, i); + }, + _reset: function () { + this._update(), this._updateTransform(this._center, this._zoom); + }, + _update: function () { + var t = this.options.padding, + e = this._map.getSize(), + i = this._map.containerPointToLayerPoint(e.multiplyBy(-t)).round(); + (this._bounds = new o.Bounds(i, i.add(e.multiplyBy(1 + 2 * t)).round())), + (this._center = this._map.getCenter()), + (this._zoom = this._map.getZoom()); + }, + })), + o.Map.include({ + getRenderer: function (t) { + var e = + t.options.renderer || + this._getPaneRenderer(t.options.pane) || + this.options.renderer || + this._renderer; + return ( + e || (e = this._renderer = (this.options.preferCanvas && o.canvas()) || o.svg()), + this.hasLayer(e) || this.addLayer(e), + e + ); + }, + _getPaneRenderer: function (t) { + if ("overlayPane" === t || t === i) return !1; + var e = this._paneRenderers[t]; + return ( + e === i && + ((e = (o.SVG && o.svg({ pane: t })) || (o.Canvas && o.canvas({ pane: t }))), + (this._paneRenderers[t] = e)), + e + ); + }, + }), + (o.Path = o.Layer.extend({ + options: { + stroke: !0, + color: "#3388ff", + weight: 3, + opacity: 1, + lineCap: "round", + lineJoin: "round", + fillOpacity: 0.2, + fillRule: "evenodd", + interactive: !0, + }, + beforeAdd: function (t) { + this._renderer = t.getRenderer(this); + }, + onAdd: function () { + this._renderer._initPath(this), this._reset(), this._renderer._addPath(this); + }, + onRemove: function () { + this._renderer._removePath(this); + }, + getEvents: function () { + return { zoomend: this._project, moveend: this._update, viewreset: this._reset }; + }, + redraw: function () { + return this._map && this._renderer._updatePath(this), this; + }, + setStyle: function (t) { + return o.setOptions(this, t), this._renderer && this._renderer._updateStyle(this), this; + }, + bringToFront: function () { + return this._renderer && this._renderer._bringToFront(this), this; + }, + bringToBack: function () { + return this._renderer && this._renderer._bringToBack(this), this; + }, + getElement: function () { + return this._path; + }, + _reset: function () { + this._project(), this._update(); + }, + _clickTolerance: function () { + return (this.options.stroke ? this.options.weight / 2 : 0) + (o.Browser.touch ? 10 : 0); + }, + })), + (o.LineUtil = { + simplify: function (t, e) { + if (!e || !t.length) return t.slice(); + var i = e * e; + return (t = this._reducePoints(t, i)), (t = this._simplifyDP(t, i)); + }, + pointToSegmentDistance: function (t, e, i) { + return Math.sqrt(this._sqClosestPointOnSegment(t, e, i, !0)); + }, + closestPointOnSegment: function (t, e, i) { + return this._sqClosestPointOnSegment(t, e, i); + }, + _simplifyDP: function (t, e) { + var n = t.length, + o = typeof Uint8Array != i + "" ? Uint8Array : Array, + s = new o(n); + (s[0] = s[n - 1] = 1), this._simplifyDPStep(t, s, e, 0, n - 1); + var r, + a = []; + for (r = 0; n > r; r++) s[r] && a.push(t[r]); + return a; + }, + _simplifyDPStep: function (t, e, i, n, o) { + var s, + r, + a, + h = 0; + for (r = n + 1; o - 1 >= r; r++) + (a = this._sqClosestPointOnSegment(t[r], t[n], t[o], !0)), a > h && ((s = r), (h = a)); + h > i && + ((e[s] = 1), this._simplifyDPStep(t, e, i, n, s), this._simplifyDPStep(t, e, i, s, o)); + }, + _reducePoints: function (t, e) { + for (var i = [t[0]], n = 1, o = 0, s = t.length; s > n; n++) + this._sqDist(t[n], t[o]) > e && (i.push(t[n]), (o = n)); + return s - 1 > o && i.push(t[s - 1]), i; + }, + clipSegment: function (t, e, i, n, o) { + var s, + r, + a, + h = n ? this._lastCode : this._getBitCode(t, i), + l = this._getBitCode(e, i); + for (this._lastCode = l; ; ) { + if (!(h | l)) return [t, e]; + if (h & l) return !1; + (s = h || l), + (r = this._getEdgeIntersection(t, e, s, i, o)), + (a = this._getBitCode(r, i)), + s === h ? ((t = r), (h = a)) : ((e = r), (l = a)); + } + }, + _getEdgeIntersection: function (t, e, i, n, s) { + var r, + a, + h = e.x - t.x, + l = e.y - t.y, + u = n.min, + c = n.max; + return ( + 8 & i + ? ((r = t.x + (h * (c.y - t.y)) / l), (a = c.y)) + : 4 & i + ? ((r = t.x + (h * (u.y - t.y)) / l), (a = u.y)) + : 2 & i + ? ((r = c.x), (a = t.y + (l * (c.x - t.x)) / h)) + : 1 & i && ((r = u.x), (a = t.y + (l * (u.x - t.x)) / h)), + new o.Point(r, a, s) + ); + }, + _getBitCode: function (t, e) { + var i = 0; + return ( + t.x < e.min.x ? (i |= 1) : t.x > e.max.x && (i |= 2), + t.y < e.min.y ? (i |= 4) : t.y > e.max.y && (i |= 8), + i + ); + }, + _sqDist: function (t, e) { + var i = e.x - t.x, + n = e.y - t.y; + return i * i + n * n; + }, + _sqClosestPointOnSegment: function (t, e, i, n) { + var s, + r = e.x, + a = e.y, + h = i.x - r, + l = i.y - a, + u = h * h + l * l; + return ( + u > 0 && + ((s = ((t.x - r) * h + (t.y - a) * l) / u), + s > 1 ? ((r = i.x), (a = i.y)) : s > 0 && ((r += h * s), (a += l * s))), + (h = t.x - r), + (l = t.y - a), + n ? h * h + l * l : new o.Point(r, a) + ); + }, + }), + (o.Polyline = o.Path.extend({ + options: { smoothFactor: 1 }, + initialize: function (t, e) { + o.setOptions(this, e), this._setLatLngs(t); + }, + getLatLngs: function () { + return this._latlngs; + }, + setLatLngs: function (t) { + return this._setLatLngs(t), this.redraw(); + }, + isEmpty: function () { + return !this._latlngs.length; + }, + closestLayerPoint: function (t) { + for ( + var e, + i, + n = 1 / 0, + s = null, + r = o.LineUtil._sqClosestPointOnSegment, + a = 0, + h = this._parts.length; + h > a; + a++ + ) + for (var l = this._parts[a], u = 1, c = l.length; c > u; u++) { + (e = l[u - 1]), (i = l[u]); + var d = r(t, e, i, !0); + n > d && ((n = d), (s = r(t, e, i))); + } + return s && (s.distance = Math.sqrt(n)), s; + }, + getCenter: function () { + var t, + e, + i, + n, + o, + s, + r, + a = this._rings[0], + h = a.length; + if (!h) return null; + for (t = 0, e = 0; h - 1 > t; t++) e += a[t].distanceTo(a[t + 1]) / 2; + if (0 === e) return this._map.layerPointToLatLng(a[0]); + for (t = 0, n = 0; h - 1 > t; t++) + if (((o = a[t]), (s = a[t + 1]), (i = o.distanceTo(s)), (n += i), n > e)) + return ( + (r = (n - e) / i), + this._map.layerPointToLatLng([s.x - r * (s.x - o.x), s.y - r * (s.y - o.y)]) + ); + }, + getBounds: function () { + return this._bounds; + }, + addLatLng: function (t, e) { + return ( + (e = e || this._defaultShape()), + (t = o.latLng(t)), + e.push(t), + this._bounds.extend(t), + this.redraw() + ); + }, + _setLatLngs: function (t) { + (this._bounds = new o.LatLngBounds()), (this._latlngs = this._convertLatLngs(t)); + }, + _defaultShape: function () { + return o.Polyline._flat(this._latlngs) ? this._latlngs : this._latlngs[0]; + }, + _convertLatLngs: function (t) { + for (var e = [], i = o.Polyline._flat(t), n = 0, s = t.length; s > n; n++) + i + ? ((e[n] = o.latLng(t[n])), this._bounds.extend(e[n])) + : (e[n] = this._convertLatLngs(t[n])); + return e; + }, + _project: function () { + (this._rings = []), this._projectLatlngs(this._latlngs, this._rings); + var t = this._clickTolerance(), + e = new o.Point(t, -t); + this._bounds.isValid() && + (this._pxBounds = new o.Bounds( + this._map.latLngToLayerPoint(this._bounds.getSouthWest())._subtract(e), + this._map.latLngToLayerPoint(this._bounds.getNorthEast())._add(e) + )); + }, + _projectLatlngs: function (t, e) { + var i, + n, + s = t[0] instanceof o.LatLng, + r = t.length; + if (s) { + for (n = [], i = 0; r > i; i++) n[i] = this._map.latLngToLayerPoint(t[i]); + e.push(n); + } else for (i = 0; r > i; i++) this._projectLatlngs(t[i], e); + }, + _clipPoints: function () { + var t = this._renderer._bounds; + if (((this._parts = []), this._pxBounds && this._pxBounds.intersects(t))) { + if (this.options.noClip) return void (this._parts = this._rings); + var e, + i, + n, + s, + r, + a, + h, + l = this._parts; + for (e = 0, n = 0, s = this._rings.length; s > e; e++) + for (h = this._rings[e], i = 0, r = h.length; r - 1 > i; i++) + (a = o.LineUtil.clipSegment(h[i], h[i + 1], t, i, !0)), + a && + ((l[n] = l[n] || []), + l[n].push(a[0]), + (a[1] !== h[i + 1] || i === r - 2) && (l[n].push(a[1]), n++)); + } + }, + _simplifyPoints: function () { + for (var t = this._parts, e = this.options.smoothFactor, i = 0, n = t.length; n > i; i++) + t[i] = o.LineUtil.simplify(t[i], e); + }, + _update: function () { + this._map && (this._clipPoints(), this._simplifyPoints(), this._updatePath()); + }, + _updatePath: function () { + this._renderer._updatePoly(this); + }, + })), + (o.polyline = function (t, e) { + return new o.Polyline(t, e); + }), + (o.Polyline._flat = function (t) { + return !o.Util.isArray(t[0]) || ("object" != typeof t[0][0] && "undefined" != typeof t[0][0]); + }), + (o.PolyUtil = {}), + (o.PolyUtil.clipPolygon = function (t, e, i) { + var n, + s, + r, + a, + h, + l, + u, + c, + d, + _ = [1, 4, 2, 8], + m = o.LineUtil; + for (s = 0, u = t.length; u > s; s++) t[s]._code = m._getBitCode(t[s], e); + for (a = 0; 4 > a; a++) { + for (c = _[a], n = [], s = 0, u = t.length, r = u - 1; u > s; r = s++) + (h = t[s]), + (l = t[r]), + h._code & c + ? l._code & c || + ((d = m._getEdgeIntersection(l, h, c, e, i)), + (d._code = m._getBitCode(d, e)), + n.push(d)) + : (l._code & c && + ((d = m._getEdgeIntersection(l, h, c, e, i)), + (d._code = m._getBitCode(d, e)), + n.push(d)), + n.push(h)); + t = n; + } + return t; + }), + (o.Polygon = o.Polyline.extend({ + options: { fill: !0 }, + isEmpty: function () { + return !this._latlngs.length || !this._latlngs[0].length; + }, + getCenter: function () { + var t, + e, + i, + n, + o, + s, + r, + a, + h, + l = this._rings[0], + u = l.length; + if (!u) return null; + for (s = r = a = 0, t = 0, e = u - 1; u > t; e = t++) + (i = l[t]), + (n = l[e]), + (o = i.y * n.x - n.y * i.x), + (r += (i.x + n.x) * o), + (a += (i.y + n.y) * o), + (s += 3 * o); + return (h = 0 === s ? l[0] : [r / s, a / s]), this._map.layerPointToLatLng(h); + }, + _convertLatLngs: function (t) { + var e = o.Polyline.prototype._convertLatLngs.call(this, t), + i = e.length; + return i >= 2 && e[0] instanceof o.LatLng && e[0].equals(e[i - 1]) && e.pop(), e; + }, + _setLatLngs: function (t) { + o.Polyline.prototype._setLatLngs.call(this, t), + o.Polyline._flat(this._latlngs) && (this._latlngs = [this._latlngs]); + }, + _defaultShape: function () { + return o.Polyline._flat(this._latlngs[0]) ? this._latlngs[0] : this._latlngs[0][0]; + }, + _clipPoints: function () { + var t = this._renderer._bounds, + e = this.options.weight, + i = new o.Point(e, e); + if ( + ((t = new o.Bounds(t.min.subtract(i), t.max.add(i))), + (this._parts = []), + this._pxBounds && this._pxBounds.intersects(t)) + ) { + if (this.options.noClip) return void (this._parts = this._rings); + for (var n, s = 0, r = this._rings.length; r > s; s++) + (n = o.PolyUtil.clipPolygon(this._rings[s], t, !0)), n.length && this._parts.push(n); + } + }, + _updatePath: function () { + this._renderer._updatePoly(this, !0); + }, + })), + (o.polygon = function (t, e) { + return new o.Polygon(t, e); + }), + (o.Rectangle = o.Polygon.extend({ + initialize: function (t, e) { + o.Polygon.prototype.initialize.call(this, this._boundsToLatLngs(t), e); + }, + setBounds: function (t) { + return this.setLatLngs(this._boundsToLatLngs(t)); + }, + _boundsToLatLngs: function (t) { + return ( + (t = o.latLngBounds(t)), + [t.getSouthWest(), t.getNorthWest(), t.getNorthEast(), t.getSouthEast()] + ); + }, + })), + (o.rectangle = function (t, e) { + return new o.Rectangle(t, e); + }), + (o.CircleMarker = o.Path.extend({ + options: { fill: !0, radius: 10 }, + initialize: function (t, e) { + o.setOptions(this, e), (this._latlng = o.latLng(t)), (this._radius = this.options.radius); + }, + setLatLng: function (t) { + return ( + (this._latlng = o.latLng(t)), this.redraw(), this.fire("move", { latlng: this._latlng }) + ); + }, + getLatLng: function () { + return this._latlng; + }, + setRadius: function (t) { + return (this.options.radius = this._radius = t), this.redraw(); + }, + getRadius: function () { + return this._radius; + }, + setStyle: function (t) { + var e = (t && t.radius) || this._radius; + return o.Path.prototype.setStyle.call(this, t), this.setRadius(e), this; + }, + _project: function () { + (this._point = this._map.latLngToLayerPoint(this._latlng)), this._updateBounds(); + }, + _updateBounds: function () { + var t = this._radius, + e = this._radiusY || t, + i = this._clickTolerance(), + n = [t + i, e + i]; + this._pxBounds = new o.Bounds(this._point.subtract(n), this._point.add(n)); + }, + _update: function () { + this._map && this._updatePath(); + }, + _updatePath: function () { + this._renderer._updateCircle(this); + }, + _empty: function () { + return this._radius && !this._renderer._bounds.intersects(this._pxBounds); + }, + })), + (o.circleMarker = function (t, e) { + return new o.CircleMarker(t, e); + }), + (o.Circle = o.CircleMarker.extend({ + initialize: function (t, e) { + o.setOptions(this, e), (this._latlng = o.latLng(t)), (this._mRadius = this.options.radius); + }, + setRadius: function (t) { + return (this._mRadius = t), this.redraw(); + }, + getRadius: function () { + return this._mRadius; + }, + getBounds: function () { + var t = [this._radius, this._radiusY || this._radius]; + return new o.LatLngBounds( + this._map.layerPointToLatLng(this._point.subtract(t)), + this._map.layerPointToLatLng(this._point.add(t)) + ); + }, + setStyle: o.Path.prototype.setStyle, + _project: function () { + var t = this._latlng.lng, + e = this._latlng.lat, + i = this._map, + n = i.options.crs; + if (n.distance === o.CRS.Earth.distance) { + var s = Math.PI / 180, + r = this._mRadius / o.CRS.Earth.R / s, + a = i.project([e + r, t]), + h = i.project([e - r, t]), + l = a.add(h).divideBy(2), + u = i.unproject(l).lat, + c = + Math.acos( + (Math.cos(r * s) - Math.sin(e * s) * Math.sin(u * s)) / + (Math.cos(e * s) * Math.cos(u * s)) + ) / s; + (this._point = l.subtract(i.getPixelOrigin())), + (this._radius = isNaN(c) + ? 0 + : Math.max(Math.round(l.x - i.project([u, t - c]).x), 1)), + (this._radiusY = Math.max(Math.round(l.y - a.y), 1)); + } else { + var d = n.unproject(n.project(this._latlng).subtract([this._mRadius, 0])); + (this._point = i.latLngToLayerPoint(this._latlng)), + (this._radius = this._point.x - i.latLngToLayerPoint(d).x); + } + this._updateBounds(); + }, + })), + (o.circle = function (t, e, i) { + return "number" == typeof e && (e = o.extend({}, i, { radius: e })), new o.Circle(t, e); + }), + (o.SVG = o.Renderer.extend({ + _initContainer: function () { + (this._container = o.SVG.create("svg")), + this._container.setAttribute("pointer-events", "none"), + (this._rootGroup = o.SVG.create("g")), + this._container.appendChild(this._rootGroup); + }, + _update: function () { + if (!this._map._animatingZoom || !this._bounds) { + o.Renderer.prototype._update.call(this); + var t = this._bounds, + e = t.getSize(), + i = this._container; + (this._svgSize && this._svgSize.equals(e)) || + ((this._svgSize = e), i.setAttribute("width", e.x), i.setAttribute("height", e.y)), + o.DomUtil.setPosition(i, t.min), + i.setAttribute("viewBox", [t.min.x, t.min.y, e.x, e.y].join(" ")); + } + }, + _initPath: function (t) { + var e = (t._path = o.SVG.create("path")); + t.options.className && o.DomUtil.addClass(e, t.options.className), + t.options.interactive && o.DomUtil.addClass(e, "leaflet-interactive"), + this._updateStyle(t); + }, + _addPath: function (t) { + this._rootGroup.appendChild(t._path), t.addInteractiveTarget(t._path); + }, + _removePath: function (t) { + o.DomUtil.remove(t._path), t.removeInteractiveTarget(t._path); + }, + _updatePath: function (t) { + t._project(), t._update(); + }, + _updateStyle: function (t) { + var e = t._path, + i = t.options; + e && + (i.stroke + ? (e.setAttribute("stroke", i.color), + e.setAttribute("stroke-opacity", i.opacity), + e.setAttribute("stroke-width", i.weight), + e.setAttribute("stroke-linecap", i.lineCap), + e.setAttribute("stroke-linejoin", i.lineJoin), + i.dashArray + ? e.setAttribute("stroke-dasharray", i.dashArray) + : e.removeAttribute("stroke-dasharray"), + i.dashOffset + ? e.setAttribute("stroke-dashoffset", i.dashOffset) + : e.removeAttribute("stroke-dashoffset")) + : e.setAttribute("stroke", "none"), + i.fill + ? (e.setAttribute("fill", i.fillColor || i.color), + e.setAttribute("fill-opacity", i.fillOpacity), + e.setAttribute("fill-rule", i.fillRule || "evenodd")) + : e.setAttribute("fill", "none"), + e.setAttribute( + "pointer-events", + i.pointerEvents || (i.interactive ? "visiblePainted" : "none") + )); + }, + _updatePoly: function (t, e) { + this._setPath(t, o.SVG.pointsToPath(t._parts, e)); + }, + _updateCircle: function (t) { + var e = t._point, + i = t._radius, + n = t._radiusY || i, + o = "a" + i + "," + n + " 0 1,0 ", + s = t._empty() + ? "M0 0" + : "M" + (e.x - i) + "," + e.y + o + 2 * i + ",0 " + o + 2 * -i + ",0 "; + this._setPath(t, s); + }, + _setPath: function (t, e) { + t._path.setAttribute("d", e); + }, + _bringToFront: function (t) { + o.DomUtil.toFront(t._path); + }, + _bringToBack: function (t) { + o.DomUtil.toBack(t._path); + }, + })), + o.extend(o.SVG, { + create: function (t) { + return e.createElementNS("http://www.w3.org/2000/svg", t); + }, + pointsToPath: function (t, e) { + var i, + n, + s, + r, + a, + h, + l = ""; + for (i = 0, s = t.length; s > i; i++) { + for (a = t[i], n = 0, r = a.length; r > n; n++) + (h = a[n]), (l += (n ? "L" : "M") + h.x + " " + h.y); + l += e ? (o.Browser.svg ? "z" : "x") : ""; + } + return l || "M0 0"; + }, + }), + (o.Browser.svg = !(!e.createElementNS || !o.SVG.create("svg").createSVGRect)), + (o.svg = function (t) { + return o.Browser.svg || o.Browser.vml ? new o.SVG(t) : null; + }), + (o.Browser.vml = + !o.Browser.svg && + (function () { + try { + var t = e.createElement("div"); + t.innerHTML = ''; + var i = t.firstChild; + return (i.style.behavior = "url(#default#VML)"), i && "object" == typeof i.adj; + } catch (n) { + return !1; + } + })()), + o.SVG.include( + o.Browser.vml + ? { + _initContainer: function () { + this._container = o.DomUtil.create("div", "leaflet-vml-container"); + }, + _update: function () { + this._map._animatingZoom || o.Renderer.prototype._update.call(this); + }, + _initPath: function (t) { + var e = (t._container = o.SVG.create("shape")); + o.DomUtil.addClass(e, "leaflet-vml-shape " + (this.options.className || "")), + (e.coordsize = "1 1"), + (t._path = o.SVG.create("path")), + e.appendChild(t._path), + this._updateStyle(t); + }, + _addPath: function (t) { + var e = t._container; + this._container.appendChild(e), + t.options.interactive && t.addInteractiveTarget(e); + }, + _removePath: function (t) { + var e = t._container; + o.DomUtil.remove(e), t.removeInteractiveTarget(e); + }, + _updateStyle: function (t) { + var e = t._stroke, + i = t._fill, + n = t.options, + s = t._container; + (s.stroked = !!n.stroke), + (s.filled = !!n.fill), + n.stroke + ? (e || (e = t._stroke = o.SVG.create("stroke")), + s.appendChild(e), + (e.weight = n.weight + "px"), + (e.color = n.color), + (e.opacity = n.opacity), + n.dashArray + ? (e.dashStyle = o.Util.isArray(n.dashArray) + ? n.dashArray.join(" ") + : n.dashArray.replace(/( *, *)/g, " ")) + : (e.dashStyle = ""), + (e.endcap = n.lineCap.replace("butt", "flat")), + (e.joinstyle = n.lineJoin)) + : e && (s.removeChild(e), (t._stroke = null)), + n.fill + ? (i || (i = t._fill = o.SVG.create("fill")), + s.appendChild(i), + (i.color = n.fillColor || n.color), + (i.opacity = n.fillOpacity)) + : i && (s.removeChild(i), (t._fill = null)); + }, + _updateCircle: function (t) { + var e = t._point.round(), + i = Math.round(t._radius), + n = Math.round(t._radiusY || i); + this._setPath( + t, + t._empty() + ? "M0 0" + : "AL " + e.x + "," + e.y + " " + i + "," + n + " 0,23592600" + ); + }, + _setPath: function (t, e) { + t._path.v = e; + }, + _bringToFront: function (t) { + o.DomUtil.toFront(t._container); + }, + _bringToBack: function (t) { + o.DomUtil.toBack(t._container); + }, + } + : {} + ), + o.Browser.vml && + (o.SVG.create = (function () { + try { + return ( + e.namespaces.add("lvml", "urn:schemas-microsoft-com:vml"), + function (t) { + return e.createElement("'); + } + ); + } catch (t) { + return function (t) { + return e.createElement( + "<" + t + ' xmlns="urn:schemas-microsoft.com:vml" class="lvml">' + ); + }; + } + })()), + (o.Canvas = o.Renderer.extend({ + onAdd: function () { + o.Renderer.prototype.onAdd.call(this), (this._layers = this._layers || {}), this._draw(); + }, + _initContainer: function () { + var t = (this._container = e.createElement("canvas")); + o.DomEvent.on(t, "mousemove", o.Util.throttle(this._onMouseMove, 32, this), this) + .on(t, "click dblclick mousedown mouseup contextmenu", this._onClick, this) + .on(t, "mouseout", this._handleMouseOut, this), + (this._ctx = t.getContext("2d")); + }, + _update: function () { + if (!this._map._animatingZoom || !this._bounds) { + (this._drawnLayers = {}), o.Renderer.prototype._update.call(this); + var t = this._bounds, + e = this._container, + i = t.getSize(), + n = o.Browser.retina ? 2 : 1; + o.DomUtil.setPosition(e, t.min), + (e.width = n * i.x), + (e.height = n * i.y), + (e.style.width = i.x + "px"), + (e.style.height = i.y + "px"), + o.Browser.retina && this._ctx.scale(2, 2), + this._ctx.translate(-t.min.x, -t.min.y); + } + }, + _initPath: function (t) { + this._layers[o.stamp(t)] = t; + }, + _addPath: o.Util.falseFn, + _removePath: function (t) { + (t._removed = !0), this._requestRedraw(t); + }, + _updatePath: function (t) { + (this._redrawBounds = t._pxBounds), + this._draw(!0), + t._project(), + t._update(), + this._draw(), + (this._redrawBounds = null); + }, + _updateStyle: function (t) { + this._requestRedraw(t); + }, + _requestRedraw: function (t) { + if (this._map) { + var e = (t.options.weight || 0) + 1; + (this._redrawBounds = this._redrawBounds || new o.Bounds()), + this._redrawBounds.extend(t._pxBounds.min.subtract([e, e])), + this._redrawBounds.extend(t._pxBounds.max.add([e, e])), + (this._redrawRequest = + this._redrawRequest || o.Util.requestAnimFrame(this._redraw, this)); + } + }, + _redraw: function () { + (this._redrawRequest = null), this._draw(!0), this._draw(), (this._redrawBounds = null); + }, + _draw: function (t) { + this._clear = t; + var e, + i = this._redrawBounds; + this._ctx.save(), + i && + (this._ctx.beginPath(), + this._ctx.rect(i.min.x, i.min.y, i.max.x - i.min.x, i.max.y - i.min.y), + this._ctx.clip()); + for (var n in this._layers) + (e = this._layers[n]), + (!i || e._pxBounds.intersects(i)) && e._updatePath(), + t && e._removed && (delete e._removed, delete this._layers[n]); + this._ctx.restore(); + }, + _updatePoly: function (t, e) { + var i, + n, + o, + s, + r = t._parts, + a = r.length, + h = this._ctx; + if (a) { + for (this._drawnLayers[t._leaflet_id] = t, h.beginPath(), i = 0; a > i; i++) { + for (n = 0, o = r[i].length; o > n; n++) + (s = r[i][n]), h[n ? "lineTo" : "moveTo"](s.x, s.y); + e && h.closePath(); + } + this._fillStroke(h, t); + } + }, + _updateCircle: function (t) { + if (!t._empty()) { + var e = t._point, + i = this._ctx, + n = t._radius, + o = (t._radiusY || n) / n; + 1 !== o && (i.save(), i.scale(1, o)), + i.beginPath(), + i.arc(e.x, e.y / o, n, 0, 2 * Math.PI, !1), + 1 !== o && i.restore(), + this._fillStroke(i, t); + } + }, + _fillStroke: function (t, e) { + var i = this._clear, + n = e.options; + (t.globalCompositeOperation = i ? "destination-out" : "source-over"), + n.fill && + ((t.globalAlpha = i ? 1 : n.fillOpacity), + (t.fillStyle = n.fillColor || n.color), + t.fill(n.fillRule || "evenodd")), + n.stroke && + 0 !== n.weight && + ((t.globalAlpha = i ? 1 : n.opacity), + (e._prevWeight = t.lineWidth = i ? e._prevWeight + 1 : n.weight), + (t.strokeStyle = n.color), + (t.lineCap = n.lineCap), + (t.lineJoin = n.lineJoin), + t.stroke()); + }, + _onClick: function (t) { + var e = this._map.mouseEventToLayerPoint(t), + i = []; + for (var n in this._layers) + this._layers[n]._containsPoint(e) && (o.DomEvent._fakeStop(t), i.push(this._layers[n])); + i.length && this._fireEvent(i, t); + }, + _onMouseMove: function (t) { + if (this._map && !this._map.dragging._draggable._moving && !this._map._animatingZoom) { + var e = this._map.mouseEventToLayerPoint(t); + this._handleMouseOut(t, e), this._handleMouseHover(t, e); + } + }, + _handleMouseOut: function (t, e) { + var i = this._hoveredLayer; + !i || + ("mouseout" !== t.type && i._containsPoint(e)) || + (o.DomUtil.removeClass(this._container, "leaflet-interactive"), + this._fireEvent([i], t, "mouseout"), + (this._hoveredLayer = null)); + }, + _handleMouseHover: function (t, e) { + var i, n; + if (!this._hoveredLayer) + for (i in this._drawnLayers) + if (((n = this._drawnLayers[i]), n.options.interactive && n._containsPoint(e))) { + o.DomUtil.addClass(this._container, "leaflet-interactive"), + this._fireEvent([n], t, "mouseover"), + (this._hoveredLayer = n); + break; + } + this._hoveredLayer && this._fireEvent([this._hoveredLayer], t); + }, + _fireEvent: function (t, e, i) { + this._map._fireDOMEvent(e, i || e.type, t); + }, + _bringToFront: o.Util.falseFn, + _bringToBack: o.Util.falseFn, + })), + (o.Browser.canvas = (function () { + return !!e.createElement("canvas").getContext; + })()), + (o.canvas = function (t) { + return o.Browser.canvas ? new o.Canvas(t) : null; + }), + (o.Polyline.prototype._containsPoint = function (t, e) { + var i, + n, + s, + r, + a, + h, + l = this._clickTolerance(); + if (!this._pxBounds.contains(t)) return !1; + for (i = 0, r = this._parts.length; r > i; i++) + for (h = this._parts[i], n = 0, a = h.length, s = a - 1; a > n; s = n++) + if ((e || 0 !== n) && o.LineUtil.pointToSegmentDistance(t, h[s], h[n]) <= l) return !0; + return !1; + }), + (o.Polygon.prototype._containsPoint = function (t) { + var e, + i, + n, + s, + r, + a, + h, + l, + u = !1; + if (!this._pxBounds.contains(t)) return !1; + for (s = 0, h = this._parts.length; h > s; s++) + for (e = this._parts[s], r = 0, l = e.length, a = l - 1; l > r; a = r++) + (i = e[r]), + (n = e[a]), + i.y > t.y != n.y > t.y && + t.x < ((n.x - i.x) * (t.y - i.y)) / (n.y - i.y) + i.x && + (u = !u); + return u || o.Polyline.prototype._containsPoint.call(this, t, !0); + }), + (o.CircleMarker.prototype._containsPoint = function (t) { + return t.distanceTo(this._point) <= this._radius + this._clickTolerance(); + }), + (o.GeoJSON = o.FeatureGroup.extend({ + initialize: function (t, e) { + o.setOptions(this, e), (this._layers = {}), t && this.addData(t); + }, + addData: function (t) { + var e, + i, + n, + s = o.Util.isArray(t) ? t : t.features; + if (s) { + for (e = 0, i = s.length; i > e; e++) + (n = s[e]), + (n.geometries || n.geometry || n.features || n.coordinates) && this.addData(n); + return this; + } + var r = this.options; + if (r.filter && !r.filter(t)) return this; + var a = o.GeoJSON.geometryToLayer(t, r); + return a + ? ((a.feature = o.GeoJSON.asFeature(t)), + (a.defaultOptions = a.options), + this.resetStyle(a), + r.onEachFeature && r.onEachFeature(t, a), + this.addLayer(a)) + : this; + }, + resetStyle: function (t) { + return (t.options = t.defaultOptions), this._setLayerStyle(t, this.options.style), this; + }, + setStyle: function (t) { + return this.eachLayer(function (e) { + this._setLayerStyle(e, t); + }, this); + }, + _setLayerStyle: function (t, e) { + "function" == typeof e && (e = e(t.feature)), t.setStyle && t.setStyle(e); + }, + })), + o.extend(o.GeoJSON, { + geometryToLayer: function (t, e) { + var i, + n, + s, + r, + a = "Feature" === t.type ? t.geometry : t, + h = a ? a.coordinates : null, + l = [], + u = e && e.pointToLayer, + c = (e && e.coordsToLatLng) || this.coordsToLatLng; + if (!h && !a) return null; + switch (a.type) { + case "Point": + return (i = c(h)), u ? u(t, i) : new o.Marker(i); + case "MultiPoint": + for (s = 0, r = h.length; r > s; s++) + (i = c(h[s])), l.push(u ? u(t, i) : new o.Marker(i)); + return new o.FeatureGroup(l); + case "LineString": + case "MultiLineString": + return ( + (n = this.coordsToLatLngs(h, "LineString" === a.type ? 0 : 1, c)), + new o.Polyline(n, e) + ); + case "Polygon": + case "MultiPolygon": + return ( + (n = this.coordsToLatLngs(h, "Polygon" === a.type ? 1 : 2, c)), + new o.Polygon(n, e) + ); + case "GeometryCollection": + for (s = 0, r = a.geometries.length; r > s; s++) { + var d = this.geometryToLayer( + { geometry: a.geometries[s], type: "Feature", properties: t.properties }, + e + ); + d && l.push(d); + } + return new o.FeatureGroup(l); + default: + throw new Error("Invalid GeoJSON object."); + } + }, + coordsToLatLng: function (t) { + return new o.LatLng(t[1], t[0], t[2]); + }, + coordsToLatLngs: function (t, e, i) { + for (var n, o = [], s = 0, r = t.length; r > s; s++) + (n = e ? this.coordsToLatLngs(t[s], e - 1, i) : (i || this.coordsToLatLng)(t[s])), + o.push(n); + return o; + }, + latLngToCoords: function (t) { + return t.alt !== i ? [t.lng, t.lat, t.alt] : [t.lng, t.lat]; + }, + latLngsToCoords: function (t, e, i) { + for (var n = [], s = 0, r = t.length; r > s; s++) + n.push(e ? o.GeoJSON.latLngsToCoords(t[s], e - 1, i) : o.GeoJSON.latLngToCoords(t[s])); + return !e && i && n.push(n[0]), n; + }, + getFeature: function (t, e) { + return t.feature ? o.extend({}, t.feature, { geometry: e }) : o.GeoJSON.asFeature(e); + }, + asFeature: function (t) { + return "Feature" === t.type ? t : { type: "Feature", properties: {}, geometry: t }; + }, + }); + var r = { + toGeoJSON: function () { + return o.GeoJSON.getFeature(this, { + type: "Point", + coordinates: o.GeoJSON.latLngToCoords(this.getLatLng()), + }); + }, + }; + o.Marker.include(r), + o.Circle.include(r), + o.CircleMarker.include(r), + (o.Polyline.prototype.toGeoJSON = function () { + var t = !o.Polyline._flat(this._latlngs), + e = o.GeoJSON.latLngsToCoords(this._latlngs, t ? 1 : 0); + return o.GeoJSON.getFeature(this, { type: (t ? "Multi" : "") + "LineString", coordinates: e }); + }), + (o.Polygon.prototype.toGeoJSON = function () { + var t = !o.Polyline._flat(this._latlngs), + e = t && !o.Polyline._flat(this._latlngs[0]), + i = o.GeoJSON.latLngsToCoords(this._latlngs, e ? 2 : t ? 1 : 0, !0); + return ( + t || (i = [i]), + o.GeoJSON.getFeature(this, { type: (e ? "Multi" : "") + "Polygon", coordinates: i }) + ); + }), + o.LayerGroup.include({ + toMultiPoint: function () { + var t = []; + return ( + this.eachLayer(function (e) { + t.push(e.toGeoJSON().geometry.coordinates); + }), + o.GeoJSON.getFeature(this, { type: "MultiPoint", coordinates: t }) + ); + }, + toGeoJSON: function () { + var t = this.feature && this.feature.geometry && this.feature.geometry.type; + if ("MultiPoint" === t) return this.toMultiPoint(); + var e = "GeometryCollection" === t, + i = []; + return ( + this.eachLayer(function (t) { + if (t.toGeoJSON) { + var n = t.toGeoJSON(); + i.push(e ? n.geometry : o.GeoJSON.asFeature(n)); + } + }), + e + ? o.GeoJSON.getFeature(this, { geometries: i, type: "GeometryCollection" }) + : { type: "FeatureCollection", features: i } + ); + }, + }), + (o.geoJson = function (t, e) { + return new o.GeoJSON(t, e); + }); + var a = "_leaflet_events"; + (o.DomEvent = { + on: function (t, e, i, n) { + if ("object" == typeof e) for (var s in e) this._on(t, s, e[s], i); + else { + e = o.Util.splitWords(e); + for (var r = 0, a = e.length; a > r; r++) this._on(t, e[r], i, n); + } + return this; + }, + off: function (t, e, i, n) { + if ("object" == typeof e) for (var s in e) this._off(t, s, e[s], i); + else { + e = o.Util.splitWords(e); + for (var r = 0, a = e.length; a > r; r++) this._off(t, e[r], i, n); + } + return this; + }, + _on: function (e, i, n, s) { + var r = i + o.stamp(n) + (s ? "_" + o.stamp(s) : ""); + if (e[a] && e[a][r]) return this; + var h = function (i) { + return n.call(s || e, i || t.event); + }, + l = h; + return ( + o.Browser.pointer && 0 === i.indexOf("touch") + ? this.addPointerListener(e, i, h, r) + : o.Browser.touch && "dblclick" === i && this.addDoubleTapListener + ? this.addDoubleTapListener(e, h, r) + : "addEventListener" in e + ? "mousewheel" === i + ? (e.addEventListener("DOMMouseScroll", h, !1), e.addEventListener(i, h, !1)) + : "mouseenter" === i || "mouseleave" === i + ? ((h = function (i) { + (i = i || t.event), o.DomEvent._isExternalTarget(e, i) && l(i); + }), + e.addEventListener("mouseenter" === i ? "mouseover" : "mouseout", h, !1)) + : ("click" === i && + o.Browser.android && + (h = function (t) { + return o.DomEvent._filterClick(t, l); + }), + e.addEventListener(i, h, !1)) + : "attachEvent" in e && e.attachEvent("on" + i, h), + (e[a] = e[a] || {}), + (e[a][r] = h), + this + ); + }, + _off: function (t, e, i, n) { + var s = e + o.stamp(i) + (n ? "_" + o.stamp(n) : ""), + r = t[a] && t[a][s]; + return r + ? (o.Browser.pointer && 0 === e.indexOf("touch") + ? this.removePointerListener(t, e, s) + : o.Browser.touch && "dblclick" === e && this.removeDoubleTapListener + ? this.removeDoubleTapListener(t, s) + : "removeEventListener" in t + ? "mousewheel" === e + ? (t.removeEventListener("DOMMouseScroll", r, !1), + t.removeEventListener(e, r, !1)) + : t.removeEventListener( + "mouseenter" === e ? "mouseover" : "mouseleave" === e ? "mouseout" : e, + r, + !1 + ) + : "detachEvent" in t && t.detachEvent("on" + e, r), + (t[a][s] = null), + this) + : this; + }, + stopPropagation: function (t) { + return ( + t.stopPropagation + ? t.stopPropagation() + : t.originalEvent + ? (t.originalEvent._stopped = !0) + : (t.cancelBubble = !0), + o.DomEvent._skipped(t), + this + ); + }, + disableScrollPropagation: function (t) { + return o.DomEvent.on(t, "mousewheel MozMousePixelScroll", o.DomEvent.stopPropagation); + }, + disableClickPropagation: function (t) { + var e = o.DomEvent.stopPropagation; + return ( + o.DomEvent.on(t, o.Draggable.START.join(" "), e), + o.DomEvent.on(t, { click: o.DomEvent._fakeStop, dblclick: e }) + ); + }, + preventDefault: function (t) { + return t.preventDefault ? t.preventDefault() : (t.returnValue = !1), this; + }, + stop: function (t) { + return o.DomEvent.preventDefault(t).stopPropagation(t); + }, + getMousePosition: function (t, e) { + if (!e) return new o.Point(t.clientX, t.clientY); + var i = e.getBoundingClientRect(); + return new o.Point(t.clientX - i.left - e.clientLeft, t.clientY - i.top - e.clientTop); + }, + getWheelDelta: function (t) { + var e = 0; + return t.wheelDelta && (e = t.wheelDelta / 120), t.detail && (e = -t.detail / 3), e; + }, + _skipEvents: {}, + _fakeStop: function (t) { + o.DomEvent._skipEvents[t.type] = !0; + }, + _skipped: function (t) { + var e = this._skipEvents[t.type]; + return (this._skipEvents[t.type] = !1), e; + }, + _isExternalTarget: function (t, e) { + var i = e.relatedTarget; + if (!i) return !0; + try { + for (; i && i !== t; ) i = i.parentNode; + } catch (n) { + return !1; + } + return i !== t; + }, + _filterClick: function (t, e) { + var i = t.timeStamp || t.originalEvent.timeStamp, + n = o.DomEvent._lastClick && i - o.DomEvent._lastClick; + return (n && n > 100 && 500 > n) || (t.target._simulatedClick && !t._simulated) + ? void o.DomEvent.stop(t) + : ((o.DomEvent._lastClick = i), void e(t)); + }, + }), + (o.DomEvent.addListener = o.DomEvent.on), + (o.DomEvent.removeListener = o.DomEvent.off), + (o.Draggable = o.Evented.extend({ + statics: { + START: o.Browser.touch ? ["touchstart", "mousedown"] : ["mousedown"], + END: { + mousedown: "mouseup", + touchstart: "touchend", + pointerdown: "touchend", + MSPointerDown: "touchend", + }, + MOVE: { + mousedown: "mousemove", + touchstart: "touchmove", + pointerdown: "touchmove", + MSPointerDown: "touchmove", + }, + }, + initialize: function (t, e, i) { + (this._element = t), (this._dragStartTarget = e || t), (this._preventOutline = i); + }, + enable: function () { + this._enabled || + (o.DomEvent.on(this._dragStartTarget, o.Draggable.START.join(" "), this._onDown, this), + (this._enabled = !0)); + }, + disable: function () { + this._enabled && + (o.DomEvent.off(this._dragStartTarget, o.Draggable.START.join(" "), this._onDown, this), + (this._enabled = !1), + (this._moved = !1)); + }, + _onDown: function (t) { + if ( + ((this._moved = !1), + !o.DomUtil.hasClass(this._element, "leaflet-zoom-anim") && + !( + o.Draggable._dragging || + t.shiftKey || + (1 !== t.which && 1 !== t.button && !t.touches) + ) && + this._enabled && + ((o.Draggable._dragging = !0), + this._preventOutline && o.DomUtil.preventOutline(this._element), + o.DomUtil.disableImageDrag(), + o.DomUtil.disableTextSelection(), + !this._moving)) + ) { + this.fire("down"); + var i = t.touches ? t.touches[0] : t; + (this._startPoint = new o.Point(i.clientX, i.clientY)), + (this._startPos = this._newPos = o.DomUtil.getPosition(this._element)), + o.DomEvent.on(e, o.Draggable.MOVE[t.type], this._onMove, this).on( + e, + o.Draggable.END[t.type], + this._onUp, + this + ); + } + }, + _onMove: function (t) { + if (t.touches && t.touches.length > 1) return void (this._moved = !0); + var i = t.touches && 1 === t.touches.length ? t.touches[0] : t, + n = new o.Point(i.clientX, i.clientY), + s = n.subtract(this._startPoint); + (s.x || s.y) && + ((o.Browser.touch && Math.abs(s.x) + Math.abs(s.y) < 3) || + (o.DomEvent.preventDefault(t), + this._moved || + (this.fire("dragstart"), + (this._moved = !0), + (this._startPos = o.DomUtil.getPosition(this._element).subtract(s)), + o.DomUtil.addClass(e.body, "leaflet-dragging"), + (this._lastTarget = t.target || t.srcElement), + o.DomUtil.addClass(this._lastTarget, "leaflet-drag-target")), + (this._newPos = this._startPos.add(s)), + (this._moving = !0), + o.Util.cancelAnimFrame(this._animRequest), + (this._lastEvent = t), + (this._animRequest = o.Util.requestAnimFrame(this._updatePosition, this, !0)))); + }, + _updatePosition: function () { + var t = { originalEvent: this._lastEvent }; + this.fire("predrag", t), + o.DomUtil.setPosition(this._element, this._newPos), + this.fire("drag", t); + }, + _onUp: function () { + o.DomUtil.removeClass(e.body, "leaflet-dragging"), + this._lastTarget && + (o.DomUtil.removeClass(this._lastTarget, "leaflet-drag-target"), + (this._lastTarget = null)); + for (var t in o.Draggable.MOVE) + o.DomEvent.off(e, o.Draggable.MOVE[t], this._onMove, this).off( + e, + o.Draggable.END[t], + this._onUp, + this + ); + o.DomUtil.enableImageDrag(), + o.DomUtil.enableTextSelection(), + this._moved && + this._moving && + (o.Util.cancelAnimFrame(this._animRequest), + this.fire("dragend", { distance: this._newPos.distanceTo(this._startPos) })), + (this._moving = !1), + (o.Draggable._dragging = !1); + }, + })), + (o.Handler = o.Class.extend({ + initialize: function (t) { + this._map = t; + }, + enable: function () { + this._enabled || ((this._enabled = !0), this.addHooks()); + }, + disable: function () { + this._enabled && ((this._enabled = !1), this.removeHooks()); + }, + enabled: function () { + return !!this._enabled; + }, + })), + o.Map.mergeOptions({ + dragging: !0, + inertia: !o.Browser.android23, + inertiaDeceleration: 3400, + inertiaMaxSpeed: 1 / 0, + easeLinearity: 0.2, + worldCopyJump: !1, + }), + (o.Map.Drag = o.Handler.extend({ + addHooks: function () { + if (!this._draggable) { + var t = this._map; + (this._draggable = new o.Draggable(t._mapPane, t._container)), + this._draggable.on( + { + down: this._onDown, + dragstart: this._onDragStart, + drag: this._onDrag, + dragend: this._onDragEnd, + }, + this + ), + this._draggable.on("predrag", this._onPreDragLimit, this), + t.options.worldCopyJump && + (this._draggable.on("predrag", this._onPreDragWrap, this), + t.on("zoomend", this._onZoomEnd, this), + t.whenReady(this._onZoomEnd, this)); + } + o.DomUtil.addClass(this._map._container, "leaflet-grab"), this._draggable.enable(); + }, + removeHooks: function () { + o.DomUtil.removeClass(this._map._container, "leaflet-grab"), this._draggable.disable(); + }, + moved: function () { + return this._draggable && this._draggable._moved; + }, + _onDown: function () { + this._map.stop(); + }, + _onDragStart: function () { + var t = this._map; + if (this._map.options.maxBounds && this._map.options.maxBoundsViscosity) { + var e = o.latLngBounds(this._map.options.maxBounds); + (this._offsetLimit = o.bounds( + this._map.latLngToContainerPoint(e.getNorthWest()).multiplyBy(-1), + this._map + .latLngToContainerPoint(e.getSouthEast()) + .multiplyBy(-1) + .add(this._map.getSize()) + )), + (this._viscosity = Math.min(1, Math.max(0, this._map.options.maxBoundsViscosity))); + } else this._offsetLimit = null; + t.fire("movestart").fire("dragstart"), + t.options.inertia && ((this._positions = []), (this._times = [])); + }, + _onDrag: function (t) { + if (this._map.options.inertia) { + var e = (this._lastTime = +new Date()), + i = (this._lastPos = this._draggable._absPos || this._draggable._newPos); + this._positions.push(i), + this._times.push(e), + e - this._times[0] > 50 && (this._positions.shift(), this._times.shift()); + } + this._map.fire("move", t).fire("drag", t); + }, + _onZoomEnd: function () { + var t = this._map.getSize().divideBy(2), + e = this._map.latLngToLayerPoint([0, 0]); + (this._initialWorldOffset = e.subtract(t).x), + (this._worldWidth = this._map.getPixelWorldBounds().getSize().x); + }, + _viscousLimit: function (t, e) { + return t - (t - e) * this._viscosity; + }, + _onPreDragLimit: function () { + if (this._viscosity && this._offsetLimit) { + var t = this._draggable._newPos.subtract(this._draggable._startPos), + e = this._offsetLimit; + t.x < e.min.x && (t.x = this._viscousLimit(t.x, e.min.x)), + t.y < e.min.y && (t.y = this._viscousLimit(t.y, e.min.y)), + t.x > e.max.x && (t.x = this._viscousLimit(t.x, e.max.x)), + t.y > e.max.y && (t.y = this._viscousLimit(t.y, e.max.y)), + (this._draggable._newPos = this._draggable._startPos.add(t)); + } + }, + _onPreDragWrap: function () { + var t = this._worldWidth, + e = Math.round(t / 2), + i = this._initialWorldOffset, + n = this._draggable._newPos.x, + o = ((n - e + i) % t) + e - i, + s = ((n + e + i) % t) - e - i, + r = Math.abs(o + i) < Math.abs(s + i) ? o : s; + (this._draggable._absPos = this._draggable._newPos.clone()), (this._draggable._newPos.x = r); + }, + _onDragEnd: function (t) { + var e = this._map, + i = e.options, + n = !i.inertia || this._times.length < 2; + if ((e.fire("dragend", t), n)) e.fire("moveend"); + else { + var s = this._lastPos.subtract(this._positions[0]), + r = (this._lastTime - this._times[0]) / 1e3, + a = i.easeLinearity, + h = s.multiplyBy(a / r), + l = h.distanceTo([0, 0]), + u = Math.min(i.inertiaMaxSpeed, l), + c = h.multiplyBy(u / l), + d = u / (i.inertiaDeceleration * a), + _ = c.multiplyBy(-d / 2).round(); + _.x || _.y + ? ((_ = e._limitOffset(_, e.options.maxBounds)), + o.Util.requestAnimFrame(function () { + e.panBy(_, { duration: d, easeLinearity: a, noMoveStart: !0, animate: !0 }); + })) + : e.fire("moveend"); + } + }, + })), + o.Map.addInitHook("addHandler", "dragging", o.Map.Drag), + o.Map.mergeOptions({ doubleClickZoom: !0 }), + (o.Map.DoubleClickZoom = o.Handler.extend({ + addHooks: function () { + this._map.on("dblclick", this._onDoubleClick, this); + }, + removeHooks: function () { + this._map.off("dblclick", this._onDoubleClick, this); + }, + _onDoubleClick: function (t) { + var e = this._map, + i = e.getZoom(), + n = t.originalEvent.shiftKey ? Math.ceil(i) - 1 : Math.floor(i) + 1; + "center" === e.options.doubleClickZoom ? e.setZoom(n) : e.setZoomAround(t.containerPoint, n); + }, + })), + o.Map.addInitHook("addHandler", "doubleClickZoom", o.Map.DoubleClickZoom), + o.Map.mergeOptions({ scrollWheelZoom: !0, wheelDebounceTime: 40 }), + (o.Map.ScrollWheelZoom = o.Handler.extend({ + addHooks: function () { + o.DomEvent.on( + this._map._container, + { mousewheel: this._onWheelScroll, MozMousePixelScroll: o.DomEvent.preventDefault }, + this + ), + (this._delta = 0); + }, + removeHooks: function () { + o.DomEvent.off( + this._map._container, + { mousewheel: this._onWheelScroll, MozMousePixelScroll: o.DomEvent.preventDefault }, + this + ); + }, + _onWheelScroll: function (t) { + var e = o.DomEvent.getWheelDelta(t), + i = this._map.options.wheelDebounceTime; + (this._delta += e), + (this._lastMousePos = this._map.mouseEventToContainerPoint(t)), + this._startTime || (this._startTime = +new Date()); + var n = Math.max(i - (+new Date() - this._startTime), 0); + clearTimeout(this._timer), + (this._timer = setTimeout(o.bind(this._performZoom, this), n)), + o.DomEvent.stop(t); + }, + _performZoom: function () { + var t = this._map, + e = this._delta, + i = t.getZoom(); + t.stop(), + (e = e > 0 ? Math.ceil(e) : Math.floor(e)), + (e = Math.max(Math.min(e, 4), -4)), + (e = t._limitZoom(i + e) - i), + (this._delta = 0), + (this._startTime = null), + e && + ("center" === t.options.scrollWheelZoom + ? t.setZoom(i + e) + : t.setZoomAround(this._lastMousePos, i + e)); + }, + })), + o.Map.addInitHook("addHandler", "scrollWheelZoom", o.Map.ScrollWheelZoom), + o.extend(o.DomEvent, { + _touchstart: o.Browser.msPointer + ? "MSPointerDown" + : o.Browser.pointer + ? "pointerdown" + : "touchstart", + _touchend: o.Browser.msPointer ? "MSPointerUp" : o.Browser.pointer ? "pointerup" : "touchend", + addDoubleTapListener: function (t, e, i) { + function n(t) { + var e; + if (((e = o.Browser.pointer ? o.DomEvent._pointersCount : t.touches.length), !(e > 1))) { + var i = Date.now(), + n = i - (r || i); + (a = t.touches ? t.touches[0] : t), (h = n > 0 && l >= n), (r = i); + } + } - function r(t) { return (Math.exp(t) - Math.exp(-t)) / 2 } + function s() { + if (h && !a.cancelBubble) { + if (o.Browser.pointer) { + var t, + i, + n = {}; + for (i in a) (t = a[i]), (n[i] = t && t.bind ? t.bind(a) : t); + a = n; + } + (a.type = "dblclick"), e(a), (r = null); + } + } + var r, + a, + h = !1, + l = 250, + u = "_leaflet_", + c = this._touchstart, + d = this._touchend; + return ( + (t[u + c + i] = n), + (t[u + d + i] = s), + t.addEventListener(c, n, !1), + t.addEventListener(d, s, !1), + this + ); + }, + removeDoubleTapListener: function (t, e) { + var i = "_leaflet_", + n = t[i + this._touchend + e]; + return ( + t.removeEventListener(this._touchstart, t[i + this._touchstart + e], !1), + t.removeEventListener(this._touchend, n, !1), + this + ); + }, + }), + o.extend(o.DomEvent, { + POINTER_DOWN: o.Browser.msPointer ? "MSPointerDown" : "pointerdown", + POINTER_MOVE: o.Browser.msPointer ? "MSPointerMove" : "pointermove", + POINTER_UP: o.Browser.msPointer ? "MSPointerUp" : "pointerup", + POINTER_CANCEL: o.Browser.msPointer ? "MSPointerCancel" : "pointercancel", + _pointers: {}, + _pointersCount: 0, + addPointerListener: function (t, e, i, n) { + return ( + "touchstart" === e + ? this._addPointerStart(t, i, n) + : "touchmove" === e + ? this._addPointerMove(t, i, n) + : "touchend" === e && this._addPointerEnd(t, i, n), + this + ); + }, + removePointerListener: function (t, e, i) { + var n = t["_leaflet_" + e + i]; + return ( + "touchstart" === e + ? t.removeEventListener(this.POINTER_DOWN, n, !1) + : "touchmove" === e + ? t.removeEventListener(this.POINTER_MOVE, n, !1) + : "touchend" === e && + (t.removeEventListener(this.POINTER_UP, n, !1), + t.removeEventListener(this.POINTER_CANCEL, n, !1)), + this + ); + }, + _addPointerStart: function (t, i, n) { + var s = o.bind(function (t) { + "mouse" !== t.pointerType && + t.pointerType !== t.MSPOINTER_TYPE_MOUSE && + o.DomEvent.preventDefault(t), + this._handlePointer(t, i); + }, this); + if ( + ((t["_leaflet_touchstart" + n] = s), + t.addEventListener(this.POINTER_DOWN, s, !1), + !this._pointerDocListener) + ) { + var r = o.bind(this._globalPointerUp, this); + e.documentElement.addEventListener( + this.POINTER_DOWN, + o.bind(this._globalPointerDown, this), + !0 + ), + e.documentElement.addEventListener( + this.POINTER_MOVE, + o.bind(this._globalPointerMove, this), + !0 + ), + e.documentElement.addEventListener(this.POINTER_UP, r, !0), + e.documentElement.addEventListener(this.POINTER_CANCEL, r, !0), + (this._pointerDocListener = !0); + } + }, + _globalPointerDown: function (t) { + (this._pointers[t.pointerId] = t), this._pointersCount++; + }, + _globalPointerMove: function (t) { + this._pointers[t.pointerId] && (this._pointers[t.pointerId] = t); + }, + _globalPointerUp: function (t) { + delete this._pointers[t.pointerId], this._pointersCount--; + }, + _handlePointer: function (t, e) { + t.touches = []; + for (var i in this._pointers) t.touches.push(this._pointers[i]); + (t.changedTouches = [t]), e(t); + }, + _addPointerMove: function (t, e, i) { + var n = o.bind(function (t) { + ((t.pointerType !== t.MSPOINTER_TYPE_MOUSE && "mouse" !== t.pointerType) || + 0 !== t.buttons) && + this._handlePointer(t, e); + }, this); + (t["_leaflet_touchmove" + i] = n), t.addEventListener(this.POINTER_MOVE, n, !1); + }, + _addPointerEnd: function (t, e, i) { + var n = o.bind(function (t) { + this._handlePointer(t, e); + }, this); + (t["_leaflet_touchend" + i] = n), + t.addEventListener(this.POINTER_UP, n, !1), + t.addEventListener(this.POINTER_CANCEL, n, !1); + }, + }), + o.Map.mergeOptions({ touchZoom: o.Browser.touch && !o.Browser.android23, bounceAtZoomLimits: !0 }), + (o.Map.TouchZoom = o.Handler.extend({ + addHooks: function () { + o.DomEvent.on(this._map._container, "touchstart", this._onTouchStart, this); + }, + removeHooks: function () { + o.DomEvent.off(this._map._container, "touchstart", this._onTouchStart, this); + }, + _onTouchStart: function (t) { + var i = this._map; + if (t.touches && 2 === t.touches.length && !i._animatingZoom && !this._zooming) { + var n = i.mouseEventToContainerPoint(t.touches[0]), + s = i.mouseEventToContainerPoint(t.touches[1]); + (this._centerPoint = i.getSize()._divideBy(2)), + (this._startLatLng = i.containerPointToLatLng(this._centerPoint)), + "center" !== i.options.touchZoom && + (this._pinchStartLatLng = i.containerPointToLatLng(n.add(s)._divideBy(2))), + (this._startDist = n.distanceTo(s)), + (this._startZoom = i.getZoom()), + (this._moved = !1), + (this._zooming = !0), + i.stop(), + o.DomEvent.on(e, "touchmove", this._onTouchMove, this).on( + e, + "touchend", + this._onTouchEnd, + this + ), + o.DomEvent.preventDefault(t); + } + }, + _onTouchMove: function (t) { + if (t.touches && 2 === t.touches.length && this._zooming) { + var e = this._map, + i = e.mouseEventToContainerPoint(t.touches[0]), + n = e.mouseEventToContainerPoint(t.touches[1]), + s = i.distanceTo(n) / this._startDist; + if ( + ((this._zoom = e.getScaleZoom(s, this._startZoom)), "center" === e.options.touchZoom) + ) { + if (((this._center = this._startLatLng), 1 === s)) return; + } else { + var r = i._add(n)._divideBy(2)._subtract(this._centerPoint); + if (1 === s && 0 === r.x && 0 === r.y) return; + this._center = e.unproject(e.project(this._pinchStartLatLng).subtract(r)); + } + if ( + e.options.bounceAtZoomLimits || + !((this._zoom <= e.getMinZoom() && 1 > s) || (this._zoom >= e.getMaxZoom() && s > 1)) + ) { + this._moved || (e._moveStart(!0), (this._moved = !0)), + o.Util.cancelAnimFrame(this._animRequest); + var a = o.bind(e._move, e, this._center, this._zoom, { pinch: !0, round: !1 }); + (this._animRequest = o.Util.requestAnimFrame(a, this, !0)), + o.DomEvent.preventDefault(t); + } + } + }, + _onTouchEnd: function () { + if (!this._moved || !this._zooming) return void (this._zooming = !1); + (this._zooming = !1), + o.Util.cancelAnimFrame(this._animRequest), + o.DomEvent.off(e, "touchmove", this._onTouchMove).off(e, "touchend", this._onTouchEnd); + var t = this._zoom; + (t = this._map._limitZoom(t - this._startZoom > 0 ? Math.ceil(t) : Math.floor(t))), + this._map._animateZoom(this._center, t, !0, !0); + }, + })), + o.Map.addInitHook("addHandler", "touchZoom", o.Map.TouchZoom), + o.Map.mergeOptions({ tap: !0, tapTolerance: 15 }), + (o.Map.Tap = o.Handler.extend({ + addHooks: function () { + o.DomEvent.on(this._map._container, "touchstart", this._onDown, this); + }, + removeHooks: function () { + o.DomEvent.off(this._map._container, "touchstart", this._onDown, this); + }, + _onDown: function (t) { + if (t.touches) { + if ((o.DomEvent.preventDefault(t), (this._fireClick = !0), t.touches.length > 1)) + return (this._fireClick = !1), void clearTimeout(this._holdTimeout); + var i = t.touches[0], + n = i.target; + (this._startPos = this._newPos = new o.Point(i.clientX, i.clientY)), + n.tagName && + "a" === n.tagName.toLowerCase() && + o.DomUtil.addClass(n, "leaflet-active"), + (this._holdTimeout = setTimeout( + o.bind(function () { + this._isTapValid() && + ((this._fireClick = !1), + this._onUp(), + this._simulateEvent("contextmenu", i)); + }, this), + 1e3 + )), + this._simulateEvent("mousedown", i), + o.DomEvent.on(e, { touchmove: this._onMove, touchend: this._onUp }, this); + } + }, + _onUp: function (t) { + if ( + (clearTimeout(this._holdTimeout), + o.DomEvent.off(e, { touchmove: this._onMove, touchend: this._onUp }, this), + this._fireClick && t && t.changedTouches) + ) { + var i = t.changedTouches[0], + n = i.target; + n && + n.tagName && + "a" === n.tagName.toLowerCase() && + o.DomUtil.removeClass(n, "leaflet-active"), + this._simulateEvent("mouseup", i), + this._isTapValid() && this._simulateEvent("click", i); + } + }, + _isTapValid: function () { + return this._newPos.distanceTo(this._startPos) <= this._map.options.tapTolerance; + }, + _onMove: function (t) { + var e = t.touches[0]; + (this._newPos = new o.Point(e.clientX, e.clientY)), this._simulateEvent("mousemove", e); + }, + _simulateEvent: function (i, n) { + var o = e.createEvent("MouseEvents"); + (o._simulated = !0), + (n.target._simulatedClick = !0), + o.initMouseEvent( + i, + !0, + !0, + t, + 1, + n.screenX, + n.screenY, + n.clientX, + n.clientY, + !1, + !1, + !1, + !1, + 0, + null + ), + n.target.dispatchEvent(o); + }, + })), + o.Browser.touch && !o.Browser.pointer && o.Map.addInitHook("addHandler", "tap", o.Map.Tap), + o.Map.mergeOptions({ boxZoom: !0 }), + (o.Map.BoxZoom = o.Handler.extend({ + initialize: function (t) { + (this._map = t), (this._container = t._container), (this._pane = t._panes.overlayPane); + }, + addHooks: function () { + o.DomEvent.on(this._container, "mousedown", this._onMouseDown, this); + }, + removeHooks: function () { + o.DomEvent.off(this._container, "mousedown", this._onMouseDown, this); + }, + moved: function () { + return this._moved; + }, + _resetState: function () { + this._moved = !1; + }, + _onMouseDown: function (t) { + return !t.shiftKey || (1 !== t.which && 1 !== t.button) + ? !1 + : (this._resetState(), + o.DomUtil.disableTextSelection(), + o.DomUtil.disableImageDrag(), + (this._startPoint = this._map.mouseEventToContainerPoint(t)), + void o.DomEvent.on( + e, + { + contextmenu: o.DomEvent.stop, + mousemove: this._onMouseMove, + mouseup: this._onMouseUp, + keydown: this._onKeyDown, + }, + this + )); + }, + _onMouseMove: function (t) { + this._moved || + ((this._moved = !0), + (this._box = o.DomUtil.create("div", "leaflet-zoom-box", this._container)), + o.DomUtil.addClass(this._container, "leaflet-crosshair"), + this._map.fire("boxzoomstart")), + (this._point = this._map.mouseEventToContainerPoint(t)); + var e = new o.Bounds(this._point, this._startPoint), + i = e.getSize(); + o.DomUtil.setPosition(this._box, e.min), + (this._box.style.width = i.x + "px"), + (this._box.style.height = i.y + "px"); + }, + _finish: function () { + this._moved && + (o.DomUtil.remove(this._box), + o.DomUtil.removeClass(this._container, "leaflet-crosshair")), + o.DomUtil.enableTextSelection(), + o.DomUtil.enableImageDrag(), + o.DomEvent.off( + e, + { + contextmenu: o.DomEvent.stop, + mousemove: this._onMouseMove, + mouseup: this._onMouseUp, + keydown: this._onKeyDown, + }, + this + ); + }, + _onMouseUp: function (t) { + if ((1 === t.which || 1 === t.button) && (this._finish(), this._moved)) { + setTimeout(o.bind(this._resetState, this), 0); + var e = new o.LatLngBounds( + this._map.containerPointToLatLng(this._startPoint), + this._map.containerPointToLatLng(this._point) + ); + this._map.fitBounds(e).fire("boxzoomend", { boxZoomBounds: e }); + } + }, + _onKeyDown: function (t) { + 27 === t.keyCode && this._finish(); + }, + })), + o.Map.addInitHook("addHandler", "boxZoom", o.Map.BoxZoom), + o.Map.mergeOptions({ keyboard: !0, keyboardPanOffset: 80, keyboardZoomOffset: 1 }), + (o.Map.Keyboard = o.Handler.extend({ + keyCodes: { + left: [37], + right: [39], + down: [40], + up: [38], + zoomIn: [187, 107, 61, 171], + zoomOut: [189, 109, 54, 173], + }, + initialize: function (t) { + (this._map = t), + this._setPanOffset(t.options.keyboardPanOffset), + this._setZoomOffset(t.options.keyboardZoomOffset); + }, + addHooks: function () { + var t = this._map._container; + t.tabIndex <= 0 && (t.tabIndex = "0"), + o.DomEvent.on( + t, + { focus: this._onFocus, blur: this._onBlur, mousedown: this._onMouseDown }, + this + ), + this._map.on({ focus: this._addHooks, blur: this._removeHooks }, this); + }, + removeHooks: function () { + this._removeHooks(), + o.DomEvent.off( + this._map._container, + { focus: this._onFocus, blur: this._onBlur, mousedown: this._onMouseDown }, + this + ), + this._map.off({ focus: this._addHooks, blur: this._removeHooks }, this); + }, + _onMouseDown: function () { + if (!this._focused) { + var i = e.body, + n = e.documentElement, + o = i.scrollTop || n.scrollTop, + s = i.scrollLeft || n.scrollLeft; + this._map._container.focus(), t.scrollTo(s, o); + } + }, + _onFocus: function () { + (this._focused = !0), this._map.fire("focus"); + }, + _onBlur: function () { + (this._focused = !1), this._map.fire("blur"); + }, + _setPanOffset: function (t) { + var e, + i, + n = (this._panKeys = {}), + o = this.keyCodes; + for (e = 0, i = o.left.length; i > e; e++) n[o.left[e]] = [-1 * t, 0]; + for (e = 0, i = o.right.length; i > e; e++) n[o.right[e]] = [t, 0]; + for (e = 0, i = o.down.length; i > e; e++) n[o.down[e]] = [0, t]; + for (e = 0, i = o.up.length; i > e; e++) n[o.up[e]] = [0, -1 * t]; + }, + _setZoomOffset: function (t) { + var e, + i, + n = (this._zoomKeys = {}), + o = this.keyCodes; + for (e = 0, i = o.zoomIn.length; i > e; e++) n[o.zoomIn[e]] = t; + for (e = 0, i = o.zoomOut.length; i > e; e++) n[o.zoomOut[e]] = -t; + }, + _addHooks: function () { + o.DomEvent.on(e, "keydown", this._onKeyDown, this); + }, + _removeHooks: function () { + o.DomEvent.off(e, "keydown", this._onKeyDown, this); + }, + _onKeyDown: function (t) { + if (!(t.altKey || t.ctrlKey || t.metaKey)) { + var e, + i = t.keyCode, + n = this._map; + if (i in this._panKeys) { + if (n._panAnim && n._panAnim._inProgress) return; + (e = this._panKeys[i]), + t.shiftKey && (e = o.point(e).multiplyBy(3)), + n.panBy(e), + n.options.maxBounds && n.panInsideBounds(n.options.maxBounds); + } else if (i in this._zoomKeys) + n.setZoom(n.getZoom() + (t.shiftKey ? 3 : 1) * this._zoomKeys[i]); + else { + if (27 !== i) return; + n.closePopup(); + } + o.DomEvent.stop(t); + } + }, + })), + o.Map.addInitHook("addHandler", "keyboard", o.Map.Keyboard), + (o.Handler.MarkerDrag = o.Handler.extend({ + initialize: function (t) { + this._marker = t; + }, + addHooks: function () { + var t = this._marker._icon; + this._draggable || (this._draggable = new o.Draggable(t, t, !0)), + this._draggable + .on( + { dragstart: this._onDragStart, drag: this._onDrag, dragend: this._onDragEnd }, + this + ) + .enable(), + o.DomUtil.addClass(t, "leaflet-marker-draggable"); + }, + removeHooks: function () { + this._draggable + .off({ dragstart: this._onDragStart, drag: this._onDrag, dragend: this._onDragEnd }, this) + .disable(), + this._marker._icon && + o.DomUtil.removeClass(this._marker._icon, "leaflet-marker-draggable"); + }, + moved: function () { + return this._draggable && this._draggable._moved; + }, + _onDragStart: function () { + this._marker.closePopup().fire("movestart").fire("dragstart"); + }, + _onDrag: function (t) { + var e = this._marker, + i = e._shadow, + n = o.DomUtil.getPosition(e._icon), + s = e._map.layerPointToLatLng(n); + i && o.DomUtil.setPosition(i, n), + (e._latlng = s), + (t.latlng = s), + e.fire("move", t).fire("drag", t); + }, + _onDragEnd: function (t) { + this._marker.fire("moveend").fire("dragend", t); + }, + })), + (o.Control = o.Class.extend({ + options: { position: "topright" }, + initialize: function (t) { + o.setOptions(this, t); + }, + getPosition: function () { + return this.options.position; + }, + setPosition: function (t) { + var e = this._map; + return e && e.removeControl(this), (this.options.position = t), e && e.addControl(this), this; + }, + getContainer: function () { + return this._container; + }, + addTo: function (t) { + this.remove(), (this._map = t); + var e = (this._container = this.onAdd(t)), + i = this.getPosition(), + n = t._controlCorners[i]; + return ( + o.DomUtil.addClass(e, "leaflet-control"), + -1 !== i.indexOf("bottom") ? n.insertBefore(e, n.firstChild) : n.appendChild(e), + this + ); + }, + remove: function () { + return this._map + ? (o.DomUtil.remove(this._container), + this.onRemove && this.onRemove(this._map), + (this._map = null), + this) + : this; + }, + _refocusOnMap: function (t) { + this._map && t && t.screenX > 0 && t.screenY > 0 && this._map.getContainer().focus(); + }, + })), + (o.control = function (t) { + return new o.Control(t); + }), + o.Map.include({ + addControl: function (t) { + return t.addTo(this), this; + }, + removeControl: function (t) { + return t.remove(), this; + }, + _initControlPos: function () { + function t(t, s) { + var r = i + t + " " + i + s; + e[t + s] = o.DomUtil.create("div", r, n); + } + var e = (this._controlCorners = {}), + i = "leaflet-", + n = (this._controlContainer = o.DomUtil.create( + "div", + i + "control-container", + this._container + )); + t("top", "left"), t("top", "right"), t("bottom", "left"), t("bottom", "right"); + }, + _clearControlPos: function () { + o.DomUtil.remove(this._controlContainer); + }, + }), + (o.Control.Zoom = o.Control.extend({ + options: { + position: "topleft", + zoomInText: "+", + zoomInTitle: "Zoom in", + zoomOutText: "-", + zoomOutTitle: "Zoom out", + }, + onAdd: function (t) { + var e = "leaflet-control-zoom", + i = o.DomUtil.create("div", e + " leaflet-bar"), + n = this.options; + return ( + (this._zoomInButton = this._createButton( + n.zoomInText, + n.zoomInTitle, + e + "-in", + i, + this._zoomIn + )), + (this._zoomOutButton = this._createButton( + n.zoomOutText, + n.zoomOutTitle, + e + "-out", + i, + this._zoomOut + )), + this._updateDisabled(), + t.on("zoomend zoomlevelschange", this._updateDisabled, this), + i + ); + }, + onRemove: function (t) { + t.off("zoomend zoomlevelschange", this._updateDisabled, this); + }, + disable: function () { + return (this._disabled = !0), this._updateDisabled(), this; + }, + enable: function () { + return (this._disabled = !1), this._updateDisabled(), this; + }, + _zoomIn: function (t) { + this._disabled || this._map.zoomIn(t.shiftKey ? 3 : 1); + }, + _zoomOut: function (t) { + this._disabled || this._map.zoomOut(t.shiftKey ? 3 : 1); + }, + _createButton: function (t, e, i, n, s) { + var r = o.DomUtil.create("a", i, n); + return ( + (r.innerHTML = t), + (r.href = "#"), + (r.title = e), + o.DomEvent.on(r, "mousedown dblclick", o.DomEvent.stopPropagation) + .on(r, "click", o.DomEvent.stop) + .on(r, "click", s, this) + .on(r, "click", this._refocusOnMap, this), + r + ); + }, + _updateDisabled: function () { + var t = this._map, + e = "leaflet-disabled"; + o.DomUtil.removeClass(this._zoomInButton, e), + o.DomUtil.removeClass(this._zoomOutButton, e), + (this._disabled || t._zoom === t.getMinZoom()) && + o.DomUtil.addClass(this._zoomOutButton, e), + (this._disabled || t._zoom === t.getMaxZoom()) && + o.DomUtil.addClass(this._zoomInButton, e); + }, + })), + o.Map.mergeOptions({ zoomControl: !0 }), + o.Map.addInitHook(function () { + this.options.zoomControl && + ((this.zoomControl = new o.Control.Zoom()), this.addControl(this.zoomControl)); + }), + (o.control.zoom = function (t) { + return new o.Control.Zoom(t); + }), + (o.Control.Attribution = o.Control.extend({ + options: { + position: "bottomright", + prefix: 'Leaflet', + }, + initialize: function (t) { + o.setOptions(this, t), (this._attributions = {}); + }, + onAdd: function (t) { + (this._container = o.DomUtil.create("div", "leaflet-control-attribution")), + o.DomEvent && o.DomEvent.disableClickPropagation(this._container); + for (var e in t._layers) + t._layers[e].getAttribution && this.addAttribution(t._layers[e].getAttribution()); + return this._update(), this._container; + }, + setPrefix: function (t) { + return (this.options.prefix = t), this._update(), this; + }, + addAttribution: function (t) { + return t + ? (this._attributions[t] || (this._attributions[t] = 0), + this._attributions[t]++, + this._update(), + this) + : this; + }, + removeAttribution: function (t) { + return t ? (this._attributions[t] && (this._attributions[t]--, this._update()), this) : this; + }, + _update: function () { + if (this._map) { + var t = []; + for (var e in this._attributions) this._attributions[e] && t.push(e); + var i = []; + this.options.prefix && i.push(this.options.prefix), + t.length && i.push(t.join(", ")), + (this._container.innerHTML = i.join(" | ")); + } + }, + })), + o.Map.mergeOptions({ attributionControl: !0 }), + o.Map.addInitHook(function () { + this.options.attributionControl && + (this.attributionControl = new o.Control.Attribution().addTo(this)); + }), + (o.control.attribution = function (t) { + return new o.Control.Attribution(t); + }), + (o.Control.Scale = o.Control.extend({ + options: { position: "bottomleft", maxWidth: 100, metric: !0, imperial: !0 }, + onAdd: function (t) { + var e = "leaflet-control-scale", + i = o.DomUtil.create("div", e), + n = this.options; + return ( + this._addScales(n, e + "-line", i), + t.on(n.updateWhenIdle ? "moveend" : "move", this._update, this), + t.whenReady(this._update, this), + i + ); + }, + onRemove: function (t) { + t.off(this.options.updateWhenIdle ? "moveend" : "move", this._update, this); + }, + _addScales: function (t, e, i) { + t.metric && (this._mScale = o.DomUtil.create("div", e, i)), + t.imperial && (this._iScale = o.DomUtil.create("div", e, i)); + }, + _update: function () { + var t = this._map, + e = t.getSize().y / 2, + i = t.distance( + t.containerPointToLatLng([0, e]), + t.containerPointToLatLng([this.options.maxWidth, e]) + ); + this._updateScales(i); + }, + _updateScales: function (t) { + this.options.metric && t && this._updateMetric(t), + this.options.imperial && t && this._updateImperial(t); + }, + _updateMetric: function (t) { + var e = this._getRoundNum(t), + i = 1e3 > e ? e + " m" : e / 1e3 + " km"; + this._updateScale(this._mScale, i, e / t); + }, + _updateImperial: function (t) { + var e, + i, + n, + o = 3.2808399 * t; + o > 5280 + ? ((e = o / 5280), + (i = this._getRoundNum(e)), + this._updateScale(this._iScale, i + " mi", i / e)) + : ((n = this._getRoundNum(o)), this._updateScale(this._iScale, n + " ft", n / o)); + }, + _updateScale: function (t, e, i) { + (t.style.width = Math.round(this.options.maxWidth * i) + "px"), (t.innerHTML = e); + }, + _getRoundNum: function (t) { + var e = Math.pow(10, (Math.floor(t) + "").length - 1), + i = t / e; + return (i = i >= 10 ? 10 : i >= 5 ? 5 : i >= 3 ? 3 : i >= 2 ? 2 : 1), e * i; + }, + })), + (o.control.scale = function (t) { + return new o.Control.Scale(t); + }), + (o.Control.Layers = o.Control.extend({ + options: { collapsed: !0, position: "topright", autoZIndex: !0, hideSingleBase: !1 }, + initialize: function (t, e, i) { + o.setOptions(this, i), + (this._layers = {}), + (this._lastZIndex = 0), + (this._handlingClick = !1); + for (var n in t) this._addLayer(t[n], n); + for (n in e) this._addLayer(e[n], n, !0); + }, + onAdd: function (t) { + return ( + this._initLayout(), + this._update(), + (this._map = t), + t.on("zoomend", this._checkDisabledLayers, this), + this._container + ); + }, + onRemove: function () { + this._map.off("zoomend", this._checkDisabledLayers, this); + }, + addBaseLayer: function (t, e) { + return this._addLayer(t, e), this._update(); + }, + addOverlay: function (t, e) { + return this._addLayer(t, e, !0), this._update(); + }, + removeLayer: function (t) { + return ( + t.off("add remove", this._onLayerChange, this), + delete this._layers[o.stamp(t)], + this._update() + ); + }, + _initLayout: function () { + var t = "leaflet-control-layers", + e = (this._container = o.DomUtil.create("div", t)); + e.setAttribute("aria-haspopup", !0), + o.DomEvent.disableClickPropagation(e), + o.Browser.touch || o.DomEvent.disableScrollPropagation(e); + var i = (this._form = o.DomUtil.create("form", t + "-list")); + if (this.options.collapsed) { + o.Browser.android || + o.DomEvent.on(e, { mouseenter: this._expand, mouseleave: this._collapse }, this); + var n = (this._layersLink = o.DomUtil.create("a", t + "-toggle", e)); + (n.href = "#"), + (n.title = "Layers"), + o.Browser.touch + ? o.DomEvent.on(n, "click", o.DomEvent.stop).on(n, "click", this._expand, this) + : o.DomEvent.on(n, "focus", this._expand, this), + o.DomEvent.on( + i, + "click", + function () { + setTimeout(o.bind(this._onInputClick, this), 0); + }, + this + ), + this._map.on("click", this._collapse, this); + } else this._expand(); + (this._baseLayersList = o.DomUtil.create("div", t + "-base", i)), + (this._separator = o.DomUtil.create("div", t + "-separator", i)), + (this._overlaysList = o.DomUtil.create("div", t + "-overlays", i)), + e.appendChild(i); + }, + _addLayer: function (t, e, i) { + t.on("add remove", this._onLayerChange, this); + var n = o.stamp(t); + (this._layers[n] = { layer: t, name: e, overlay: i }), + this.options.autoZIndex && + t.setZIndex && + (this._lastZIndex++, t.setZIndex(this._lastZIndex)); + }, + _update: function () { + if (!this._container) return this; + o.DomUtil.empty(this._baseLayersList), o.DomUtil.empty(this._overlaysList); + var t, + e, + i, + n, + s = 0; + for (i in this._layers) + (n = this._layers[i]), + this._addItem(n), + (e = e || n.overlay), + (t = t || !n.overlay), + (s += n.overlay ? 0 : 1); + return ( + this.options.hideSingleBase && + ((t = t && s > 1), (this._baseLayersList.style.display = t ? "" : "none")), + (this._separator.style.display = e && t ? "" : "none"), + this + ); + }, + _onLayerChange: function (t) { + this._handlingClick || this._update(); + var e = this._layers[o.stamp(t.target)], + i = e.overlay + ? "add" === t.type + ? "overlayadd" + : "overlayremove" + : "add" === t.type + ? "baselayerchange" + : null; + i && this._map.fire(i, e); + }, + _createRadioElement: function (t, i) { + var n = + '", + o = e.createElement("div"); + return (o.innerHTML = n), o.firstChild; + }, + _addItem: function (t) { + var i, + n = e.createElement("label"), + s = this._map.hasLayer(t.layer); + t.overlay + ? ((i = e.createElement("input")), + (i.type = "checkbox"), + (i.className = "leaflet-control-layers-selector"), + (i.defaultChecked = s)) + : (i = this._createRadioElement("leaflet-base-layers", s)), + (i.layerId = o.stamp(t.layer)), + o.DomEvent.on(i, "click", this._onInputClick, this); + var r = e.createElement("span"); + r.innerHTML = " " + t.name; + var a = e.createElement("div"); + n.appendChild(a), a.appendChild(i), a.appendChild(r); + var h = t.overlay ? this._overlaysList : this._baseLayersList; + return h.appendChild(n), this._checkDisabledLayers(), n; + }, + _onInputClick: function () { + var t, + e, + i, + n = this._form.getElementsByTagName("input"), + o = [], + s = []; + this._handlingClick = !0; + for (var r = n.length - 1; r >= 0; r--) + (t = n[r]), + (e = this._layers[t.layerId].layer), + (i = this._map.hasLayer(e)), + t.checked && !i ? o.push(e) : !t.checked && i && s.push(e); + for (r = 0; r < s.length; r++) this._map.removeLayer(s[r]); + for (r = 0; r < o.length; r++) this._map.addLayer(o[r]); + (this._handlingClick = !1), this._refocusOnMap(); + }, + _expand: function () { + o.DomUtil.addClass(this._container, "leaflet-control-layers-expanded"), + (this._form.style.height = null); + var t = this._map._size.y - (this._container.offsetTop + 50); + t < this._form.clientHeight + ? (o.DomUtil.addClass(this._form, "leaflet-control-layers-scrollbar"), + (this._form.style.height = t + "px")) + : o.DomUtil.removeClass(this._form, "leaflet-control-layers-scrollbar"), + this._checkDisabledLayers(); + }, + _collapse: function () { + o.DomUtil.removeClass(this._container, "leaflet-control-layers-expanded"); + }, + _checkDisabledLayers: function () { + for ( + var t, + e, + n = this._form.getElementsByTagName("input"), + o = this._map.getZoom(), + s = n.length - 1; + s >= 0; + s-- + ) + (t = n[s]), + (e = this._layers[t.layerId].layer), + (t.disabled = + (e.options.minZoom !== i && o < e.options.minZoom) || + (e.options.maxZoom !== i && o > e.options.maxZoom)); + }, + })), + (o.control.layers = function (t, e, i) { + return new o.Control.Layers(t, e, i); + }), + (o.PosAnimation = o.Evented.extend({ + run: function (t, e, i, n) { + this.stop(), + (this._el = t), + (this._inProgress = !0), + (this._duration = i || 0.25), + (this._easeOutPower = 1 / Math.max(n || 0.5, 0.2)), + (this._startPos = o.DomUtil.getPosition(t)), + (this._offset = e.subtract(this._startPos)), + (this._startTime = +new Date()), + this.fire("start"), + this._animate(); + }, + stop: function () { + this._inProgress && (this._step(!0), this._complete()); + }, + _animate: function () { + (this._animId = o.Util.requestAnimFrame(this._animate, this)), this._step(); + }, + _step: function (t) { + var e = +new Date() - this._startTime, + i = 1e3 * this._duration; + i > e ? this._runFrame(this._easeOut(e / i), t) : (this._runFrame(1), this._complete()); + }, + _runFrame: function (t, e) { + var i = this._startPos.add(this._offset.multiplyBy(t)); + e && i._round(), o.DomUtil.setPosition(this._el, i), this.fire("step"); + }, + _complete: function () { + o.Util.cancelAnimFrame(this._animId), (this._inProgress = !1), this.fire("end"); + }, + _easeOut: function (t) { + return 1 - Math.pow(1 - t, this._easeOutPower); + }, + })), + o.Map.include({ + setView: function (t, e, n) { + if ( + ((e = e === i ? this._zoom : this._limitZoom(e)), + (t = this._limitCenter(o.latLng(t), e, this.options.maxBounds)), + (n = n || {}), + this.stop(), + this._loaded && !n.reset && n !== !0) + ) { + n.animate !== i && + ((n.zoom = o.extend({ animate: n.animate }, n.zoom)), + (n.pan = o.extend({ animate: n.animate, duration: n.duration }, n.pan))); + var s = + this._zoom !== e + ? this._tryAnimatedZoom && this._tryAnimatedZoom(t, e, n.zoom) + : this._tryAnimatedPan(t, n.pan); + if (s) return clearTimeout(this._sizeTimer), this; + } + return this._resetView(t, e), this; + }, + panBy: function (t, e) { + if (((t = o.point(t).round()), (e = e || {}), !t.x && !t.y)) return this.fire("moveend"); + if (e.animate !== !0 && !this.getSize().contains(t)) + return ( + this._resetView( + this.unproject(this.project(this.getCenter()).add(t)), + this.getZoom() + ), + this + ); + if ( + (this._panAnim || + ((this._panAnim = new o.PosAnimation()), + this._panAnim.on( + { step: this._onPanTransitionStep, end: this._onPanTransitionEnd }, + this + )), + e.noMoveStart || this.fire("movestart"), + e.animate !== !1) + ) { + o.DomUtil.addClass(this._mapPane, "leaflet-pan-anim"); + var i = this._getMapPanePos().subtract(t); + this._panAnim.run(this._mapPane, i, e.duration || 0.25, e.easeLinearity); + } else this._rawPanBy(t), this.fire("move").fire("moveend"); + return this; + }, + _onPanTransitionStep: function () { + this.fire("move"); + }, + _onPanTransitionEnd: function () { + o.DomUtil.removeClass(this._mapPane, "leaflet-pan-anim"), this.fire("moveend"); + }, + _tryAnimatedPan: function (t, e) { + var i = this._getCenterOffset(t)._floor(); + return (e && e.animate) === !0 || this.getSize().contains(i) ? (this.panBy(i, e), !0) : !1; + }, + }), + o.Map.mergeOptions({ zoomAnimation: !0, zoomAnimationThreshold: 4 }); + var h = o.DomUtil.TRANSITION && o.Browser.any3d && !o.Browser.mobileOpera; + h && + o.Map.addInitHook(function () { + (this._zoomAnimated = this.options.zoomAnimation), + this._zoomAnimated && + (this._createAnimProxy(), + o.DomEvent.on(this._proxy, o.DomUtil.TRANSITION_END, this._catchTransitionEnd, this)); + }), + o.Map.include( + h + ? { + _createAnimProxy: function () { + var t = (this._proxy = o.DomUtil.create( + "div", + "leaflet-proxy leaflet-zoom-animated" + )); + this._panes.mapPane.appendChild(t), + this.on( + "zoomanim", + function (e) { + var i = o.DomUtil.TRANSFORM, + n = t.style[i]; + o.DomUtil.setTransform( + t, + this.project(e.center, e.zoom), + this.getZoomScale(e.zoom, 1) + ), + n === t.style[i] && + this._animatingZoom && + this._onZoomTransitionEnd(); + }, + this + ), + this.on( + "load moveend", + function () { + var e = this.getCenter(), + i = this.getZoom(); + o.DomUtil.setTransform( + t, + this.project(e, i), + this.getZoomScale(i, 1) + ); + }, + this + ); + }, + _catchTransitionEnd: function (t) { + this._animatingZoom && + t.propertyName.indexOf("transform") >= 0 && + this._onZoomTransitionEnd(); + }, + _nothingToAnimate: function () { + return !this._container.getElementsByClassName("leaflet-zoom-animated").length; + }, + _tryAnimatedZoom: function (t, e, i) { + if (this._animatingZoom) return !0; + if ( + ((i = i || {}), + !this._zoomAnimated || + i.animate === !1 || + this._nothingToAnimate() || + Math.abs(e - this._zoom) > this.options.zoomAnimationThreshold) + ) + return !1; + var n = this.getZoomScale(e), + s = this._getCenterOffset(t)._divideBy(1 - 1 / n); + return i.animate === !0 || this.getSize().contains(s) + ? (o.Util.requestAnimFrame(function () { + this._moveStart(!0)._animateZoom(t, e, !0); + }, this), + !0) + : !1; + }, + _animateZoom: function (t, e, i, n) { + i && + ((this._animatingZoom = !0), + (this._animateToCenter = t), + (this._animateToZoom = e), + o.DomUtil.addClass(this._mapPane, "leaflet-zoom-anim")), + this.fire("zoomanim", { center: t, zoom: e, noUpdate: n }), + setTimeout(o.bind(this._onZoomTransitionEnd, this), 250); + }, + _onZoomTransitionEnd: function () { + this._animatingZoom && + (o.DomUtil.removeClass(this._mapPane, "leaflet-zoom-anim"), + o.Util.requestAnimFrame(function () { + (this._animatingZoom = !1), + this._move(this._animateToCenter, this._animateToZoom)._moveEnd(!0); + }, this)); + }, + } + : {} + ), + o.Map.include({ + flyTo: function (t, e, n) { + function s(t) { + var e = (v * v - g * g + (t ? -1 : 1) * L * L * y * y) / (2 * (t ? v : g) * L * y); + return Math.log(Math.sqrt(e * e + 1) - e); + } - function a(t) { return (Math.exp(t) + Math.exp(-t)) / 2 } + function r(t) { + return (Math.exp(t) - Math.exp(-t)) / 2; + } - function h(t) { return r(t) / a(t) } + function a(t) { + return (Math.exp(t) + Math.exp(-t)) / 2; + } - function l(t) { return g * (a(x) / a(x + P * t)) } + function h(t) { + return r(t) / a(t); + } - function u(t) { return g * (a(x) * h(x + P * t) - r(x)) / L } + function l(t) { + return g * (a(x) / a(x + P * t)); + } - function c(t) { return 1 - Math.pow(1 - t, 1.5) } + function u(t) { + return (g * (a(x) * h(x + P * t) - r(x))) / L; + } - function d() { var i = (Date.now() - b) / D, - n = c(i) * w; - 1 >= i ? (this._flyToFrame = o.Util.requestAnimFrame(d, this), this._move(this.unproject(_.add(m.subtract(_).multiplyBy(u(n) / y)), f), this.getScaleZoom(g / l(n), f), { flyTo: !0 })) : this._move(t, e)._moveEnd(!0) } if (n = n || {}, n.animate === !1 || !o.Browser.any3d) return this.setView(t, e, n); - this.stop(); var _ = this.project(this.getCenter()), - m = this.project(t), - p = this.getSize(), - f = this._zoom; - t = o.latLng(t), e = e === i ? f : e; var g = Math.max(p.x, p.y), - v = g * this.getZoomScale(f, e), - y = m.distanceTo(_) || 1, - P = 1.42, - L = P * P, - x = s(0), - b = Date.now(), - w = (s(1) - x) / P, - D = n.duration ? 1e3 * n.duration : 1e3 * w * .8; return this._moveStart(!0), d.call(this), this }, flyToBounds: function(t, e) { var i = this._getBoundsCenterZoom(t, e); return this.flyTo(i.center, i.zoom, e) } }), o.Map.include({ _defaultLocateOptions: { timeout: 1e4, watch: !1 }, locate: function(t) { if (t = this._locateOptions = o.extend({}, this._defaultLocateOptions, t), !("geolocation" in navigator)) return this._handleGeolocationError({ code: 0, message: "Geolocation not supported." }), this; var e = o.bind(this._handleGeolocationResponse, this), - i = o.bind(this._handleGeolocationError, this); return t.watch ? this._locationWatchId = navigator.geolocation.watchPosition(e, i, t) : navigator.geolocation.getCurrentPosition(e, i, t), this }, stopLocate: function() { return navigator.geolocation && navigator.geolocation.clearWatch && navigator.geolocation.clearWatch(this._locationWatchId), this._locateOptions && (this._locateOptions.setView = !1), this }, _handleGeolocationError: function(t) { var e = t.code, - i = t.message || (1 === e ? "permission denied" : 2 === e ? "position unavailable" : "timeout"); - this._locateOptions.setView && !this._loaded && this.fitWorld(), this.fire("locationerror", { code: e, message: "Geolocation error: " + i + "." }) }, _handleGeolocationResponse: function(t) { var e = t.coords.latitude, - i = t.coords.longitude, - n = new o.LatLng(e, i), - s = n.toBounds(t.coords.accuracy), - r = this._locateOptions; if (r.setView) { var a = this.getBoundsZoom(s); - this.setView(n, r.maxZoom ? Math.min(a, r.maxZoom) : a) } var h = { latlng: n, bounds: s, timestamp: t.timestamp }; for (var l in t.coords) "number" == typeof t.coords[l] && (h[l] = t.coords[l]); - this.fire("locationfound", h) } }) -}(window, document); + function c(t) { + return 1 - Math.pow(1 - t, 1.5); + } + + function d() { + var i = (Date.now() - b) / D, + n = c(i) * w; + 1 >= i + ? ((this._flyToFrame = o.Util.requestAnimFrame(d, this)), + this._move( + this.unproject(_.add(m.subtract(_).multiplyBy(u(n) / y)), f), + this.getScaleZoom(g / l(n), f), + { flyTo: !0 } + )) + : this._move(t, e)._moveEnd(!0); + } + if (((n = n || {}), n.animate === !1 || !o.Browser.any3d)) return this.setView(t, e, n); + this.stop(); + var _ = this.project(this.getCenter()), + m = this.project(t), + p = this.getSize(), + f = this._zoom; + (t = o.latLng(t)), (e = e === i ? f : e); + var g = Math.max(p.x, p.y), + v = g * this.getZoomScale(f, e), + y = m.distanceTo(_) || 1, + P = 1.42, + L = P * P, + x = s(0), + b = Date.now(), + w = (s(1) - x) / P, + D = n.duration ? 1e3 * n.duration : 1e3 * w * 0.8; + return this._moveStart(!0), d.call(this), this; + }, + flyToBounds: function (t, e) { + var i = this._getBoundsCenterZoom(t, e); + return this.flyTo(i.center, i.zoom, e); + }, + }), + o.Map.include({ + _defaultLocateOptions: { timeout: 1e4, watch: !1 }, + locate: function (t) { + if ( + ((t = this._locateOptions = o.extend({}, this._defaultLocateOptions, t)), + !("geolocation" in navigator)) + ) + return ( + this._handleGeolocationError({ code: 0, message: "Geolocation not supported." }), this + ); + var e = o.bind(this._handleGeolocationResponse, this), + i = o.bind(this._handleGeolocationError, this); + return ( + t.watch + ? (this._locationWatchId = navigator.geolocation.watchPosition(e, i, t)) + : navigator.geolocation.getCurrentPosition(e, i, t), + this + ); + }, + stopLocate: function () { + return ( + navigator.geolocation && + navigator.geolocation.clearWatch && + navigator.geolocation.clearWatch(this._locationWatchId), + this._locateOptions && (this._locateOptions.setView = !1), + this + ); + }, + _handleGeolocationError: function (t) { + var e = t.code, + i = + t.message || + (1 === e ? "permission denied" : 2 === e ? "position unavailable" : "timeout"); + this._locateOptions.setView && !this._loaded && this.fitWorld(), + this.fire("locationerror", { code: e, message: "Geolocation error: " + i + "." }); + }, + _handleGeolocationResponse: function (t) { + var e = t.coords.latitude, + i = t.coords.longitude, + n = new o.LatLng(e, i), + s = n.toBounds(t.coords.accuracy), + r = this._locateOptions; + if (r.setView) { + var a = this.getBoundsZoom(s); + this.setView(n, r.maxZoom ? Math.min(a, r.maxZoom) : a); + } + var h = { latlng: n, bounds: s, timestamp: t.timestamp }; + for (var l in t.coords) "number" == typeof t.coords[l] && (h[l] = t.coords[l]); + this.fire("locationfound", h); + }, + }); +})(window, document); diff --git a/erpnext/public/js/newsletter.js b/erpnext/public/js/newsletter.js index 3a4dbf893301..96c65de8d6fd 100644 --- a/erpnext/public/js/newsletter.js +++ b/erpnext/public/js/newsletter.js @@ -1,8 +1,8 @@ // Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -frappe.ui.form.on('Newsletter', { +frappe.ui.form.on("Newsletter", { refresh() { erpnext.toggle_naming_series(); - } + }, }); diff --git a/erpnext/public/js/payment/payments.js b/erpnext/public/js/payment/payments.js index 4c23669dbbb5..0e5842053962 100644 --- a/erpnext/public/js/payment/payments.js +++ b/erpnext/public/js/payment/payments.js @@ -6,7 +6,7 @@ erpnext.payments = class payments extends erpnext.stock.StockController { var me = this; this.dialog = new frappe.ui.Dialog({ - title: 'Payment' + title: "Payment", }); this.dialog.show(); @@ -17,15 +17,17 @@ erpnext.payments = class payments extends erpnext.stock.StockController { } select_text() { - $(this.$body).find('.form-control').click(function() { - $(this).select(); - }); + $(this.$body) + .find(".form-control") + .click(function () { + $(this).select(); + }); } set_payment_primary_action() { var me = this; - this.dialog.set_primary_action(__("Submit"), function() { + this.dialog.set_primary_action(__("Submit"), function () { // Allow no ZERO payment $.each(me.frm.doc.payments, function (index, data) { if (data.amount != 0) { @@ -34,131 +36,147 @@ erpnext.payments = class payments extends erpnext.stock.StockController { return; } }); - }) + }); } - make_keyboard(){ + make_keyboard() { var me = this; $(this.$body).empty(); - $(this.$body).html(frappe.render_template('pos_payment', this.frm.doc)) + $(this.$body).html(frappe.render_template("pos_payment", this.frm.doc)); this.show_payment_details(); - this.bind_keyboard_event() - this.clear_amount() + this.bind_keyboard_event(); + this.clear_amount(); } - make_multimode_payment(){ + make_multimode_payment() { var me = this; if (this.frm.doc.change_amount > 0) { me.payment_val = me.doc.outstanding_amount; } - this.payments = frappe.model.add_child(this.frm.doc, 'Multi Mode Payment', "payments"); + this.payments = frappe.model.add_child(this.frm.doc, "Multi Mode Payment", "payments"); this.payments.mode_of_payment = this.dialog.fields_dict.mode_of_payment.get_value(); this.payments.amount = flt(this.payment_val); } - show_payment_details(){ + show_payment_details() { var me = this; - var multimode_payments = $(this.$body).find('.multimode-payments').empty(); + var multimode_payments = $(this.$body).find(".multimode-payments").empty(); if (this.frm.doc.payments.length) { - $.each(this.frm.doc.payments, function(index, data) { - $(frappe.render_template('payment_details', { - mode_of_payment: data.mode_of_payment, - amount: data.amount, - idx: data.idx, - currency: me.frm.doc.currency, - type: data.type - })).appendTo(multimode_payments) - - if (data.type == 'Cash' && data.amount == me.frm.doc.paid_amount) { + $.each(this.frm.doc.payments, function (index, data) { + $( + frappe.render_template("payment_details", { + mode_of_payment: data.mode_of_payment, + amount: data.amount, + idx: data.idx, + currency: me.frm.doc.currency, + type: data.type, + }) + ).appendTo(multimode_payments); + + if (data.type == "Cash" && data.amount == me.frm.doc.paid_amount) { me.idx = data.idx; - me.selected_mode = $(me.$body).find(repl("input[idx='%(idx)s']",{'idx': me.idx})); + me.selected_mode = $(me.$body).find(repl("input[idx='%(idx)s']", { idx: me.idx })); me.highlight_selected_row(); me.bind_amount_change_event(); } - }) - }else{ - $("

              No payment mode selected in pos profile

              ").appendTo(multimode_payments) + }); + } else { + $("

              No payment mode selected in pos profile

              ").appendTo(multimode_payments); } } - set_outstanding_amount(){ - this.selected_mode = $(this.$body).find(repl("input[idx='%(idx)s']",{'idx': this.idx})); + set_outstanding_amount() { + this.selected_mode = $(this.$body).find(repl("input[idx='%(idx)s']", { idx: this.idx })); this.highlight_selected_row(); this.payment_val = 0.0; if (this.frm.doc.outstanding_amount > 0 && flt(this.selected_mode.val()) == 0.0) { //When user first time click on row - this.payment_val = flt(this.frm.doc.outstanding_amount / this.frm.doc.conversion_rate, precision("outstanding_amount")) + this.payment_val = flt( + this.frm.doc.outstanding_amount / this.frm.doc.conversion_rate, + precision("outstanding_amount") + ); this.selected_mode.val(format_currency(this.payment_val, this.frm.doc.currency)); this.update_payment_amount(); } else if (flt(this.selected_mode.val()) > 0) { //If user click on existing row which has value this.payment_val = flt(this.selected_mode.val()); } - this.selected_mode.select() + this.selected_mode.select(); this.bind_amount_change_event(); } - bind_keyboard_event(){ + bind_keyboard_event() { var me = this; - this.payment_val = ''; + this.payment_val = ""; this.bind_form_control_event(); this.bind_numeric_keys_event(); } bind_form_control_event() { var me = this; - $(this.$body).find('.pos-payment-row').click(function() { - me.idx = $(this).attr("idx"); - me.set_outstanding_amount(); - }); + $(this.$body) + .find(".pos-payment-row") + .click(function () { + me.idx = $(this).attr("idx"); + me.set_outstanding_amount(); + }); - $(this.$body).find('.form-control').click(function() { - me.idx = $(this).attr("idx"); - me.set_outstanding_amount(); - me.update_paid_amount(true); - }); + $(this.$body) + .find(".form-control") + .click(function () { + me.idx = $(this).attr("idx"); + me.set_outstanding_amount(); + me.update_paid_amount(true); + }); - $(this.$body).find('.write_off_amount').change(function() { - me.write_off_amount(flt($(this).val()), precision("write_off_amount")); - }); + $(this.$body) + .find(".write_off_amount") + .change(function () { + me.write_off_amount(flt($(this).val()), precision("write_off_amount")); + }); - $(this.$body).find('.change_amount').change(function() { - me.change_amount(flt($(this).val()), precision("change_amount")); - }); + $(this.$body) + .find(".change_amount") + .change(function () { + me.change_amount(flt($(this).val()), precision("change_amount")); + }); } highlight_selected_row() { - var selected_row = $(this.$body).find(repl(".pos-payment-row[idx='%(idx)s']", {'idx': this.idx})); - $(this.$body).find('.pos-payment-row').removeClass('selected-payment-mode'); - selected_row.addClass('selected-payment-mode'); - $(this.$body).find('.amount').attr('disabled', true); - this.selected_mode.attr('disabled', false); + var selected_row = $(this.$body).find(repl(".pos-payment-row[idx='%(idx)s']", { idx: this.idx })); + $(this.$body).find(".pos-payment-row").removeClass("selected-payment-mode"); + selected_row.addClass("selected-payment-mode"); + $(this.$body).find(".amount").attr("disabled", true); + this.selected_mode.attr("disabled", false); } bind_numeric_keys_event() { var me = this; - $(this.$body).find('.pos-keyboard-key').click(function(){ - me.payment_val += $(this).text(); - me.selected_mode.val(format_currency(me.payment_val, me.frm.doc.currency)); - me.idx = me.selected_mode.attr("idx"); - me.update_paid_amount(); - }); - - $(this.$body).find('.delete-btn').click(function() { - me.payment_val = cstr(flt(me.selected_mode.val())).slice(0, -1); - me.selected_mode.val(format_currency(me.payment_val, me.frm.doc.currency)); - me.idx = me.selected_mode.attr("idx"); - me.update_paid_amount(); - }) + $(this.$body) + .find(".pos-keyboard-key") + .click(function () { + me.payment_val += $(this).text(); + me.selected_mode.val(format_currency(me.payment_val, me.frm.doc.currency)); + me.idx = me.selected_mode.attr("idx"); + me.update_paid_amount(); + }); + $(this.$body) + .find(".delete-btn") + .click(function () { + me.payment_val = cstr(flt(me.selected_mode.val())).slice(0, -1); + me.selected_mode.val(format_currency(me.payment_val, me.frm.doc.currency)); + me.idx = me.selected_mode.attr("idx"); + me.update_paid_amount(); + }); } bind_amount_change_event() { var me = this; - this.selected_mode.change(function() { - me.payment_val = flt($(this).val()) || 0.0; + this.selected_mode.change(function () { + me.payment_val = flt($(this).val()) || 0.0; me.selected_mode.val(format_currency(me.payment_val, me.frm.doc.currency)); me.idx = me.selected_mode.attr("idx"); me.update_payment_amount(); @@ -167,21 +185,25 @@ erpnext.payments = class payments extends erpnext.stock.StockController { clear_amount() { var me = this; - $(this.$body).find('.clr').click(function(e) { - e.stopPropagation(); - me.idx = $(this).attr("idx"); - me.selected_mode = $(me.$body).find(repl("input[idx='%(idx)s']",{'idx': me.idx})); - me.payment_val = 0.0; - me.selected_mode.val(0.0); - me.highlight_selected_row(); - me.update_payment_amount(); - }); + $(this.$body) + .find(".clr") + .click(function (e) { + e.stopPropagation(); + me.idx = $(this).attr("idx"); + me.selected_mode = $(me.$body).find(repl("input[idx='%(idx)s']", { idx: me.idx })); + me.payment_val = 0.0; + me.selected_mode.val(0.0); + me.highlight_selected_row(); + me.update_payment_amount(); + }); } write_off_amount(write_off_amount) { this.frm.doc.write_off_amount = flt(write_off_amount, precision("write_off_amount")); - this.frm.doc.base_write_off_amount = flt(this.frm.doc.write_off_amount * this.frm.doc.conversion_rate, - precision("base_write_off_amount")); + this.frm.doc.base_write_off_amount = flt( + this.frm.doc.write_off_amount * this.frm.doc.conversion_rate, + precision("base_write_off_amount") + ); this.calculate_outstanding_amount(false); this.show_amounts(); } @@ -196,13 +218,16 @@ erpnext.payments = class payments extends erpnext.stock.StockController { update_paid_amount(update_write_off) { var me = this; - if (in_list(['change_amount', 'write_off_amount'], this.idx)) { + if (in_list(["change_amount", "write_off_amount"], this.idx)) { var value = me.selected_mode.val(); - if (me.idx == 'change_amount') { + if (me.idx == "change_amount") { me.change_amount(value); } else { - if(flt(value) == 0 && update_write_off && me.frm.doc.outstanding_amount > 0) { - value = flt(me.frm.doc.outstanding_amount / me.frm.doc.conversion_rate, precision(me.idx)); + if (flt(value) == 0 && update_write_off && me.frm.doc.outstanding_amount > 0) { + value = flt( + me.frm.doc.outstanding_amount / me.frm.doc.conversion_rate, + precision(me.idx) + ); } me.write_off_amount(value); } @@ -211,25 +236,38 @@ erpnext.payments = class payments extends erpnext.stock.StockController { } } - update_payment_amount(){ + update_payment_amount() { var me = this; - $.each(this.frm.doc.payments, function(index, data) { + $.each(this.frm.doc.payments, function (index, data) { if (cint(me.idx) == cint(data.idx)) { data.amount = flt(me.selected_mode.val(), 2); } - }) + }); this.calculate_outstanding_amount(false); this.show_amounts(); } - show_amounts(){ + show_amounts() { var me = this; - $(this.$body).find(".write_off_amount").val(format_currency(this.frm.doc.write_off_amount, this.frm.doc.currency)); - $(this.$body).find('.paid_amount').text(format_currency(this.frm.doc.paid_amount, this.frm.doc.currency)); - $(this.$body).find('.change_amount').val(format_currency(this.frm.doc.change_amount, this.frm.doc.currency)); - $(this.$body).find('.outstanding_amount').text(format_currency(this.frm.doc.outstanding_amount, frappe.get_doc(":Company", this.frm.doc.company).default_currency)); + $(this.$body) + .find(".write_off_amount") + .val(format_currency(this.frm.doc.write_off_amount, this.frm.doc.currency)); + $(this.$body) + .find(".paid_amount") + .text(format_currency(this.frm.doc.paid_amount, this.frm.doc.currency)); + $(this.$body) + .find(".change_amount") + .val(format_currency(this.frm.doc.change_amount, this.frm.doc.currency)); + $(this.$body) + .find(".outstanding_amount") + .text( + format_currency( + this.frm.doc.outstanding_amount, + frappe.get_doc(":Company", this.frm.doc.company).default_currency + ) + ); this.update_invoice(); } -} +}; diff --git a/erpnext/public/js/projects/timer.js b/erpnext/public/js/projects/timer.js index 0209f4c2322e..8370cc6ffffb 100644 --- a/erpnext/public/js/projects/timer.js +++ b/erpnext/public/js/projects/timer.js @@ -1,26 +1,30 @@ frappe.provide("erpnext.timesheet"); -erpnext.timesheet.timer = function(frm, row, timestamp=0) { +erpnext.timesheet.timer = function (frm, row, timestamp = 0) { let dialog = new frappe.ui.Dialog({ title: __("Timer"), - fields: - [ - {"fieldtype": "Link", "label": __("Activity Type"), "fieldname": "activity_type", - "reqd": 1, "options": "Activity Type"}, - {"fieldtype": "Link", "label": __("Project"), "fieldname": "project", "options": "Project"}, - {"fieldtype": "Link", "label": __("Task"), "fieldname": "task", "options": "Task"}, - {"fieldtype": "Float", "label": __("Expected Hrs"), "fieldname": "expected_hours"}, - {"fieldtype": "Section Break"}, - {"fieldtype": "HTML", "fieldname": "timer_html"} - ] + fields: [ + { + fieldtype: "Link", + label: __("Activity Type"), + fieldname: "activity_type", + reqd: 1, + options: "Activity Type", + }, + { fieldtype: "Link", label: __("Project"), fieldname: "project", options: "Project" }, + { fieldtype: "Link", label: __("Task"), fieldname: "task", options: "Task" }, + { fieldtype: "Float", label: __("Expected Hrs"), fieldname: "expected_hours" }, + { fieldtype: "Section Break" }, + { fieldtype: "HTML", fieldname: "timer_html" }, + ], }); if (row) { dialog.set_values({ - 'activity_type': row.activity_type, - 'project': row.project, - 'task': row.task, - 'expected_hours': row.expected_hours + activity_type: row.activity_type, + project: row.project, + task: row.task, + expected_hours: row.expected_hours, }); } dialog.get_field("timer_html").$wrapper.append(get_timer_html()); @@ -34,8 +38,8 @@ erpnext.timesheet.timer = function(frm, row, timestamp=0) { 00
              - - + +
              `; } @@ -43,7 +47,7 @@ erpnext.timesheet.timer = function(frm, row, timestamp=0) { dialog.show(); }; -erpnext.timesheet.control_timer = function(frm, dialog, row, timestamp=0) { +erpnext.timesheet.control_timer = function (frm, dialog, row, timestamp = 0) { var $btn_start = dialog.$wrapper.find(".playpause .btn-start"); var $btn_complete = dialog.$wrapper.find(".playpause .btn-complete"); var interval = null; @@ -63,12 +67,16 @@ erpnext.timesheet.control_timer = function(frm, dialog, row, timestamp=0) { $btn_complete.hide(); } - $btn_start.click(function(e) { + $btn_start.click(function (e) { if (!initialized) { // New activity if no activities found var args = dialog.get_values(); - if(!args) return; - if (frm.doc.time_logs.length == 1 && !frm.doc.time_logs[0].activity_type && !frm.doc.time_logs[0].from_time) { + if (!args) return; + if ( + frm.doc.time_logs.length == 1 && + !frm.doc.time_logs[0].activity_type && + !frm.doc.time_logs[0].from_time + ) { frm.doc.time_logs = []; } row = frappe.model.add_child(frm.doc, "Timesheet Detail", "time_logs"); @@ -79,7 +87,7 @@ erpnext.timesheet.control_timer = function(frm, dialog, row, timestamp=0) { row.expected_hours = args.expected_hours; row.completed = 0; let d = moment(row.from_time); - if(row.expected_hours) { + if (row.expected_hours) { d.add(row.expected_hours, "hours"); row.to_time = d.format(frappe.defaultDatetimeFormat); } @@ -101,8 +109,8 @@ erpnext.timesheet.control_timer = function(frm, dialog, row, timestamp=0) { }); // Stop the timer and update the time logged by the timer on click of 'Complete' button - $btn_complete.click(function() { - var grid_row = cur_frm.fields_dict['time_logs'].grid.get_row(row.idx - 1); + $btn_complete.click(function () { + var grid_row = cur_frm.fields_dict["time_logs"].grid.get_row(row.idx - 1); var args = dialog.get_values(); grid_row.doc.completed = 1; grid_row.doc.activity_type = args.activity_type; @@ -119,7 +127,7 @@ erpnext.timesheet.control_timer = function(frm, dialog, row, timestamp=0) { }); function initializeTimer() { - interval = setInterval(function() { + interval = setInterval(function () { var current = setCurrentIncrement(); updateStopwatch(current); }, 1000); @@ -127,25 +135,24 @@ erpnext.timesheet.control_timer = function(frm, dialog, row, timestamp=0) { function updateStopwatch(increment) { var hours = Math.floor(increment / 3600); - var minutes = Math.floor((increment - (hours * 3600)) / 60); - var seconds = increment - (hours * 3600) - (minutes * 60); + var minutes = Math.floor((increment - hours * 3600) / 60); + var seconds = increment - hours * 3600 - minutes * 60; // If modal is closed by clicking anywhere outside, reset the timer - if (!$('.modal-dialog').is(':visible')) { + if (!$(".modal-dialog").is(":visible")) { reset(); } - if(hours > 99999) - reset(); - if(cur_dialog && cur_dialog.get_value('expected_hours') > 0) { - if(flag && (currentIncrement >= (cur_dialog.get_value('expected_hours') * 3600))) { + if (hours > 99999) reset(); + if (cur_dialog && cur_dialog.get_value("expected_hours") > 0) { + if (flag && currentIncrement >= cur_dialog.get_value("expected_hours") * 3600) { frappe.utils.play_sound("alert"); frappe.msgprint(__("Timer exceeded the given hours.")); flag = false; } } - $(".hours").text(hours < 10 ? ("0" + hours.toString()) : hours.toString()); - $(".minutes").text(minutes < 10 ? ("0" + minutes.toString()) : minutes.toString()); - $(".seconds").text(seconds < 10 ? ("0" + seconds.toString()) : seconds.toString()); + $(".hours").text(hours < 10 ? "0" + hours.toString() : hours.toString()); + $(".minutes").text(minutes < 10 ? "0" + minutes.toString() : minutes.toString()); + $(".seconds").text(seconds < 10 ? "0" + seconds.toString() : seconds.toString()); } function setCurrentIncrement() { diff --git a/erpnext/public/js/purchase_trends_filters.js b/erpnext/public/js/purchase_trends_filters.js index 77f1d2b496ae..14ffaf82162c 100644 --- a/erpnext/public/js/purchase_trends_filters.js +++ b/erpnext/public/js/purchase_trends_filters.js @@ -1,71 +1,67 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -erpnext.get_purchase_trends_filters = function() { +erpnext.get_purchase_trends_filters = function () { return [ { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "reqd": 1, - "default": frappe.defaults.get_user_default("Company") + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + reqd: 1, + default: frappe.defaults.get_user_default("Company"), }, { - "fieldname":"period", - "label": __("Period"), - "fieldtype": "Select", - "options": [ - { "value": "Monthly", "label": __("Monthly") }, - { "value": "Quarterly", "label": __("Quarterly") }, - { "value": "Half-Yearly", "label": __("Half-Yearly") }, - { "value": "Yearly", "label": __("Yearly") } + fieldname: "period", + label: __("Period"), + fieldtype: "Select", + options: [ + { value: "Monthly", label: __("Monthly") }, + { value: "Quarterly", label: __("Quarterly") }, + { value: "Half-Yearly", label: __("Half-Yearly") }, + { value: "Yearly", label: __("Yearly") }, ], - "default": "Monthly" + default: "Monthly", }, { - "fieldname":"fiscal_year", - "label": __("Fiscal Year"), - "fieldtype": "Link", - "options":'Fiscal Year', - "default": erpnext.utils.get_fiscal_year(frappe.datetime.get_today()) + fieldname: "fiscal_year", + label: __("Fiscal Year"), + fieldtype: "Link", + options: "Fiscal Year", + default: erpnext.utils.get_fiscal_year(frappe.datetime.get_today()), }, { - "fieldname":"period_based_on", - "label": __("Period based On"), - "fieldtype": "Select", - "options": [ - { "value": "posting_date", "label": __("Posting Date") }, - { "value": "bill_date", "label": __("Billing Date") }, + fieldname: "period_based_on", + label: __("Period based On"), + fieldtype: "Select", + options: [ + { value: "posting_date", label: __("Posting Date") }, + { value: "bill_date", label: __("Billing Date") }, ], - "default": "posting_date" + default: "posting_date", }, { - "fieldname":"based_on", - "label": __("Based On"), - "fieldtype": "Select", - "options": [ - { "value": "Item", "label": __("Item") }, - { "value": "Item Group", "label": __("Item Group") }, - { "value": "Supplier", "label": __("Supplier") }, - { "value": "Supplier Group", "label": __("Supplier Group") }, - { "value": "Project", "label": __("Project") } + fieldname: "based_on", + label: __("Based On"), + fieldtype: "Select", + options: [ + { value: "Item", label: __("Item") }, + { value: "Item Group", label: __("Item Group") }, + { value: "Supplier", label: __("Supplier") }, + { value: "Supplier Group", label: __("Supplier Group") }, + { value: "Project", label: __("Project") }, ], - "default": "Item", - "dashboard_config": { - "read_only": 1 - } + default: "Item", + dashboard_config: { + read_only: 1, + }, }, { - "fieldname":"group_by", - "label": __("Group By"), - "fieldtype": "Select", - "options": [ - "", - { "value": "Item", "label": __("Item") }, - { "value": "Supplier", "label": __("Supplier") } - ], - "default": "" + fieldname: "group_by", + label: __("Group By"), + fieldtype: "Select", + options: ["", { value: "Item", label: __("Item") }, { value: "Supplier", label: __("Supplier") }], + default: "", }, ]; -} +}; diff --git a/erpnext/public/js/queries.js b/erpnext/public/js/queries.js index b7d880ae408e..b7e685cd6fb8 100644 --- a/erpnext/public/js/queries.js +++ b/erpnext/public/js/queries.js @@ -4,129 +4,139 @@ // searches for enabled users frappe.provide("erpnext.queries"); $.extend(erpnext.queries, { - user: function() { + user: function () { return { query: "frappe.core.doctype.user.user.user_query" }; }, - lead: function() { + lead: function () { return { query: "erpnext.controllers.queries.lead_query" }; }, - customer: function() { + customer: function () { return { query: "erpnext.controllers.queries.customer_query" }; }, - supplier: function() { + supplier: function () { return { query: "erpnext.controllers.queries.supplier_query" }; }, - item: function(filters) { + item: function (filters) { var args = { query: "erpnext.controllers.queries.item_query" }; - if(filters) args["filters"] = filters; + if (filters) args["filters"] = filters; return args; }, - bom: function() { + bom: function () { return { query: "erpnext.controllers.queries.bom" }; }, - task: function() { + task: function () { return { query: "erpnext.projects.utils.query_task" }; }, - customer_filter: function(doc) { - if(!doc.customer) { - frappe.throw(__("Please set {0}", [__(frappe.meta.get_label(doc.doctype, "customer", doc.name))])); + customer_filter: function (doc) { + if (!doc.customer) { + frappe.throw( + __("Please set {0}", [__(frappe.meta.get_label(doc.doctype, "customer", doc.name))]) + ); } return { filters: { customer: doc.customer } }; }, - contact_query: function(doc) { - if(frappe.dynamic_link) { - if(!doc[frappe.dynamic_link.fieldname]) { - frappe.throw(__("Please set {0}", - [__(frappe.meta.get_label(doc.doctype, frappe.dynamic_link.fieldname, doc.name))])); + contact_query: function (doc) { + if (frappe.dynamic_link) { + if (!doc[frappe.dynamic_link.fieldname]) { + frappe.throw( + __("Please set {0}", [ + __(frappe.meta.get_label(doc.doctype, frappe.dynamic_link.fieldname, doc.name)), + ]) + ); } return { - query: 'frappe.contacts.doctype.contact.contact.contact_query', + query: "frappe.contacts.doctype.contact.contact.contact_query", filters: { link_doctype: frappe.dynamic_link.doctype, - link_name: doc[frappe.dynamic_link.fieldname] - } + link_name: doc[frappe.dynamic_link.fieldname], + }, }; } }, - address_query: function(doc) { - if(frappe.dynamic_link) { - if(!doc[frappe.dynamic_link.fieldname]) { - frappe.throw(__("Please set {0}", - [__(frappe.meta.get_label(doc.doctype, frappe.dynamic_link.fieldname, doc.name))])); + address_query: function (doc) { + if (frappe.dynamic_link) { + if (!doc[frappe.dynamic_link.fieldname]) { + frappe.throw( + __("Please set {0}", [ + __(frappe.meta.get_label(doc.doctype, frappe.dynamic_link.fieldname, doc.name)), + ]) + ); } return { - query: 'frappe.contacts.doctype.address.address.address_query', + query: "frappe.contacts.doctype.address.address.address_query", filters: { link_doctype: frappe.dynamic_link.doctype, - link_name: doc[frappe.dynamic_link.fieldname] - } + link_name: doc[frappe.dynamic_link.fieldname], + }, }; } }, - company_address_query: function(doc) { + company_address_query: function (doc) { return { - query: 'frappe.contacts.doctype.address.address.address_query', - filters: { is_your_company_address: 1, link_doctype: 'Company', link_name: doc.company || '' } + query: "frappe.contacts.doctype.address.address.address_query", + filters: { is_your_company_address: 1, link_doctype: "Company", link_name: doc.company || "" }, }; }, - dispatch_address_query: function(doc) { + dispatch_address_query: function (doc) { return { - query: 'frappe.contacts.doctype.address.address.address_query', - filters: { link_doctype: 'Company', link_name: doc.company || '' } + query: "frappe.contacts.doctype.address.address.address_query", + filters: { link_doctype: "Company", link_name: doc.company || "" }, }; }, - supplier_filter: function(doc) { - if(!doc.supplier) { - frappe.throw(__("Please set {0}", [__(frappe.meta.get_label(doc.doctype, "supplier", doc.name))])); + supplier_filter: function (doc) { + if (!doc.supplier) { + frappe.throw( + __("Please set {0}", [__(frappe.meta.get_label(doc.doctype, "supplier", doc.name))]) + ); } return { filters: { supplier: doc.supplier } }; }, - lead_filter: function(doc) { - if(!doc.lead) { - frappe.throw(__("Please specify a {0}", - [__(frappe.meta.get_label(doc.doctype, "lead", doc.name))])); + lead_filter: function (doc) { + if (!doc.lead) { + frappe.throw( + __("Please specify a {0}", [__(frappe.meta.get_label(doc.doctype, "lead", doc.name))]) + ); } return { filters: { lead: doc.lead } }; }, - not_a_group_filter: function() { + not_a_group_filter: function () { return { filters: { is_group: 0 } }; }, - employee: function() { - return { query: "erpnext.controllers.queries.employee_query" } + employee: function () { + return { query: "erpnext.controllers.queries.employee_query" }; }, - warehouse: function(doc) { + warehouse: function (doc) { return { filters: [ ["Warehouse", "company", "in", ["", cstr(doc.company)]], - ["Warehouse", "is_group", "=",0] - - ] + ["Warehouse", "is_group", "=", 0], + ], }; }, - get_filtered_dimensions: function(doc, child_fields, dimension, company) { - let account = ''; + get_filtered_dimensions: function (doc, child_fields, dimension, company) { + let account = ""; child_fields.forEach((field) => { if (!account) { @@ -137,21 +147,23 @@ $.extend(erpnext.queries, { return { query: "erpnext.controllers.queries.get_filtered_dimensions", filters: { - 'dimension': dimension, - 'account': account, - 'company': company - } + dimension: dimension, + account: account, + company: company, + }, }; - } + }, }); -erpnext.queries.setup_queries = function(frm, options, query_fn) { +erpnext.queries.setup_queries = function (frm, options, query_fn) { var me = this; - var set_query = function(doctype, parentfield) { - var link_fields = frappe.meta.get_docfields(doctype, frm.doc.name, - {"fieldtype": "Link", "options": options}); - $.each(link_fields, function(i, df) { - if(parentfield) { + var set_query = function (doctype, parentfield) { + var link_fields = frappe.meta.get_docfields(doctype, frm.doc.name, { + fieldtype: "Link", + options: options, + }); + $.each(link_fields, function (i, df) { + if (parentfield) { frm.set_query(df.fieldname, parentfield, query_fn); } else { frm.set_query(df.fieldname, query_fn); @@ -162,24 +174,26 @@ erpnext.queries.setup_queries = function(frm, options, query_fn) { set_query(frm.doc.doctype); // warehouse field in tables - $.each(frappe.meta.get_docfields(frm.doc.doctype, frm.doc.name, {"fieldtype": "Table"}), - function(i, df) { + $.each( + frappe.meta.get_docfields(frm.doc.doctype, frm.doc.name, { fieldtype: "Table" }), + function (i, df) { set_query(df.options, df.fieldname); - }); -} + } + ); +}; /* if item code is selected in child table then list down warehouses with its quantity else apply default filters. */ -erpnext.queries.setup_warehouse_query = function(frm){ - frm.set_query('warehouse', 'items', function(doc, cdt, cdn) { - var row = locals[cdt][cdn]; +erpnext.queries.setup_warehouse_query = function (frm) { + frm.set_query("warehouse", "items", function (doc, cdt, cdn) { + var row = locals[cdt][cdn]; var filters = erpnext.queries.warehouse(frm.doc); - if(row.item_code){ - $.extend(filters, {"query":"erpnext.controllers.queries.warehouse_query"}); + if (row.item_code) { + $.extend(filters, { query: "erpnext.controllers.queries.warehouse_query" }); filters["filters"].push(["Bin", "item_code", "=", row.item_code]); } - return filters + return filters; }); -} +}; diff --git a/erpnext/public/js/sales_trends_filters.js b/erpnext/public/js/sales_trends_filters.js index 9a70a3da4c61..85daa01ff679 100644 --- a/erpnext/public/js/sales_trends_filters.js +++ b/erpnext/public/js/sales_trends_filters.js @@ -1,61 +1,57 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -erpnext.get_sales_trends_filters = function() { - return[ +erpnext.get_sales_trends_filters = function () { + return [ { - "fieldname":"period", - "label": __("Period"), - "fieldtype": "Select", - "options": [ - { "value": "Monthly", "label": __("Monthly") }, - { "value": "Quarterly", "label": __("Quarterly") }, - { "value": "Half-Yearly", "label": __("Half-Yearly") }, - { "value": "Yearly", "label": __("Yearly") } + fieldname: "period", + label: __("Period"), + fieldtype: "Select", + options: [ + { value: "Monthly", label: __("Monthly") }, + { value: "Quarterly", label: __("Quarterly") }, + { value: "Half-Yearly", label: __("Half-Yearly") }, + { value: "Yearly", label: __("Yearly") }, ], - "default": "Monthly" + default: "Monthly", }, { - "fieldname":"based_on", - "label": __("Based On"), - "fieldtype": "Select", - "options": [ - { "value": "Item", "label": __("Item") }, - { "value": "Item Group", "label": __("Item Group") }, - { "value": "Customer", "label": __("Customer") }, - { "value": "Customer Group", "label": __("Customer Group") }, - { "value": "Territory", "label": __("Territory") }, - { "value": "Project", "label": __("Project") } + fieldname: "based_on", + label: __("Based On"), + fieldtype: "Select", + options: [ + { value: "Item", label: __("Item") }, + { value: "Item Group", label: __("Item Group") }, + { value: "Customer", label: __("Customer") }, + { value: "Customer Group", label: __("Customer Group") }, + { value: "Territory", label: __("Territory") }, + { value: "Project", label: __("Project") }, ], - "default": "Item", - "dashboard_config": { - "read_only": 1, - } + default: "Item", + dashboard_config: { + read_only: 1, + }, }, { - "fieldname":"group_by", - "label": __("Group By"), - "fieldtype": "Select", - "options": [ - "", - { "value": "Item", "label": __("Item") }, - { "value": "Customer", "label": __("Customer") } - ], - "default": "" + fieldname: "group_by", + label: __("Group By"), + fieldtype: "Select", + options: ["", { value: "Item", label: __("Item") }, { value: "Customer", label: __("Customer") }], + default: "", }, { - "fieldname":"fiscal_year", - "label": __("Fiscal Year"), - "fieldtype": "Link", - "options":'Fiscal Year', - "default": erpnext.utils.get_fiscal_year(frappe.datetime.get_today()) + fieldname: "fiscal_year", + label: __("Fiscal Year"), + fieldtype: "Link", + options: "Fiscal Year", + default: erpnext.utils.get_fiscal_year(frappe.datetime.get_today()), }, { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_user_default("Company") + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), }, ]; -} +}; diff --git a/erpnext/public/js/setup_wizard.js b/erpnext/public/js/setup_wizard.js index 934fd1f88ae2..b146cd19a363 100644 --- a/erpnext/public/js/setup_wizard.js +++ b/erpnext/public/js/setup_wizard.js @@ -1,7 +1,7 @@ frappe.provide("erpnext.setup"); -frappe.pages['setup-wizard'].on_page_load = function(wrapper) { - if(frappe.sys_defaults.company) { +frappe.pages["setup-wizard"].on_page_load = function (wrapper) { + if (frappe.sys_defaults.company) { frappe.set_route("desk"); return; } @@ -14,32 +14,34 @@ frappe.setup.on("before_load", function () { erpnext.setup.slides_settings = [ { // Organization - name: 'organization', + name: "organization", title: __("Setup your organization"), icon: "fa fa-building", fields: [ { - fieldname: 'company_name', - label: __('Company Name'), - fieldtype: 'Data', - reqd: 1 + fieldname: "company_name", + label: __("Company Name"), + fieldtype: "Data", + reqd: 1, }, { fieldtype: "Column Break" }, { - fieldname: 'company_abbr', - label: __('Company Abbreviation'), - fieldtype: 'Data', - reqd: 1 + fieldname: "company_abbr", + label: __("Company Abbreviation"), + fieldtype: "Data", + reqd: 1, }, { fieldtype: "Section Break" }, { - fieldname: 'chart_of_accounts', label: __('Chart of Accounts'), - options: "", fieldtype: 'Select' + fieldname: "chart_of_accounts", + label: __("Chart of Accounts"), + options: "", + fieldtype: "Select", }, - { fieldname: 'view_coa', label: __('View Chart of Accounts'), fieldtype: 'Button' }, - { fieldname: 'fy_start_date', label: __('Financial Year Begins On'), fieldtype: 'Date', reqd: 1 }, + { fieldname: "view_coa", label: __("View Chart of Accounts"), fieldtype: "Button" }, + { fieldname: "fy_start_date", label: __("Financial Year Begins On"), fieldtype: "Date", reqd: 1 }, // end date should be hidden (auto calculated) - { fieldname: 'fy_end_date', label: __('End Date'), fieldtype: 'Date', reqd: 1, hidden: 1 }, + { fieldname: "fy_end_date", label: __("End Date"), fieldtype: "Date", reqd: 1, hidden: 1 }, ], onload: function (slide) { @@ -66,10 +68,10 @@ erpnext.setup.slides_settings = [ return true; }, - validate_fy_dates: function() { + validate_fy_dates: function () { // validate fiscal year start and end dates - const invalid = this.values.fy_start_date == 'Invalid date' || - this.values.fy_end_date == 'Invalid date'; + const invalid = + this.values.fy_start_date == "Invalid date" || this.values.fy_end_date == "Invalid date"; const start_greater_than_end = this.values.fy_start_date > this.values.fy_end_date; if (invalid || start_greater_than_end) { @@ -97,26 +99,24 @@ erpnext.setup.slides_settings = [ next_year = current_year; current_year -= 1; } - slide.get_field("fy_start_date").set_value(current_year + '-' + fy[0]); - slide.get_field("fy_end_date").set_value(next_year + '-' + fy[1]); + slide.get_field("fy_start_date").set_value(current_year + "-" + fy[0]); + slide.get_field("fy_end_date").set_value(next_year + "-" + fy[1]); } }, - load_chart_of_accounts: function (slide) { let country = frappe.wizard.values.country; if (country) { frappe.call({ method: "erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts.get_charts_for_country", - args: { "country": country, with_standard: true }, + args: { country: country, with_standard: true }, callback: function (r) { if (r.message) { - slide.get_input("chart_of_accounts").empty() - .add_options(r.message); + slide.get_input("chart_of_accounts").empty().add_options(r.message); } - } - }) + }, + }); } }, @@ -124,56 +124,74 @@ erpnext.setup.slides_settings = [ let me = this; slide.get_input("fy_start_date").on("change", function () { var start_date = slide.form.fields_dict.fy_start_date.get_value(); - var year_end_date = - frappe.datetime.add_days(frappe.datetime.add_months(start_date, 12), -1); + var year_end_date = frappe.datetime.add_days(frappe.datetime.add_months(start_date, 12), -1); slide.form.fields_dict.fy_end_date.set_value(year_end_date); }); - slide.get_input("view_coa").on("click", function() { + slide.get_input("view_coa").on("click", function () { let chart_template = slide.form.fields_dict.chart_of_accounts.get_value(); - if(!chart_template) return; + if (!chart_template) return; me.charts_modal(slide, chart_template); }); - slide.get_input("company_name").on("input", function () { - let parts = slide.get_input("company_name").val().split(" "); - let abbr = $.map(parts, function (p) { return p ? p.substr(0, 1) : null }).join(""); - slide.get_field("company_abbr").set_value(abbr.slice(0, 10).toUpperCase()); - }).val(frappe.boot.sysdefaults.company_name || "").trigger("change"); - - slide.get_input("company_abbr").on("change", function () { - let abbr = slide.get_input("company_abbr").val(); - if (abbr.length > 10) { - frappe.msgprint(__("Company Abbreviation cannot have more than 5 characters")); - abbr = abbr.slice(0, 10); - } - slide.get_field("company_abbr").set_value(abbr); - }).val(frappe.boot.sysdefaults.company_abbr || "").trigger("change"); + slide + .get_input("company_name") + .on("input", function () { + let parts = slide.get_input("company_name").val().split(" "); + let abbr = $.map(parts, function (p) { + return p ? p.substr(0, 1) : null; + }).join(""); + slide.get_field("company_abbr").set_value(abbr.slice(0, 10).toUpperCase()); + }) + .val(frappe.boot.sysdefaults.company_name || "") + .trigger("change"); + + slide + .get_input("company_abbr") + .on("change", function () { + let abbr = slide.get_input("company_abbr").val(); + if (abbr.length > 10) { + frappe.msgprint(__("Company Abbreviation cannot have more than 5 characters")); + abbr = abbr.slice(0, 10); + } + slide.get_field("company_abbr").set_value(abbr); + }) + .val(frappe.boot.sysdefaults.company_abbr || "") + .trigger("change"); }, - charts_modal: function(slide, chart_template) { - let parent = __('All Accounts'); + charts_modal: function (slide, chart_template) { + let parent = __("All Accounts"); let dialog = new frappe.ui.Dialog({ title: chart_template, fields: [ - {'fieldname': 'expand_all', 'label': __('Expand All'), 'fieldtype': 'Button', - click: function() { + { + fieldname: "expand_all", + label: __("Expand All"), + fieldtype: "Button", + click: function () { // expand all nodes on button click coa_tree.load_children(coa_tree.root_node, true); - } + }, }, - {'fieldname': 'collapse_all', 'label': __('Collapse All'), 'fieldtype': 'Button', - click: function() { + { + fieldname: "collapse_all", + label: __("Collapse All"), + fieldtype: "Button", + click: function () { // collapse all nodes - coa_tree.get_all_nodes(coa_tree.root_node.data.value, coa_tree.root_node.is_root) - .then(data_list => { - data_list.map(d => { coa_tree.toggle_node(coa_tree.nodes[d.parent]); }); + coa_tree + .get_all_nodes(coa_tree.root_node.data.value, coa_tree.root_node.is_root) + .then((data_list) => { + data_list.map((d) => { + coa_tree.toggle_node(coa_tree.nodes[d.parent]); + }); }); - } - } - ] + }, + }, + ], }); // render tree structure in the dialog modal @@ -181,49 +199,49 @@ erpnext.setup.slides_settings = [ parent: $(dialog.body), label: parent, expandable: true, - method: 'erpnext.accounts.utils.get_coa', + method: "erpnext.accounts.utils.get_coa", args: { chart: chart_template, parent: parent, - doctype: 'Account' + doctype: "Account", }, - onclick: function(node) { + onclick: function (node) { parent = node.value; - } + }, }); // add class to show buttons side by side - const form_container = $(dialog.body).find('form'); - const buttons = $(form_container).find('.frappe-control'); - form_container.addClass('flex'); + const form_container = $(dialog.body).find("form"); + const buttons = $(form_container).find(".frappe-control"); + form_container.addClass("flex"); buttons.map((index, button) => { - $(button).css({"margin-right": "1em"}); - }) + $(button).css({ "margin-right": "1em" }); + }); dialog.show(); coa_tree.load_children(coa_tree.root_node, true); // expand all node trigger - } - } + }, + }, ]; // Source: https://en.wikipedia.org/wiki/Fiscal_year // default 1st Jan - 31st Dec erpnext.setup.fiscal_years = { - "Afghanistan": ["12-21", "12-20"], - "Australia": ["07-01", "06-30"], - "Bangladesh": ["07-01", "06-30"], - "Canada": ["04-01", "03-31"], + Afghanistan: ["12-21", "12-20"], + Australia: ["07-01", "06-30"], + Bangladesh: ["07-01", "06-30"], + Canada: ["04-01", "03-31"], "Costa Rica": ["10-01", "09-30"], - "Egypt": ["07-01", "06-30"], + Egypt: ["07-01", "06-30"], "Hong Kong": ["04-01", "03-31"], - "India": ["04-01", "03-31"], - "Iran": ["06-23", "06-22"], - "Myanmar": ["04-01", "03-31"], + India: ["04-01", "03-31"], + Iran: ["06-23", "06-22"], + Myanmar: ["04-01", "03-31"], "New Zealand": ["04-01", "03-31"], - "Pakistan": ["07-01", "06-30"], - "Singapore": ["04-01", "03-31"], + Pakistan: ["07-01", "06-30"], + Singapore: ["04-01", "03-31"], "South Africa": ["03-01", "02-28"], - "Thailand": ["10-01", "09-30"], + Thailand: ["10-01", "09-30"], "United Kingdom": ["04-01", "03-31"], }; diff --git a/erpnext/public/js/shopping_cart.js b/erpnext/public/js/shopping_cart.js index d14740c1060d..45ac9ad7ac40 100644 --- a/erpnext/public/js/shopping_cart.js +++ b/erpnext/public/js/shopping_cart.js @@ -7,45 +7,46 @@ var shopping_cart = erpnext.e_commerce.shopping_cart; var getParams = function (url) { var params = []; - var parser = document.createElement('a'); + var parser = document.createElement("a"); parser.href = url; var query = parser.search.substring(1); - var vars = query.split('&'); + var vars = query.split("&"); for (var i = 0; i < vars.length; i++) { - var pair = vars[i].split('='); + var pair = vars[i].split("="); params[pair[0]] = decodeURIComponent(pair[1]); } return params; }; -frappe.ready(function() { +frappe.ready(function () { var full_name = frappe.session && frappe.session.user_fullname; // update user - if(full_name) { - $('.navbar li[data-label="User"] a') - .html(' ' + full_name); + if (full_name) { + $('.navbar li[data-label="User"] a').html( + ' ' + full_name + ); } // set coupon code and sales partner code var url_args = getParams(window.location.href); - var referral_coupon_code = url_args['cc']; - var referral_sales_partner = url_args['sp']; + var referral_coupon_code = url_args["cc"]; + var referral_sales_partner = url_args["sp"]; var d = new Date(); // expires within 30 minutes - d.setTime(d.getTime() + (0.02 * 24 * 60 * 60 * 1000)); - var expires = "expires="+d.toUTCString(); + d.setTime(d.getTime() + 0.02 * 24 * 60 * 60 * 1000); + var expires = "expires=" + d.toUTCString(); if (referral_coupon_code) { document.cookie = "referral_coupon_code=" + referral_coupon_code + ";" + expires + ";path=/"; } if (referral_sales_partner) { document.cookie = "referral_sales_partner=" + referral_sales_partner + ";" + expires + ";path=/"; } - referral_coupon_code=frappe.get_cookie("referral_coupon_code"); - referral_sales_partner=frappe.get_cookie("referral_sales_partner"); + referral_coupon_code = frappe.get_cookie("referral_coupon_code"); + referral_sales_partner = frappe.get_cookie("referral_sales_partner"); - if (referral_coupon_code && $(".tot_quotation_discount").val()==undefined ) { + if (referral_coupon_code && $(".tot_quotation_discount").val() == undefined) { $(".txtcoupon").val(referral_coupon_code); } if (referral_sales_partner) { @@ -59,27 +60,27 @@ frappe.ready(function() { }); $.extend(shopping_cart, { - show_shoppingcart_dropdown: function() { - $(".shopping-cart").on('shown.bs.dropdown', function() { - if (!$('.shopping-cart-menu .cart-container').length) { + show_shoppingcart_dropdown: function () { + $(".shopping-cart").on("shown.bs.dropdown", function () { + if (!$(".shopping-cart-menu .cart-container").length) { return frappe.call({ - method: 'erpnext.e_commerce.shopping_cart.cart.get_shopping_cart_menu', - callback: function(r) { + method: "erpnext.e_commerce.shopping_cart.cart.get_shopping_cart_menu", + callback: function (r) { if (r.message) { - $('.shopping-cart-menu').html(r.message); + $(".shopping-cart-menu").html(r.message); } - } + }, }); } }); }, - update_cart: function(opts) { - if (frappe.session.user==="Guest") { + update_cart: function (opts) { + if (frappe.session.user === "Guest") { if (localStorage) { localStorage.setItem("last_visited", window.location.pathname); } - frappe.call('erpnext.e_commerce.api.get_guest_redirect_on_action').then((res) => { + frappe.call("erpnext.e_commerce.api.get_guest_redirect_on_action").then((res) => { window.location.href = res.message || "/login"; }); } else { @@ -91,35 +92,34 @@ $.extend(shopping_cart, { item_code: opts.item_code, qty: opts.qty, additional_notes: opts.additional_notes !== undefined ? opts.additional_notes : undefined, - with_items: opts.with_items || 0 + with_items: opts.with_items || 0, }, btn: opts.btn, - callback: function(r) { + callback: function (r) { shopping_cart.unfreeze(); shopping_cart.set_cart_count(true); - if(opts.callback) - opts.callback(r); - } + if (opts.callback) opts.callback(r); + }, }); } }, - set_cart_count: function(animate=false) { + set_cart_count: function (animate = false) { $(".intermediate-empty-cart").remove(); var cart_count = frappe.get_cookie("cart_count"); - if(frappe.session.user==="Guest") { + if (frappe.session.user === "Guest") { cart_count = 0; } - if(cart_count) { - $(".shopping-cart").toggleClass('hidden', false); + if (cart_count) { + $(".shopping-cart").toggleClass("hidden", false); } - var $cart = $('.cart-icon'); + var $cart = $(".cart-icon"); var $badge = $cart.find("#cart-count"); - if(parseInt(cart_count) === 0 || cart_count === undefined) { + if (parseInt(cart_count) === 0 || cart_count === undefined) { $cart.css("display", "none"); $(".cart-tax-items").hide(); $(".btn-place-order").hide(); @@ -127,17 +127,16 @@ $.extend(shopping_cart, { let intermediate_empty_cart_msg = `
              - ${ __("Cart is Empty") } + ${__("Cart is Empty")}
              `; $(".cart-table").after(intermediate_empty_cart_msg); - } - else { + } else { $cart.css("display", "inline"); $("#cart-count").text(cart_count); } - if(cart_count) { + if (cart_count) { $badge.html(cart_count); if (animate) { @@ -151,15 +150,15 @@ $.extend(shopping_cart, { } }, - shopping_cart_update: function({item_code, qty, cart_dropdown, additional_notes}) { + shopping_cart_update: function ({ item_code, qty, cart_dropdown, additional_notes }) { shopping_cart.update_cart({ item_code, qty, additional_notes, with_items: 1, btn: this, - callback: function(r) { - if(!r.exc) { + callback: function (r) { + if (!r.exc) { $(".cart-items").html(r.message.items); $(".cart-tax-items").html(r.message.total); $(".payment-summary").html(r.message.taxes_and_totals); @@ -176,9 +175,9 @@ $.extend(shopping_cart, { show_cart_navbar: function () { frappe.call({ method: "erpnext.e_commerce.doctype.e_commerce_settings.e_commerce_settings.is_cart_enabled", - callback: function(r) { - $(".shopping-cart").toggleClass('hidden', r.message ? false : true); - } + callback: function (r) { + $(".shopping-cart").toggleClass("hidden", r.message ? false : true); + }, }); }, @@ -188,43 +187,41 @@ $.extend(shopping_cart, { }, bind_add_to_cart_action() { - $('.page_content').on('click', '.btn-add-to-cart-list', (e) => { + $(".page_content").on("click", ".btn-add-to-cart-list", (e) => { const $btn = $(e.currentTarget); - $btn.prop('disabled', true); + $btn.prop("disabled", true); - if (frappe.session.user==="Guest") { + if (frappe.session.user === "Guest") { if (localStorage) { localStorage.setItem("last_visited", window.location.pathname); } - frappe.call('erpnext.e_commerce.api.get_guest_redirect_on_action').then((res) => { + frappe.call("erpnext.e_commerce.api.get_guest_redirect_on_action").then((res) => { window.location.href = res.message || "/login"; }); return; } - $btn.addClass('hidden'); - $btn.closest('.cart-action-container').addClass('d-flex'); - $btn.parent().find('.go-to-cart').removeClass('hidden'); - $btn.parent().find('.go-to-cart-grid').removeClass('hidden'); - $btn.parent().find('.cart-indicator').removeClass('hidden'); + $btn.addClass("hidden"); + $btn.closest(".cart-action-container").addClass("d-flex"); + $btn.parent().find(".go-to-cart").removeClass("hidden"); + $btn.parent().find(".go-to-cart-grid").removeClass("hidden"); + $btn.parent().find(".cart-indicator").removeClass("hidden"); - const item_code = $btn.data('item-code'); + const item_code = $btn.data("item-code"); erpnext.e_commerce.shopping_cart.update_cart({ item_code, - qty: 1 + qty: 1, }); - }); }, freeze() { if (window.location.pathname !== "/cart") return; - if (!$('#freeze').length) { - let freeze = $('') - .appendTo("body"); + if (!$("#freeze").length) { + let freeze = $('').appendTo("body"); - setTimeout(function() { + setTimeout(function () { freeze.addClass("show"); }, 1); } else { @@ -233,11 +230,11 @@ $.extend(shopping_cart, { }, unfreeze() { - if ($('#freeze').length) { - let freeze = $('#freeze').removeClass("show"); - setTimeout(function() { + if ($("#freeze").length) { + let freeze = $("#freeze").removeClass("show"); + setTimeout(function () { freeze.remove(); }, 1); } - } + }, }); diff --git a/erpnext/public/js/sms_manager.js b/erpnext/public/js/sms_manager.js index a058da23ac40..d3147bb46002 100644 --- a/erpnext/public/js/sms_manager.js +++ b/erpnext/public/js/sms_manager.js @@ -3,104 +3,114 @@ erpnext.SMSManager = function SMSManager(doc) { var me = this; - this.setup = function() { + this.setup = function () { var default_msg = { - 'Lead' : '', - 'Opportunity' : 'Your enquiry has been logged into the system. Ref No: ' + doc.name, - 'Quotation' : 'Quotation ' + doc.name + ' has been sent via email. Thanks!', - 'Sales Order' : 'Sales Order ' + doc.name + ' has been created against ' - + (doc.quotation_no ? ('Quote No:' + doc.quotation_no) : '') - + (doc.po_no ? (' for your PO: ' + doc.po_no) : ''), - 'Delivery Note' : 'Items has been delivered against delivery note: ' + doc.name - + (doc.po_no ? (' for your PO: ' + doc.po_no) : ''), - 'Sales Invoice': 'Invoice ' + doc.name + ' has been sent via email ' - + (doc.po_no ? (' for your PO: ' + doc.po_no) : ''), - 'Material Request' : 'Material Request ' + doc.name + ' has been raised in the system', - 'Purchase Order' : 'Purchase Order ' + doc.name + ' has been sent via email', - 'Purchase Receipt' : 'Items has been received against purchase receipt: ' + doc.name - } - - if (in_list(['Sales Order', 'Delivery Note', 'Sales Invoice'], doc.doctype)) - this.show(doc.contact_person, 'Customer', doc.customer, '', default_msg[doc.doctype]); - else if (doc.doctype === 'Quotation') - this.show(doc.contact_person, 'Customer', doc.party_name, '', default_msg[doc.doctype]); - else if (in_list(['Purchase Order', 'Purchase Receipt'], doc.doctype)) - this.show(doc.contact_person, 'Supplier', doc.supplier, '', default_msg[doc.doctype]); - else if (doc.doctype == 'Lead') - this.show('', '', '', doc.mobile_no, default_msg[doc.doctype]); - else if (doc.doctype == 'Opportunity') - this.show('', '', '', doc.contact_no, default_msg[doc.doctype]); - else if (doc.doctype == 'Material Request') - this.show('', '', '', '', default_msg[doc.doctype]); + Lead: "", + Opportunity: "Your enquiry has been logged into the system. Ref No: " + doc.name, + Quotation: "Quotation " + doc.name + " has been sent via email. Thanks!", + "Sales Order": + "Sales Order " + + doc.name + + " has been created against " + + (doc.quotation_no ? "Quote No:" + doc.quotation_no : "") + + (doc.po_no ? " for your PO: " + doc.po_no : ""), + "Delivery Note": + "Items has been delivered against delivery note: " + + doc.name + + (doc.po_no ? " for your PO: " + doc.po_no : ""), + "Sales Invoice": + "Invoice " + + doc.name + + " has been sent via email " + + (doc.po_no ? " for your PO: " + doc.po_no : ""), + "Material Request": "Material Request " + doc.name + " has been raised in the system", + "Purchase Order": "Purchase Order " + doc.name + " has been sent via email", + "Purchase Receipt": "Items has been received against purchase receipt: " + doc.name, + }; + if (in_list(["Sales Order", "Delivery Note", "Sales Invoice"], doc.doctype)) + this.show(doc.contact_person, "Customer", doc.customer, "", default_msg[doc.doctype]); + else if (doc.doctype === "Quotation") + this.show(doc.contact_person, "Customer", doc.party_name, "", default_msg[doc.doctype]); + else if (in_list(["Purchase Order", "Purchase Receipt"], doc.doctype)) + this.show(doc.contact_person, "Supplier", doc.supplier, "", default_msg[doc.doctype]); + else if (doc.doctype == "Lead") this.show("", "", "", doc.mobile_no, default_msg[doc.doctype]); + else if (doc.doctype == "Opportunity") + this.show("", "", "", doc.contact_no, default_msg[doc.doctype]); + else if (doc.doctype == "Material Request") this.show("", "", "", "", default_msg[doc.doctype]); }; - this.get_contact_number = function(contact, ref_doctype, ref_name) { + this.get_contact_number = function (contact, ref_doctype, ref_name) { frappe.call({ method: "frappe.core.doctype.sms_settings.sms_settings.get_contact_number", args: { contact_name: contact, ref_doctype: ref_doctype, - ref_name: ref_name + ref_name: ref_name, }, - callback: function(r) { - if(r.exc) { frappe.msgprint(r.exc); return; } + callback: function (r) { + if (r.exc) { + frappe.msgprint(r.exc); + return; + } me.number = r.message; me.show_dialog(); - } + }, }); }; - this.show = function(contact, ref_doctype, ref_name, mobile_nos, message) { + this.show = function (contact, ref_doctype, ref_name, mobile_nos, message) { this.message = message; if (mobile_nos) { me.number = mobile_nos; me.show_dialog(); - } else if (contact){ - this.get_contact_number(contact, ref_doctype, ref_name) + } else if (contact) { + this.get_contact_number(contact, ref_doctype, ref_name); } else { me.show_dialog(); } - } - this.show_dialog = function() { - if(!me.dialog) - me.make_dialog(); + }; + this.show_dialog = function () { + if (!me.dialog) me.make_dialog(); me.dialog.set_values({ - 'message': me.message, - 'number': me.number - }) + message: me.message, + number: me.number, + }); me.dialog.show(); - } - this.make_dialog = function() { + }; + this.make_dialog = function () { var d = new frappe.ui.Dialog({ - title: 'Send SMS', + title: "Send SMS", width: 400, fields: [ - {fieldname:'number', fieldtype:'Data', label:'Mobile Number', reqd:1}, - {fieldname:'message', fieldtype:'Text', label:'Message', reqd:1}, - {fieldname:'send', fieldtype:'Button', label:'Send'} - ] - }) - d.fields_dict.send.input.onclick = function() { + { fieldname: "number", fieldtype: "Data", label: "Mobile Number", reqd: 1 }, + { fieldname: "message", fieldtype: "Text", label: "Message", reqd: 1 }, + { fieldname: "send", fieldtype: "Button", label: "Send" }, + ], + }); + d.fields_dict.send.input.onclick = function () { var btn = d.fields_dict.send.input; var v = me.dialog.get_values(); - if(v) { + if (v) { $(btn).set_working(); frappe.call({ method: "frappe.core.doctype.sms_settings.sms_settings.send_sms", args: { receiver_list: [v.number], - msg: v.message + msg: v.message, }, - callback: function(r) { + callback: function (r) { $(btn).done_working(); - if(r.exc) {frappe.msgprint(r.exc); return; } + if (r.exc) { + frappe.msgprint(r.exc); + return; + } me.dialog.hide(); - } + }, }); } - } + }; this.dialog = d; - } + }; this.setup(); -} +}; diff --git a/erpnext/public/js/stock_analytics.js b/erpnext/public/js/stock_analytics.js index a343c3402afd..1c75d161e647 100644 --- a/erpnext/public/js/stock_analytics.js +++ b/erpnext/public/js/stock_analytics.js @@ -1,68 +1,104 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt - erpnext.StockAnalytics = class StockAnalytics extends erpnext.StockGridReport { constructor(wrapper, opts) { var args = { title: __("Stock Analytics"), - parent: $(wrapper).find('.layout-main'), + parent: $(wrapper).find(".layout-main"), page: wrapper.page, - doctypes: ["Item", "Item Group", "Warehouse", "Stock Ledger Entry", "Brand", - "Fiscal Year", "Serial No"], + doctypes: [ + "Item", + "Item Group", + "Warehouse", + "Stock Ledger Entry", + "Brand", + "Fiscal Year", + "Serial No", + ], tree_grid: { show: true, parent_field: "parent_item_group", - formatter: function(item) { - if(!item.is_group) { - return repl("\ - %(value)s", { + %(value)s", + { value: item.name, - }); + } + ); } else { return item.name; } - - } + }, }, - } + }; - if(opts) $.extend(args, opts); + if (opts) $.extend(args, opts); super(args); this.filters = [ - {fieldtype:"Select", label: __("Value or Qty"), fieldname: "value_or_qty", - options:[{label:__("Value"), value:"Value"}, {label:__("Quantity"), value:"Quantity"}], - filter: function(val, item, opts, me) { + { + fieldtype: "Select", + label: __("Value or Qty"), + fieldname: "value_or_qty", + options: [ + { label: __("Value"), value: "Value" }, + { label: __("Quantity"), value: "Quantity" }, + ], + filter: function (val, item, opts, me) { return me.apply_zero_filter(val, item, opts, me); - }}, - {fieldtype:"Select", label: __("Brand"), link:"Brand", fieldname: "brand", - default_value: __("Select Brand..."), filter: function(val, item, opts) { + }, + }, + { + fieldtype: "Select", + label: __("Brand"), + link: "Brand", + fieldname: "brand", + default_value: __("Select Brand..."), + filter: function (val, item, opts) { return val == opts.default_value || item.brand == val || item._show; - }, link_formatter: {filter_input: "brand"}}, - {fieldtype:"Select", label: __("Warehouse"), link:"Warehouse", fieldname: "warehouse", - default_value: __("Select Warehouse...")}, - {fieldtype:"Date", label: __("From Date"), fieldname: "from_date"}, - {fieldtype:"Date", label: __("To Date"), fieldname: "to_date"}, - {fieldtype:"Select", label: __("Range"), fieldname: "range", - options:[ - {label:__("Daily"), value:"Daily"}, - {label:__("Weekly"), value:"Weekly"}, - {label:__("Monthly"), value:"Monthly"}, - {label:__("Quarterly"), value:"Quarterly"}, - {label:__("Yearly"), value:"Yearly"}, - ]} + }, + link_formatter: { filter_input: "brand" }, + }, + { + fieldtype: "Select", + label: __("Warehouse"), + link: "Warehouse", + fieldname: "warehouse", + default_value: __("Select Warehouse..."), + }, + { fieldtype: "Date", label: __("From Date"), fieldname: "from_date" }, + { fieldtype: "Date", label: __("To Date"), fieldname: "to_date" }, + { + fieldtype: "Select", + label: __("Range"), + fieldname: "range", + options: [ + { label: __("Daily"), value: "Daily" }, + { label: __("Weekly"), value: "Weekly" }, + { label: __("Monthly"), value: "Monthly" }, + { label: __("Quarterly"), value: "Quarterly" }, + { label: __("Yearly"), value: "Yearly" }, + ], + }, ]; } setup_columns() { var std_columns = [ - {id: "name", name: __("Item"), field: "name", width: 300}, - {id: "brand", name: __("Brand"), field: "brand", width: 100}, - {id: "stock_uom", name: __("UOM"), field: "stock_uom", width: 100}, - {id: "opening", name: __("Opening"), field: "opening", hidden: true, - formatter: this.currency_formatter} + { id: "name", name: __("Item"), field: "name", width: 300 }, + { id: "brand", name: __("Brand"), field: "brand", width: 100 }, + { id: "stock_uom", name: __("UOM"), field: "stock_uom", width: 100 }, + { + id: "opening", + name: __("Opening"), + field: "opening", + hidden: true, + formatter: this.currency_formatter, + }, ]; this.make_date_range_columns(); @@ -79,24 +115,24 @@ erpnext.StockAnalytics = class StockAnalytics extends erpnext.StockGridReport { } init_filter_values() { super.init_filter_values(); - this.filter_inputs.range && this.filter_inputs.range.val('Monthly'); + this.filter_inputs.range && this.filter_inputs.range.val("Monthly"); } prepare_data() { var me = this; - if(!this.data) { + if (!this.data) { var items = this.prepare_tree("Item", "Item Group"); me.parent_map = {}; me.item_by_name = {}; me.data = []; - $.each(items, function(i, v) { + $.each(items, function (i, v) { var d = copy_dict(v); me.data.push(d); me.item_by_name[d.name] = d; - if(d.parent_item_group) { + if (d.parent_item_group) { me.parent_map[d.name] = d.parent_item_group; } me.reset_item_values(d); @@ -105,7 +141,7 @@ erpnext.StockAnalytics = class StockAnalytics extends erpnext.StockGridReport { this.data[0].checked = true; } else { // otherwise, only reset values - $.each(this.data, function(i, d) { + $.each(this.data, function (i, d) { me.reset_item_values(d); d["closing_qty_value"] = 0; }); @@ -113,7 +149,6 @@ erpnext.StockAnalytics = class StockAnalytics extends erpnext.StockGridReport { this.prepare_balances(); this.update_groups(); - } prepare_balances() { var me = this; @@ -124,23 +159,24 @@ erpnext.StockAnalytics = class StockAnalytics extends erpnext.StockGridReport { this.item_warehouse = {}; this.serialized_buying_rates = this.get_serialized_buying_rates(); - for(var i=0, j=data.length; i 0) { + if (sl.qty > 0) { // incoming - rate is given var rate = sl.incoming_rate; var add_qty = sl.qty; - if(wh.balance_qty < 0) { + if (wh.balance_qty < 0) { // negative valuation // only add value of quantity if // the balance goes above 0 add_qty = wh.balance_qty + sl.qty; - if(add_qty < 0) { + if (add_qty < 0) { add_qty = 0; } } - if(sl.serial_no) { + if (sl.serial_no) { var value_diff = this.get_serialized_value_diff(sl); } else { - var value_diff = (rate * add_qty); + var value_diff = rate * add_qty; } - if(add_qty) - wh.fifo_stack.push([add_qty, sl.incoming_rate, sl.posting_date]); + if (add_qty) wh.fifo_stack.push([add_qty, sl.incoming_rate, sl.posting_date]); } else { // called everytime for maintaining fifo stack var fifo_value_diff = this.get_fifo_value_diff(wh, sl); // outgoing - if(sl.serial_no) { + if (sl.serial_no) { var value_diff = -1 * this.get_serialized_value_diff(sl); - } else if(is_fifo) { + } else if (is_fifo) { var value_diff = fifo_value_diff; } else { // average rate for weighted average - var rate = (wh.balance_qty.toFixed(2) == 0.00 ? 0 : - flt(wh.balance_value) / flt(wh.balance_qty)); + var rate = wh.balance_qty.toFixed(2) == 0.0 ? 0 : flt(wh.balance_value) / flt(wh.balance_qty); // no change in value if negative qty - if((wh.balance_qty + sl.qty).toFixed(2) >= 0.00) - var value_diff = (rate * sl.qty); - else - var value_diff = -wh.balance_value; + if ((wh.balance_qty + sl.qty).toFixed(2) >= 0.0) var value_diff = rate * sl.qty; + else var value_diff = -wh.balance_value; } } @@ -66,14 +65,14 @@ erpnext.StockGridReport = class StockGridReport extends frappe.views.TreeGridRep var fifo_value_diff = 0.0; var qty = -sl.qty; - for(var i=0, j=fifo_stack.length; i= qty) { + if (batch[0] >= qty) { batch[0] = batch[0] - qty; - fifo_value_diff += (qty * batch[1]); + fifo_value_diff += qty * batch[1]; qty = 0.0; - if(batch[0]) { + if (batch[0]) { // batch still has qty put it back fifo_stack.push(batch); } @@ -82,7 +81,7 @@ erpnext.StockGridReport = class StockGridReport extends frappe.views.TreeGridRep break; } else { // consume this batch fully - fifo_value_diff += (batch[0] * batch[1]); + fifo_value_diff += batch[0] * batch[1]; qty = qty - batch[0]; } } @@ -96,8 +95,8 @@ erpnext.StockGridReport = class StockGridReport extends frappe.views.TreeGridRep var value_diff = 0.0; - $.each(sl.serial_no.trim().split("\n"), function(i, sr) { - if(sr) { + $.each(sl.serial_no.trim().split("\n"), function (i, sr) { + if (sr) { value_diff += flt(me.serialized_buying_rates[sr.trim().toLowerCase()]); } }); @@ -109,7 +108,7 @@ erpnext.StockGridReport = class StockGridReport extends frappe.views.TreeGridRep var serialized_buying_rates = {}; if (frappe.report_dump.data["Serial No"]) { - $.each(frappe.report_dump.data["Serial No"], function(i, sn) { + $.each(frappe.report_dump.data["Serial No"], function (i, sn) { serialized_buying_rates[sn.name.toLowerCase()] = flt(sn.incoming_rate); }); } diff --git a/erpnext/public/js/telephony.js b/erpnext/public/js/telephony.js index 1c3e3147976d..7caf87d3f67c 100644 --- a/erpnext/public/js/telephony.js +++ b/erpnext/public/js/telephony.js @@ -1,13 +1,17 @@ -frappe.ui.form.ControlData = class ControlData extends frappe.ui.form.ControlData { +frappe.ui.form.ControlData = class ControlData extends frappe.ui.form.ControlData { make_input() { super.make_input(); - if (this.df.options == 'Phone') { + if (this.df.options == "Phone") { this.setup_phone(); } if (this.frm && this.frm.fields_dict) { - Object.values(this.frm.fields_dict).forEach(function(field) { - if (field.df.read_only === 1 && field.df.options === 'Phone' - && field.disp_area.style[0] != 'display' && !field.has_icon) { + Object.values(this.frm.fields_dict).forEach(function (field) { + if ( + field.df.read_only === 1 && + field.df.options === "Phone" && + field.disp_area.style[0] != "display" && + !field.has_icon + ) { field.setup_phone(); field.has_icon = true; } @@ -16,15 +20,18 @@ frappe.ui.form.ControlData = class ControlData extends frappe.ui.form.ControlDat } setup_phone() { if (frappe.phone_call.handler) { - let control = this.df.read_only ? '.control-value' : '.control-input'; - this.$wrapper.find(control) - .append(` + let control = this.df.read_only ? ".control-value" : ".control-input"; + this.$wrapper + .find(control) + .append( + ` - - ${frappe.utils.icon('call')} + + ${frappe.utils.icon("call")} - `) - .find('.phone-btn') + ` + ) + .find(".phone-btn") .click(() => { frappe.phone_call.handler(this.get_value(), this.frm); }); diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js index 27c7444daf47..731ebeae230e 100755 --- a/erpnext/public/js/utils.js +++ b/erpnext/public/js/utils.js @@ -4,44 +4,42 @@ frappe.provide("erpnext"); frappe.provide("erpnext.utils"); $.extend(erpnext, { - get_currency: function(company) { - if(!company && cur_frm) - company = cur_frm.doc.company; - if(company) + get_currency: function (company) { + if (!company && cur_frm) company = cur_frm.doc.company; + if (company) return frappe.get_doc(":Company", company).default_currency || frappe.boot.sysdefaults.currency; - else - return frappe.boot.sysdefaults.currency; + else return frappe.boot.sysdefaults.currency; }, get_presentation_currency_list: () => { const docs = frappe.boot.docs; - let currency_list = docs.filter(d => d.doctype === ":Currency").map(d => d.name); + let currency_list = docs.filter((d) => d.doctype === ":Currency").map((d) => d.name); currency_list.unshift(""); return currency_list; }, - toggle_naming_series: function() { - if(cur_frm && cur_frm.fields_dict.naming_series) { - cur_frm.toggle_display("naming_series", cur_frm.doc.__islocal?true:false); + toggle_naming_series: function () { + if (cur_frm && cur_frm.fields_dict.naming_series) { + cur_frm.toggle_display("naming_series", cur_frm.doc.__islocal ? true : false); } }, - hide_company: function() { - if(cur_frm.fields_dict.company) { + hide_company: function () { + if (cur_frm.fields_dict.company) { var companies = Object.keys(locals[":Company"] || {}); - if(companies.length === 1) { - if(!cur_frm.doc.company) cur_frm.set_value("company", companies[0]); + if (companies.length === 1) { + if (!cur_frm.doc.company) cur_frm.set_value("company", companies[0]); cur_frm.toggle_display("company", false); - } else if(erpnext.last_selected_company) { - if(!cur_frm.doc.company) cur_frm.set_value("company", erpnext.last_selected_company); + } else if (erpnext.last_selected_company) { + if (!cur_frm.doc.company) cur_frm.set_value("company", erpnext.last_selected_company); } } }, - is_perpetual_inventory_enabled: function(company) { - if(company) { + is_perpetual_inventory_enabled: function (company) { + if (company) { let company_local = locals[":Company"] && locals[":Company"][company]; - if(company_local) { + if (company_local) { return cint(company_local.enable_perpetual_inventory); } } @@ -51,280 +49,321 @@ $.extend(erpnext, { return cint(frappe.boot.sysdefaults.allow_stale); }, - setup_serial_or_batch_no: function() { + setup_serial_or_batch_no: function () { let grid_row = cur_frm.open_grid_row(); - if (!grid_row || !grid_row.grid_form.fields_dict.serial_no || - grid_row.grid_form.fields_dict.serial_no.get_status() !== "Write") return; - - frappe.model.get_value('Item', {'name': grid_row.doc.item_code}, - ['has_serial_no', 'has_batch_no'], ({has_serial_no, has_batch_no}) => { - Object.assign(grid_row.doc, {has_serial_no, has_batch_no}); + if ( + !grid_row || + !grid_row.grid_form.fields_dict.serial_no || + grid_row.grid_form.fields_dict.serial_no.get_status() !== "Write" + ) + return; + + frappe.model.get_value( + "Item", + { name: grid_row.doc.item_code }, + ["has_serial_no", "has_batch_no"], + ({ has_serial_no, has_batch_no }) => { + Object.assign(grid_row.doc, { has_serial_no, has_batch_no }); if (has_serial_no) { - attach_selector_button(__("Add Serial No"), - grid_row.grid_form.fields_dict.serial_no.$wrapper, this, grid_row); + attach_selector_button( + __("Add Serial No"), + grid_row.grid_form.fields_dict.serial_no.$wrapper, + this, + grid_row + ); } else if (has_batch_no) { - attach_selector_button(__("Pick Batch No"), - grid_row.grid_form.fields_dict.batch_no.$wrapper, this, grid_row); + attach_selector_button( + __("Pick Batch No"), + grid_row.grid_form.fields_dict.batch_no.$wrapper, + this, + grid_row + ); } } ); }, route_to_adjustment_jv: (args) => { - frappe.model.with_doctype('Journal Entry', () => { + frappe.model.with_doctype("Journal Entry", () => { // route to adjustment Journal Entry to handle Account Balance and Stock Value mismatch - let journal_entry = frappe.model.get_new_doc('Journal Entry'); + let journal_entry = frappe.model.get_new_doc("Journal Entry"); args.accounts.forEach((je_account) => { let child_row = frappe.model.add_child(journal_entry, "accounts"); child_row.account = je_account.account; child_row.debit_in_account_currency = je_account.debit_in_account_currency; child_row.credit_in_account_currency = je_account.credit_in_account_currency; - child_row.party_type = "" ; + child_row.party_type = ""; }); - frappe.set_route('Form','Journal Entry', journal_entry.name); + frappe.set_route("Form", "Journal Entry", journal_entry.name); }); }, route_to_pending_reposts: (args) => { - frappe.set_route('List', 'Repost Item Valuation', args); + frappe.set_route("List", "Repost Item Valuation", args); }, }); - $.extend(erpnext.utils, { - set_party_dashboard_indicators: function(frm) { - if(frm.doc.__onload && frm.doc.__onload.dashboard_info) { + set_party_dashboard_indicators: function (frm) { + if (frm.doc.__onload && frm.doc.__onload.dashboard_info) { var company_wise_info = frm.doc.__onload.dashboard_info; - if(company_wise_info.length > 1) { - company_wise_info.forEach(function(info) { + if (company_wise_info.length > 1) { + company_wise_info.forEach(function (info) { erpnext.utils.add_indicator_for_multicompany(frm, info); }); } else if (company_wise_info.length === 1) { - frm.dashboard.add_indicator(__('Annual Billing: {0}', - [format_currency(company_wise_info[0].billing_this_year, company_wise_info[0].currency)]), 'blue'); - frm.dashboard.add_indicator(__('Total Unpaid: {0}', - [format_currency(company_wise_info[0].total_unpaid, company_wise_info[0].currency)]), - company_wise_info[0].total_unpaid ? 'orange' : 'green'); - - if(company_wise_info[0].loyalty_points) { - frm.dashboard.add_indicator(__('Loyalty Points: {0}', - [company_wise_info[0].loyalty_points]), 'blue'); + frm.dashboard.add_indicator( + __("Annual Billing: {0}", [ + format_currency( + company_wise_info[0].billing_this_year, + company_wise_info[0].currency + ), + ]), + "blue" + ); + frm.dashboard.add_indicator( + __("Total Unpaid: {0}", [ + format_currency(company_wise_info[0].total_unpaid, company_wise_info[0].currency), + ]), + company_wise_info[0].total_unpaid ? "orange" : "green" + ); + + if (company_wise_info[0].loyalty_points) { + frm.dashboard.add_indicator( + __("Loyalty Points: {0}", [company_wise_info[0].loyalty_points]), + "blue" + ); } } } }, - add_indicator_for_multicompany: function(frm, info) { + add_indicator_for_multicompany: function (frm, info) { frm.dashboard.stats_area.show(); - frm.dashboard.stats_area_row.addClass('flex'); - frm.dashboard.stats_area_row.css('flex-wrap', 'wrap'); - - var color = info.total_unpaid ? 'orange' : 'green'; - - var indicator = $('
              '+ - '
              '+info.company+'
              '+ - - ''+ - - ''+ - - - '
              ').appendTo(frm.dashboard.stats_area_row); - - if(info.loyalty_points){ - $('').appendTo(indicator); + frm.dashboard.stats_area_row.addClass("flex"); + frm.dashboard.stats_area_row.css("flex-wrap", "wrap"); + + var color = info.total_unpaid ? "orange" : "green"; + + var indicator = $( + '
              ' + + '
              ' + + info.company + + "
              " + + '" + + '" + + "
              " + ).appendTo(frm.dashboard.stats_area_row); + + if (info.loyalty_points) { + $( + '" + ).appendTo(indicator); } return indicator; }, - get_party_name: function(party_type) { - var dict = {'Customer': 'customer_name', 'Supplier': 'supplier_name', 'Employee': 'employee_name', - 'Member': 'member_name'}; + get_party_name: function (party_type) { + var dict = { + Customer: "customer_name", + Supplier: "supplier_name", + Employee: "employee_name", + Member: "member_name", + }; return dict[party_type]; }, - copy_value_in_all_rows: function(doc, dt, dn, table_fieldname, fieldname) { + copy_value_in_all_rows: function (doc, dt, dn, table_fieldname, fieldname) { var d = locals[dt][dn]; - if(d[fieldname]){ + if (d[fieldname]) { var cl = doc[table_fieldname] || []; - for(var i = 0; i < cl.length; i++) { - if(!cl[i][fieldname]) cl[i][fieldname] = d[fieldname]; + for (var i = 0; i < cl.length; i++) { + if (!cl[i][fieldname]) cl[i][fieldname] = d[fieldname]; } } refresh_field(table_fieldname); }, - get_terms: function(tc_name, doc, callback) { - if(tc_name) { + get_terms: function (tc_name, doc, callback) { + if (tc_name) { return frappe.call({ - method: 'erpnext.setup.doctype.terms_and_conditions.terms_and_conditions.get_terms_and_conditions', + method: "erpnext.setup.doctype.terms_and_conditions.terms_and_conditions.get_terms_and_conditions", args: { template_name: tc_name, - doc: doc + doc: doc, + }, + callback: function (r) { + callback(r); }, - callback: function(r) { - callback(r) - } }); } }, - make_bank_account: function(doctype, docname) { + make_bank_account: function (doctype, docname) { frappe.call({ method: "erpnext.accounts.doctype.bank_account.bank_account.make_bank_account", args: { doctype: doctype, - docname: docname + docname: docname, }, freeze: true, - callback: function(r) { + callback: function (r) { var doclist = frappe.model.sync(r.message); frappe.set_route("Form", doclist[0].doctype, doclist[0].name); - } - }) + }, + }); }, - add_dimensions: function(report_name, index) { + add_dimensions: function (report_name, index) { let filters = frappe.query_reports[report_name].filters; frappe.call({ method: "erpnext.accounts.doctype.accounting_dimension.accounting_dimension.get_dimensions", - callback: function(r) { + callback: function (r) { let accounting_dimensions = r.message[0]; accounting_dimensions.forEach((dimension) => { - let found = filters.some(el => el.fieldname === dimension['fieldname']); + let found = filters.some((el) => el.fieldname === dimension["fieldname"]); if (!found) { filters.splice(index, 0, { - "fieldname": dimension["fieldname"], - "label": __(dimension["label"]), - "fieldtype": "MultiSelectList", - get_data: function(txt) { + fieldname: dimension["fieldname"], + label: __(dimension["label"]), + fieldtype: "MultiSelectList", + get_data: function (txt) { return frappe.db.get_link_options(dimension["document_type"], txt); }, }); } }); - } + }, }); }, - add_inventory_dimensions: function(report_name, index) { + add_inventory_dimensions: function (report_name, index) { let filters = frappe.query_reports[report_name].filters; frappe.call({ method: "erpnext.stock.doctype.inventory_dimension.inventory_dimension.get_inventory_dimensions", - callback: function(r) { + callback: function (r) { if (r.message && r.message.length) { r.message.forEach((dimension) => { - let existing_filter = filters.filter(el => el.fieldname === dimension['fieldname']); + let existing_filter = filters.filter((el) => el.fieldname === dimension["fieldname"]); if (!existing_filter.length) { filters.splice(index, 0, { - "fieldname": dimension["fieldname"], - "label": __(dimension["doctype"]), - "fieldtype": "MultiSelectList", - get_data: function(txt) { + fieldname: dimension["fieldname"], + label: __(dimension["doctype"]), + fieldtype: "MultiSelectList", + get_data: function (txt) { return frappe.db.get_link_options(dimension["doctype"], txt); }, }); } else { - existing_filter[0]['fieldtype'] = "MultiSelectList"; - existing_filter[0]['get_data'] = function(txt) { + existing_filter[0]["fieldtype"] = "MultiSelectList"; + existing_filter[0]["get_data"] = function (txt) { return frappe.db.get_link_options(dimension["doctype"], txt); - } + }; } }); } - } + }, }); }, - make_subscription: function(doctype, docname) { + make_subscription: function (doctype, docname) { frappe.call({ method: "frappe.automation.doctype.auto_repeat.auto_repeat.make_auto_repeat", args: { doctype: doctype, - docname: docname + docname: docname, }, - callback: function(r) { + callback: function (r) { var doclist = frappe.model.sync(r.message); frappe.set_route("Form", doclist[0].doctype, doclist[0].name); - } - }) + }, + }); }, - make_pricing_rule: function(doctype, docname) { + make_pricing_rule: function (doctype, docname) { frappe.call({ method: "erpnext.accounts.doctype.pricing_rule.pricing_rule.make_pricing_rule", args: { doctype: doctype, - docname: docname + docname: docname, }, - callback: function(r) { + callback: function (r) { var doclist = frappe.model.sync(r.message); frappe.set_route("Form", doclist[0].doctype, doclist[0].name); - } - }) + }, + }); }, /** - * Checks if the first row of a given child table is empty - * @param child_table - Child table Doctype - * @return {Boolean} - **/ - first_row_is_empty: function(child_table){ - if($.isArray(child_table) && child_table.length > 0) { + * Checks if the first row of a given child table is empty + * @param child_table - Child table Doctype + * @return {Boolean} + **/ + first_row_is_empty: function (child_table) { + if ($.isArray(child_table) && child_table.length > 0) { return !child_table[0].item_code; } return false; }, /** - * Removes the first row of a child table if it is empty - * @param {_Frm} frm - The current form - * @param {String} child_table_name - The child table field name - * @return {Boolean} - **/ - remove_empty_first_row: function(frm, child_table_name){ - const rows = frm['doc'][child_table_name]; - if (this.first_row_is_empty(rows)){ - frm['doc'][child_table_name] = rows.splice(1); + * Removes the first row of a child table if it is empty + * @param {_Frm} frm - The current form + * @param {String} child_table_name - The child table field name + * @return {Boolean} + **/ + remove_empty_first_row: function (frm, child_table_name) { + const rows = frm["doc"][child_table_name]; + if (this.first_row_is_empty(rows)) { + frm["doc"][child_table_name] = rows.splice(1); } return rows; }, - get_tree_options: function(option) { + get_tree_options: function (option) { // get valid options for tree based on user permission & locals dict let unscrub_option = frappe.model.unscrub(option); let user_permission = frappe.defaults.get_user_permissions(); let options; - if(user_permission && user_permission[unscrub_option]) { - options = user_permission[unscrub_option].map(perm => perm.doc); + if (user_permission && user_permission[unscrub_option]) { + options = user_permission[unscrub_option].map((perm) => perm.doc); } else { - options = $.map(locals[`:${unscrub_option}`], function(c) { return c.name; }).sort(); + options = $.map(locals[`:${unscrub_option}`], function (c) { + return c.name; + }).sort(); } // filter unique values, as there may be multiple user permissions for any value return options.filter((value, index, self) => self.indexOf(value) === index); }, - get_tree_default: function(option) { + get_tree_default: function (option) { // set default for a field based on user permission let options = this.get_tree_options(option); - if(options.includes(frappe.defaults.get_default(option))) { + if (options.includes(frappe.defaults.get_default(option))) { return frappe.defaults.get_default(option); } else { return options[0]; } }, - overrides_parent_value_in_all_rows: function(doc, dt, dn, table_fieldname, fieldname, parent_fieldname) { + overrides_parent_value_in_all_rows: function (doc, dt, dn, table_fieldname, fieldname, parent_fieldname) { if (doc[parent_fieldname]) { let cl = doc[table_fieldname] || []; for (let i = 0; i < cl.length; i++) { @@ -334,7 +373,7 @@ $.extend(erpnext.utils, { } }, create_new_doc: function (doctype, update_fields) { - frappe.model.with_doctype(doctype, function() { + frappe.model.with_doctype(doctype, function () { var new_doc = frappe.model.get_new_doc(doctype); for (let [key, value] of Object.entries(update_fields)) { new_doc[key] = value; @@ -346,147 +385,161 @@ $.extend(erpnext.utils, { // check if payments app is installed on site, if not warn user. check_payments_app: () => { if (frappe.boot.versions && !frappe.boot.versions.payments) { - const marketplace_link = '
              Marketplace' - const github_link = 'GitHub' - const msg = __("payments app is not installed. Please install it from {0} or {1}", [marketplace_link, github_link]) + const marketplace_link = + 'Marketplace'; + const github_link = 'GitHub'; + const msg = __("payments app is not installed. Please install it from {0} or {1}", [ + marketplace_link, + github_link, + ]); frappe.msgprint(msg); } - }, - get_fiscal_year: function(date) { - if(!date) { + get_fiscal_year: function (date) { + if (!date) { date = frappe.datetime.get_today(); } - let fiscal_year = ''; + let fiscal_year = ""; frappe.call({ method: "erpnext.accounts.utils.get_fiscal_year", args: { - date: date + date: date, }, async: false, - callback: function(r) { + callback: function (r) { if (r.message) { fiscal_year = r.message[0]; } - } + }, }); return fiscal_year; - } + }, }); -erpnext.utils.select_alternate_items = function(opts) { +erpnext.utils.select_alternate_items = function (opts) { const frm = opts.frm; - const warehouse_field = opts.warehouse_field || 'warehouse'; - const item_field = opts.item_field || 'item_code'; + const warehouse_field = opts.warehouse_field || "warehouse"; + const item_field = opts.item_field || "item_code"; this.data = []; const dialog = new frappe.ui.Dialog({ title: __("Select Alternate Item"), fields: [ - {fieldtype:'Section Break', label: __('Items')}, + { fieldtype: "Section Break", label: __("Items") }, { - fieldname: "alternative_items", fieldtype: "Table", cannot_add_rows: true, - in_place_edit: true, data: this.data, + fieldname: "alternative_items", + fieldtype: "Table", + cannot_add_rows: true, + in_place_edit: true, + data: this.data, get_data: () => { return this.data; }, - fields: [{ - fieldtype:'Data', - fieldname:"docname", - hidden: 1 - }, { - fieldtype:'Link', - fieldname:"item_code", - options: 'Item', - in_list_view: 1, - read_only: 1, - label: __('Item Code') - }, { - fieldtype:'Link', - fieldname:"alternate_item", - options: 'Item', - default: "", - in_list_view: 1, - label: __('Alternate Item'), - onchange: function() { - const item_code = this.get_value(); - const warehouse = this.grid_row.on_grid_fields_dict.warehouse.get_value(); - if (item_code && warehouse) { - frappe.call({ - method: "erpnext.stock.utils.get_latest_stock_qty", - args: { - item_code: item_code, - warehouse: warehouse - }, - callback: (r) => { - this.grid_row.on_grid_fields_dict - .actual_qty.set_value(r.message || 0); - } - }) - } + fields: [ + { + fieldtype: "Data", + fieldname: "docname", + hidden: 1, }, - get_query: (e) => { - return { - query: "erpnext.stock.doctype.item_alternative.item_alternative.get_alternative_items", - filters: { - item_code: e.item_code + { + fieldtype: "Link", + fieldname: "item_code", + options: "Item", + in_list_view: 1, + read_only: 1, + label: __("Item Code"), + }, + { + fieldtype: "Link", + fieldname: "alternate_item", + options: "Item", + default: "", + in_list_view: 1, + label: __("Alternate Item"), + onchange: function () { + const item_code = this.get_value(); + const warehouse = this.grid_row.on_grid_fields_dict.warehouse.get_value(); + if (item_code && warehouse) { + frappe.call({ + method: "erpnext.stock.utils.get_latest_stock_qty", + args: { + item_code: item_code, + warehouse: warehouse, + }, + callback: (r) => { + this.grid_row.on_grid_fields_dict.actual_qty.set_value( + r.message || 0 + ); + }, + }); } - }; - } - }, { - fieldtype:'Link', - fieldname:"warehouse", - options: 'Warehouse', - default: "", - in_list_view: 1, - label: __('Warehouse'), - onchange: function() { - const warehouse = this.get_value(); - const item_code = this.grid_row.on_grid_fields_dict.item_code.get_value(); - if (item_code && warehouse) { - frappe.call({ - method: "erpnext.stock.utils.get_latest_stock_qty", - args: { - item_code: item_code, - warehouse: warehouse + }, + get_query: (e) => { + return { + query: "erpnext.stock.doctype.item_alternative.item_alternative.get_alternative_items", + filters: { + item_code: e.item_code, }, - callback: (r) => { - this.grid_row.on_grid_fields_dict - .actual_qty.set_value(r.message || 0); - } - }) - } + }; + }, + }, + { + fieldtype: "Link", + fieldname: "warehouse", + options: "Warehouse", + default: "", + in_list_view: 1, + label: __("Warehouse"), + onchange: function () { + const warehouse = this.get_value(); + const item_code = this.grid_row.on_grid_fields_dict.item_code.get_value(); + if (item_code && warehouse) { + frappe.call({ + method: "erpnext.stock.utils.get_latest_stock_qty", + args: { + item_code: item_code, + warehouse: warehouse, + }, + callback: (r) => { + this.grid_row.on_grid_fields_dict.actual_qty.set_value( + r.message || 0 + ); + }, + }); + } + }, }, - }, { - fieldtype:'Float', - fieldname:"actual_qty", - default: 0, - read_only: 1, - in_list_view: 1, - label: __('Available Qty') - }] + { + fieldtype: "Float", + fieldname: "actual_qty", + default: 0, + read_only: 1, + in_list_view: 1, + label: __("Available Qty"), + }, + ], }, ], - primary_action: function() { + primary_action: function () { const args = this.get_values()["alternative_items"]; - const alternative_items = args.filter(d => { + const alternative_items = args.filter((d) => { if (d.alternate_item && d.item_code != d.alternate_item) { return true; } }); - alternative_items.forEach(d => { + alternative_items.forEach((d) => { let row = frappe.get_doc(opts.child_doctype, d.docname); let qty = null; - if (row.doctype === 'Work Order Item') { + if (row.doctype === "Work Order Item") { qty = row.required_qty; } else { qty = row.qty; } row[item_field] = d.alternate_item; - frappe.model.set_value(row.doctype, row.name, 'qty', qty); + frappe.model.set_value(row.doctype, row.name, "qty", qty); frappe.model.set_value(row.doctype, row.name, opts.original_item_field, d.item_code); frm.trigger(item_field, row.doctype, row.name); }); @@ -494,139 +547,145 @@ erpnext.utils.select_alternate_items = function(opts) { refresh_field(opts.child_docname); this.hide(); }, - primary_action_label: __('Update') + primary_action_label: __("Update"), }); - frm.doc[opts.child_docname].forEach(d => { + frm.doc[opts.child_docname].forEach((d) => { if (!opts.condition || opts.condition(d)) { dialog.fields_dict.alternative_items.df.data.push({ - "docname": d.name, - "item_code": d[item_field], - "warehouse": d[warehouse_field], - "actual_qty": d.actual_qty + docname: d.name, + item_code: d[item_field], + warehouse: d[warehouse_field], + actual_qty: d.actual_qty, }); } - }) + }); this.data = dialog.fields_dict.alternative_items.df.data; dialog.fields_dict.alternative_items.grid.refresh(); dialog.show(); -} +}; -erpnext.utils.update_child_items = function(opts) { +erpnext.utils.update_child_items = function (opts) { const frm = opts.frm; - const cannot_add_row = (typeof opts.cannot_add_row === 'undefined') ? true : opts.cannot_add_row; - const child_docname = (typeof opts.cannot_add_row === 'undefined') ? "items" : opts.child_docname; + const cannot_add_row = typeof opts.cannot_add_row === "undefined" ? true : opts.cannot_add_row; + const child_docname = typeof opts.cannot_add_row === "undefined" ? "items" : opts.child_docname; const child_meta = frappe.get_meta(`${frm.doc.doctype} Item`); - const get_precision = (fieldname) => child_meta.fields.find(f => f.fieldname == fieldname).precision; + const get_precision = (fieldname) => child_meta.fields.find((f) => f.fieldname == fieldname).precision; this.data = frm.doc[opts.child_docname].map((d) => { return { - "docname": d.name, - "name": d.name, - "item_code": d.item_code, - "delivery_date": d.delivery_date, - "schedule_date": d.schedule_date, - "conversion_factor": d.conversion_factor, - "qty": d.qty, - "rate": d.rate, - "uom": d.uom - } + docname: d.name, + name: d.name, + item_code: d.item_code, + delivery_date: d.delivery_date, + schedule_date: d.schedule_date, + conversion_factor: d.conversion_factor, + qty: d.qty, + rate: d.rate, + uom: d.uom, + }; }); - const fields = [{ - fieldtype:'Data', - fieldname:"docname", - read_only: 1, - hidden: 1, - }, { - fieldtype:'Link', - fieldname:"item_code", - options: 'Item', - in_list_view: 1, - read_only: 0, - disabled: 0, - label: __('Item Code'), - get_query: function() { - let filters; - if (frm.doc.doctype == 'Sales Order') { - filters = {"is_sales_item": 1}; - } else if (frm.doc.doctype == 'Purchase Order') { - if (frm.doc.is_subcontracted) { - if (frm.doc.is_old_subcontracting_flow) { - filters = {"is_sub_contracted_item": 1}; + const fields = [ + { + fieldtype: "Data", + fieldname: "docname", + read_only: 1, + hidden: 1, + }, + { + fieldtype: "Link", + fieldname: "item_code", + options: "Item", + in_list_view: 1, + read_only: 0, + disabled: 0, + label: __("Item Code"), + get_query: function () { + let filters; + if (frm.doc.doctype == "Sales Order") { + filters = { is_sales_item: 1 }; + } else if (frm.doc.doctype == "Purchase Order") { + if (frm.doc.is_subcontracted) { + if (frm.doc.is_old_subcontracting_flow) { + filters = { is_sub_contracted_item: 1 }; + } else { + filters = { is_stock_item: 0 }; + } } else { - filters = {"is_stock_item": 0}; - } - } else { - filters = {"is_purchase_item": 1}; - } - } - return { - query: "erpnext.controllers.queries.item_query", - filters: filters - }; - } - }, { - fieldtype:'Link', - fieldname:'uom', - options: 'UOM', - read_only: 0, - label: __('UOM'), - reqd: 1, - onchange: function () { - frappe.call({ - method: "erpnext.stock.get_item_details.get_conversion_factor", - args: { item_code: this.doc.item_code, uom: this.value }, - callback: r => { - if(!r.exc) { - if (this.doc.conversion_factor == r.message.conversion_factor) return; - - const docname = this.doc.docname; - dialog.fields_dict.trans_items.df.data.some(doc => { - if (doc.docname == docname) { - doc.conversion_factor = r.message.conversion_factor; - dialog.fields_dict.trans_items.grid.refresh(); - return true; - } - }) + filters = { is_purchase_item: 1 }; } } - }); - } - }, { - fieldtype:'Float', - fieldname:"qty", - default: 0, - read_only: 0, - in_list_view: 1, - label: __('Qty'), - precision: get_precision("qty") - }, { - fieldtype:'Currency', - fieldname:"rate", - options: "currency", - default: 0, - read_only: 0, - in_list_view: 1, - label: __('Rate'), - precision: get_precision("rate") - }]; - - if (frm.doc.doctype == 'Sales Order' || frm.doc.doctype == 'Purchase Order' ) { + return { + query: "erpnext.controllers.queries.item_query", + filters: filters, + }; + }, + }, + { + fieldtype: "Link", + fieldname: "uom", + options: "UOM", + read_only: 0, + label: __("UOM"), + reqd: 1, + onchange: function () { + frappe.call({ + method: "erpnext.stock.get_item_details.get_conversion_factor", + args: { item_code: this.doc.item_code, uom: this.value }, + callback: (r) => { + if (!r.exc) { + if (this.doc.conversion_factor == r.message.conversion_factor) return; + + const docname = this.doc.docname; + dialog.fields_dict.trans_items.df.data.some((doc) => { + if (doc.docname == docname) { + doc.conversion_factor = r.message.conversion_factor; + dialog.fields_dict.trans_items.grid.refresh(); + return true; + } + }); + } + }, + }); + }, + }, + { + fieldtype: "Float", + fieldname: "qty", + default: 0, + read_only: 0, + in_list_view: 1, + label: __("Qty"), + precision: get_precision("qty"), + }, + { + fieldtype: "Currency", + fieldname: "rate", + options: "currency", + default: 0, + read_only: 0, + in_list_view: 1, + label: __("Rate"), + precision: get_precision("rate"), + }, + ]; + + if (frm.doc.doctype == "Sales Order" || frm.doc.doctype == "Purchase Order") { fields.splice(2, 0, { - fieldtype: 'Date', - fieldname: frm.doc.doctype == 'Sales Order' ? "delivery_date" : "schedule_date", + fieldtype: "Date", + fieldname: frm.doc.doctype == "Sales Order" ? "delivery_date" : "schedule_date", in_list_view: 1, - label: frm.doc.doctype == 'Sales Order' ? __("Delivery Date") : __("Reqd by date"), - reqd: 1 - }) + label: frm.doc.doctype == "Sales Order" ? __("Delivery Date") : __("Reqd by date"), + reqd: 1, + }); fields.splice(3, 0, { - fieldtype: 'Float', + fieldtype: "Float", fieldname: "conversion_factor", label: __("Conversion Factor"), - precision: get_precision('conversion_factor') - }) + precision: get_precision("conversion_factor"), + }); } new frappe.ui.Dialog({ @@ -644,86 +703,82 @@ erpnext.utils.update_child_items = function(opts) { get_data: () => { return this.data; }, - fields: fields + fields: fields, }, ], - primary_action: function() { + primary_action: function () { const trans_items = this.get_values()["trans_items"].filter((item) => !!item.item_code); frappe.call({ - method: 'erpnext.controllers.accounts_controller.update_child_qty_rate', + method: "erpnext.controllers.accounts_controller.update_child_qty_rate", freeze: true, args: { - 'parent_doctype': frm.doc.doctype, - 'trans_items': trans_items, - 'parent_doctype_name': frm.doc.name, - 'child_docname': child_docname + parent_doctype: frm.doc.doctype, + trans_items: trans_items, + parent_doctype_name: frm.doc.name, + child_docname: child_docname, }, - callback: function() { + callback: function () { frm.reload_doc(); - } + }, }); this.hide(); refresh_field("items"); }, - primary_action_label: __('Update') + primary_action_label: __("Update"), }).show(); -} - - - +}; -erpnext.utils.map_current_doc = function(opts) { +erpnext.utils.map_current_doc = function (opts) { function _map() { - if($.isArray(cur_frm.doc.items) && cur_frm.doc.items.length > 0) { + if ($.isArray(cur_frm.doc.items) && cur_frm.doc.items.length > 0) { // remove first item row if empty - if(!cur_frm.doc.items[0].item_code) { + if (!cur_frm.doc.items[0].item_code) { cur_frm.doc.items = cur_frm.doc.items.splice(1); } // find the doctype of the items table - var items_doctype = frappe.meta.get_docfield(cur_frm.doctype, 'items').options; + var items_doctype = frappe.meta.get_docfield(cur_frm.doctype, "items").options; // find the link fieldname from items table for the given // source_doctype var link_fieldname = null; - frappe.get_meta(items_doctype).fields.forEach(function(d) { - if(d.options===opts.source_doctype) link_fieldname = d.fieldname; }); + frappe.get_meta(items_doctype).fields.forEach(function (d) { + if (d.options === opts.source_doctype) link_fieldname = d.fieldname; + }); // search in existing items if the source_name is already set and full qty fetched var already_set = false; var item_qty_map = {}; - $.each(cur_frm.doc.items, function(i, d) { - opts.source_name.forEach(function(src) { - if(d[link_fieldname]==src) { + $.each(cur_frm.doc.items, function (i, d) { + opts.source_name.forEach(function (src) { + if (d[link_fieldname] == src) { already_set = true; - if (item_qty_map[d.item_code]) - item_qty_map[d.item_code] += flt(d.qty); - else - item_qty_map[d.item_code] = flt(d.qty); + if (item_qty_map[d.item_code]) item_qty_map[d.item_code] += flt(d.qty); + else item_qty_map[d.item_code] = flt(d.qty); } }); }); - if(already_set) { - opts.source_name.forEach(function(src) { - frappe.model.with_doc(opts.source_doctype, src, function(r) { + if (already_set) { + opts.source_name.forEach(function (src) { + frappe.model.with_doc(opts.source_doctype, src, function (r) { var source_doc = frappe.model.get_doc(opts.source_doctype, src); - $.each(source_doc.items || [], function(i, row) { - if(row.qty > flt(item_qty_map[row.item_code])) { + $.each(source_doc.items || [], function (i, row) { + if (row.qty > flt(item_qty_map[row.item_code])) { already_set = false; return false; } - }) - }) + }); + }); - if(already_set) { - frappe.msgprint(__("You have already selected items from {0} {1}", - [opts.source_doctype, src])); + if (already_set) { + frappe.msgprint( + __("You have already selected items from {0} {1}", [opts.source_doctype, src]) + ); return; } - - }) + }); } } @@ -731,20 +786,20 @@ erpnext.utils.map_current_doc = function(opts) { // Sometimes we hit the limit for URL length of a GET request // as we send the full target_doc. Hence this is a POST request. type: "POST", - method: 'frappe.model.mapper.map_docs', + method: "frappe.model.mapper.map_docs", args: { - "method": opts.method, - "source_names": opts.source_name, - "target_doc": cur_frm.doc, - "args": opts.args + method: opts.method, + source_names: opts.source_name, + target_doc: cur_frm.doc, + args: opts.args, }, - callback: function(r) { - if(!r.exc) { + callback: function (r) { + if (!r.exc) { frappe.model.sync(r.message); cur_frm.dirty(); cur_frm.refresh(); } - } + }, }); } @@ -763,11 +818,11 @@ erpnext.utils.map_current_doc = function(opts) { if (opts.source_doctype) { let data_fields = []; - if(opts.source_doctype == "Purchase Receipt") { + if (opts.source_doctype == "Purchase Receipt") { data_fields.push({ - fieldname: 'merge_taxes', - fieldtype: 'Check', - label: __('Merge taxes from multiple documents'), + fieldname: "merge_taxes", + fieldtype: "Check", + label: __("Merge taxes from multiple documents"), }); } const d = new frappe.ui.form.MultiSelectDialog({ @@ -782,10 +837,10 @@ erpnext.utils.map_current_doc = function(opts) { child_fieldname: opts.child_fieldname, child_columns: opts.child_columns, size: opts.size, - action: function(selections, args) { + action: function (selections, args) { let values = selections; if (values.length === 0) { - frappe.msgprint(__("Please select {0}", [opts.source_doctype])) + frappe.msgprint(__("Please select {0}", [opts.source_doctype])); return; } opts.source_name = values; @@ -805,11 +860,11 @@ erpnext.utils.map_current_doc = function(opts) { opts.source_name = [opts.source_name]; _map(); } -} +}; -frappe.form.link_formatters['Item'] = function(value, doc) { +frappe.form.link_formatters["Item"] = function (value, doc) { if (doc && value && doc.item_name && doc.item_name !== value && doc.item_code === value) { - return value + ': ' + doc.item_name; + return value + ": " + doc.item_name; } else if (!value && doc.doctype && doc.item_name) { // format blank value in child table return doc.item_name; @@ -817,11 +872,11 @@ frappe.form.link_formatters['Item'] = function(value, doc) { // if value is blank in report view or item code and name are the same, return as is return value; } -} +}; -frappe.form.link_formatters['Employee'] = function(value, doc) { +frappe.form.link_formatters["Employee"] = function (value, doc) { if (doc && value && doc.employee_name && doc.employee_name !== value && doc.employee === value) { - return value + ': ' + doc.employee_name; + return value + ": " + doc.employee_name; } else if (!value && doc.doctype && doc.employee_name) { // format blank value in child table return doc.employee; @@ -829,11 +884,11 @@ frappe.form.link_formatters['Employee'] = function(value, doc) { // if value is blank in report view or project name and name are the same, return as is return value; } -} +}; -frappe.form.link_formatters['Project'] = function(value, doc) { +frappe.form.link_formatters["Project"] = function (value, doc) { if (doc && value && doc.project_name && doc.project_name !== value && doc.project === value) { - return value + ': ' + doc.project_name; + return value + ": " + doc.project_name; } else if (!value && doc.doctype && doc.project_name) { // format blank value in child table return doc.project; @@ -844,64 +899,74 @@ frappe.form.link_formatters['Project'] = function(value, doc) { }; // add description on posting time -$(document).on('app_ready', function() { - if(!frappe.datetime.is_timezone_same()) { - $.each(["Stock Reconciliation", "Stock Entry", "Stock Ledger Entry", - "Delivery Note", "Purchase Receipt", "Sales Invoice"], function(i, d) { - frappe.ui.form.on(d, "onload", function(frm) { - cur_frm.set_df_property("posting_time", "description", - frappe.sys_defaults.time_zone); - }); - }); +$(document).on("app_ready", function () { + if (!frappe.datetime.is_timezone_same()) { + $.each( + [ + "Stock Reconciliation", + "Stock Entry", + "Stock Ledger Entry", + "Delivery Note", + "Purchase Receipt", + "Sales Invoice", + ], + function (i, d) { + frappe.ui.form.on(d, "onload", function (frm) { + cur_frm.set_df_property("posting_time", "description", frappe.sys_defaults.time_zone); + }); + } + ); } }); // Show SLA dashboard -$(document).on('app_ready', function() { - $.each(frappe.boot.service_level_agreement_doctypes, function(_i, d) { +$(document).on("app_ready", function () { + $.each(frappe.boot.service_level_agreement_doctypes, function (_i, d) { frappe.ui.form.on(d, { - onload: function(frm) { - if (!frm.doc.service_level_agreement) - return; + onload: function (frm) { + if (!frm.doc.service_level_agreement) return; frappe.call({ - method: 'erpnext.support.doctype.service_level_agreement.service_level_agreement.get_service_level_agreement_filters', + method: "erpnext.support.doctype.service_level_agreement.service_level_agreement.get_service_level_agreement_filters", args: { doctype: frm.doc.doctype, name: frm.doc.service_level_agreement, - customer: frm.doc.customer + customer: frm.doc.customer, }, callback: function (r) { if (r && r.message) { - frm.set_query('priority', function() { + frm.set_query("priority", function () { return { filters: { - 'name': ['in', r.message.priority], - } + name: ["in", r.message.priority], + }, }; }); - frm.set_query('service_level_agreement', function() { + frm.set_query("service_level_agreement", function () { return { filters: { - 'name': ['in', r.message.service_level_agreements], - } + name: ["in", r.message.service_level_agreements], + }, }; }); } - } + }, }); }, - refresh: function(frm) { - if (frm.doc.status !== 'Closed' && frm.doc.service_level_agreement - && ['First Response Due', 'Resolution Due'].includes(frm.doc.agreement_status)) { + refresh: function (frm) { + if ( + frm.doc.status !== "Closed" && + frm.doc.service_level_agreement && + ["First Response Due", "Resolution Due"].includes(frm.doc.agreement_status) + ) { frappe.call({ - 'method': 'frappe.client.get', + method: "frappe.client.get", args: { - doctype: 'Service Level Agreement', - name: frm.doc.service_level_agreement + doctype: "Service Level Agreement", + name: frm.doc.service_level_agreement, }, - callback: function(data) { + callback: function (data) { let statuses = data.message.pause_sla_on; const hold_statuses = []; $.each(statuses, (_i, entry) => { @@ -909,32 +974,46 @@ $(document).on('app_ready', function() { }); if (hold_statuses.includes(frm.doc.status)) { frm.dashboard.clear_headline(); - let message = {'indicator': 'orange', 'msg': __('SLA is on hold since {0}', [moment(frm.doc.on_hold_since).fromNow(true)])}; + let message = { + indicator: "orange", + msg: __("SLA is on hold since {0}", [ + moment(frm.doc.on_hold_since).fromNow(true), + ]), + }; frm.dashboard.set_headline_alert( '
              ' + '
              ' + - ''+ message.msg +' ' + - '
              ' + - '
              ' + '' + + message.msg + + " " + + "
              " + + "
              " ); } else { set_time_to_resolve_and_response(frm, data.message.apply_sla_for_resolution); } - } + }, }); } else if (frm.doc.service_level_agreement) { frm.dashboard.clear_headline(); - let agreement_status = (frm.doc.agreement_status == 'Fulfilled') ? - {'indicator': 'green', 'msg': 'Service Level Agreement has been fulfilled'} : - {'indicator': 'red', 'msg': 'Service Level Agreement Failed'}; + let agreement_status = + frm.doc.agreement_status == "Fulfilled" + ? { indicator: "green", msg: "Service Level Agreement has been fulfilled" } + : { indicator: "red", msg: "Service Level Agreement Failed" }; frm.dashboard.set_headline_alert( '
              ' + '
              ' + - ' ' + - '
              ' + - '
              ' + ' " + + "" + + "" ); } }, @@ -960,7 +1039,6 @@ function set_time_to_resolve_and_response(frm, apply_sla_for_resolution) {
              `; - if (apply_sla_for_resolution) { let time_to_resolve; if (!frm.doc.resolution_date) { @@ -977,34 +1055,32 @@ function set_time_to_resolve_and_response(frm, apply_sla_for_resolution) { `; } - alert += ''; + alert += ""; frm.dashboard.set_headline_alert(alert); } function get_time_left(timestamp, agreement_status) { const diff = moment(timestamp).diff(frappe.datetime.system_datetime(true)); - const diff_display = diff >= 44500 ? moment.duration(diff).humanize() : 'Failed'; - let indicator = (diff_display == 'Failed' && agreement_status != 'Fulfilled') ? 'red' : 'green'; - return {'diff_display': diff_display, 'indicator': indicator}; + const diff_display = diff >= 44500 ? moment.duration(diff).humanize() : "Failed"; + let indicator = diff_display == "Failed" && agreement_status != "Fulfilled" ? "red" : "green"; + return { diff_display: diff_display, indicator: indicator }; } function get_status(expected, actual) { const time_left = moment(expected).diff(moment(actual)); if (time_left >= 0) { - return {'diff_display': 'Fulfilled', 'indicator': 'green'}; + return { diff_display: "Fulfilled", indicator: "green" }; } else { - return {'diff_display': 'Failed', 'indicator': 'red'}; + return { diff_display: "Failed", indicator: "red" }; } } function attach_selector_button(inner_text, append_loction, context, grid_row) { - let $btn_div = $("
              ").css({"margin-bottom": "10px", "margin-top": "10px"}) - .appendTo(append_loction); - let $btn = $(``) - .appendTo($btn_div); + let $btn_div = $("
              ").css({ "margin-bottom": "10px", "margin-top": "10px" }).appendTo(append_loction); + let $btn = $(``).appendTo($btn_div); - $btn.on("click", function() { + $btn.on("click", function () { context.show_serial_batch_selector(grid_row.frm, grid_row.doc, "", "", true); }); } diff --git a/erpnext/public/js/utils/barcode_scanner.js b/erpnext/public/js/utils/barcode_scanner.js index aadbb24cc04b..15d13f9ffb15 100644 --- a/erpnext/public/js/utils/barcode_scanner.js +++ b/erpnext/public/js/utils/barcode_scanner.js @@ -58,13 +58,15 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner { return; } - me.update_table(data).then(row => { - this.play_success_sound(); - resolve(row); - }).catch(() => { - this.play_fail_sound(); - reject(); - }); + me.update_table(data) + .then((row) => { + this.play_success_sound(); + resolve(row); + }) + .catch(() => { + this.play_fail_sound(); + reject(); + }); }); }); } @@ -83,11 +85,11 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner { } update_table(data) { - return new Promise(resolve => { + return new Promise((resolve) => { let cur_grid = this.frm.fields_dict[this.items_table_name].grid; frappe.flags.trigger_from_barcode_scanner = true; - const {item_code, barcode, batch_no, serial_no, uom} = data; + const { item_code, barcode, batch_no, serial_no, uom } = data; let row = this.get_row_to_modify_on_scan(item_code, batch_no, uom, barcode); @@ -116,16 +118,17 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner { frappe.run_serially([ () => this.set_selector_trigger_flag(data), - () => this.set_item(row, item_code, barcode, batch_no, serial_no).then(qty => { - this.show_scan_message(row.idx, row.item_code, qty); - }), + () => + this.set_item(row, item_code, barcode, batch_no, serial_no).then((qty) => { + this.show_scan_message(row.idx, row.item_code, qty); + }), () => this.set_barcode_uom(row, uom), () => this.set_serial_no(row, serial_no), () => this.set_batch_no(row, batch_no), () => this.set_barcode(row, barcode), () => this.clean_up(), () => this.revert_selector_flag(), - () => resolve(row) + () => resolve(row), ]); }); } @@ -133,7 +136,7 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner { // batch and serial selector is reduandant when all info can be added by scan // this flag on item row is used by transaction.js to avoid triggering selector set_selector_trigger_flag(data) { - const {batch_no, serial_no, has_batch_no, has_serial_no} = data; + const { batch_no, serial_no, has_batch_no, has_serial_no } = data; const require_selecting_batch = has_batch_no && !batch_no; const require_selecting_serial = has_serial_no && !serial_no; @@ -149,17 +152,17 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner { } set_item(row, item_code, barcode, batch_no, serial_no) { - return new Promise(resolve => { + return new Promise((resolve) => { const increment = async (value = 1) => { - const item_data = {item_code: item_code}; + const item_data = { item_code: item_code }; frappe.flags.trigger_from_barcode_scanner = true; - item_data[this.qty_field] = Number((row[this.qty_field] || 0)) + Number(value); + item_data[this.qty_field] = Number(row[this.qty_field] || 0) + Number(value); await frappe.model.set_value(row.doctype, row.name, item_data); return value; }; if (this.prompt_qty) { - frappe.prompt(__("Please enter quantity for item {0}", [item_code]), ({value}) => { + frappe.prompt(__("Please enter quantity for item {0}", [item_code]), ({ value }) => { increment(value).then((value) => resolve(value)); }); } else if (this.frm.has_items) { @@ -175,14 +178,15 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner { this.dialog = new frappe.ui.Dialog({ title: __("Scan barcode for item {0}", [item_code]), fields: me.get_fields_for_dialog(row, item_code, barcode, batch_no, serial_no), - }) + }); this.dialog.set_primary_action(__("Update"), () => { - const item_data = {item_code: item_code}; + const item_data = { item_code: item_code }; item_data[this.qty_field] = this.dialog.get_value("scanned_qty"); item_data["has_item_scanned"] = 1; - this.remaining_qty = flt(this.dialog.get_value("qty")) - flt(this.dialog.get_value("scanned_qty")); + this.remaining_qty = + flt(this.dialog.get_value("qty")) - flt(this.dialog.get_value("scanned_qty")); frappe.model.set_value(row.doctype, row.name, item_data); frappe.run_serially([ @@ -190,7 +194,7 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner { () => this.set_barcode(row, this.dialog.get_value("barcode")), () => this.set_serial_no(row, this.dialog.get_value("serial_no")), () => this.add_child_for_remaining_qty(row), - () => this.clean_up() + () => this.clean_up(), ]); this.dialog.hide(); @@ -219,9 +223,9 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner { if (r.message) { this.update_dialog_values(item_code, r); } - }) + }); } - } + }, }, { fieldtype: "Section Break", @@ -245,8 +249,8 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner { }, { fieldtype: "Section Break", - } - ] + }, + ]; if (batch_no) { fields.push({ @@ -256,7 +260,7 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner { label: __("Batch No"), default: batch_no, read_only: 1, - hidden: 1 + hidden: 1, }); } @@ -278,7 +282,7 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner { label: __("Barcode"), default: barcode, read_only: 1, - hidden: 1 + hidden: 1, }); } @@ -286,18 +290,18 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner { } update_dialog_values(scanned_item, r) { - const {item_code, barcode, batch_no, serial_no} = r.message; + const { item_code, barcode, batch_no, serial_no } = r.message; this.dialog.set_value("barcode_scanner", ""); - if (item_code === scanned_item && - (this.dialog.get_value("barcode") === barcode || batch_no || serial_no)) { - + if ( + item_code === scanned_item && + (this.dialog.get_value("barcode") === barcode || batch_no || serial_no) + ) { if (batch_no) { this.dialog.set_value("batch_no", batch_no); } if (serial_no) { - this.validate_duplicate_serial_no(serial_no); let serial_nos = this.dialog.get_value("serial_no") + "\n" + serial_no; this.dialog.set_value("serial_no", serial_nos); @@ -309,8 +313,9 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner { } validate_duplicate_serial_no(serial_no) { - let serial_nos = this.dialog.get_value("serial_no") ? - this.dialog.get_value("serial_no").split("\n") : []; + let serial_nos = this.dialog.get_value("serial_no") + ? this.dialog.get_value("serial_no").split("\n") + : []; if (in_list(serial_nos, serial_no)) { frappe.throw(__("Serial No {0} already scanned", [serial_no])); @@ -318,12 +323,19 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner { } add_child_for_remaining_qty(prev_row) { - if (this.remaining_qty && this.remaining_qty >0) { + if (this.remaining_qty && this.remaining_qty > 0) { let cur_grid = this.frm.fields_dict[this.items_table_name].grid; let row = frappe.model.add_child(this.frm.doc, cur_grid.doctype, this.items_table_name); - let ignore_fields = ["name", "idx", "batch_no", "barcode", - "received_qty", "serial_no", "has_item_scanned"]; + let ignore_fields = [ + "name", + "idx", + "batch_no", + "barcode", + "received_qty", + "serial_no", + "has_item_scanned", + ]; for (let key in prev_row) { if (in_list(ignore_fields, key)) { @@ -379,7 +391,7 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner { if (exist) { this.show_alert(__("Row #{0}: Qty increased by {1}", [idx, qty]), "green"); } else { - this.show_alert(__("Row #{0}: Item added", [idx]), "green") + this.show_alert(__("Row #{0}: Item added", [idx]), "green"); } } @@ -401,17 +413,19 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner { const matching_row = (row) => { const item_match = row.item_code == item_code; - const batch_match = (!row[this.batch_no_field] || row[this.batch_no_field] == batch_no); + const batch_match = !row[this.batch_no_field] || row[this.batch_no_field] == batch_no; const uom_match = !uom || row[this.uom_field] == uom; const qty_in_limit = flt(row[this.qty_field]) < flt(row[this.max_qty_field]); const item_scanned = row.has_item_scanned; - return item_match - && uom_match - && !item_scanned - && (!is_batch_no_scan || batch_match) - && (!check_max_qty || qty_in_limit) - } + return ( + item_match && + uom_match && + !item_scanned && + (!is_batch_no_scan || batch_match) && + (!check_max_qty || qty_in_limit) + ); + }; return this.items_table.find(matching_row) || this.get_existing_blank_row(); } @@ -432,7 +446,7 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner { this.scan_barcode_field.set_value(""); refresh_field(this.items_table_name); } - show_alert(msg, indicator, duration=3) { - frappe.show_alert({message: msg, indicator: indicator}, duration); + show_alert(msg, indicator, duration = 3) { + frappe.show_alert({ message: msg, indicator: indicator }, duration); } }; diff --git a/erpnext/public/js/utils/contact_address_quick_entry.js b/erpnext/public/js/utils/contact_address_quick_entry.js index adabf08c2036..2f61dee19946 100644 --- a/erpnext/public/js/utils/contact_address_quick_entry.js +++ b/erpnext/public/js/utils/contact_address_quick_entry.js @@ -1,6 +1,8 @@ -frappe.provide('frappe.ui.form'); +frappe.provide("frappe.ui.form"); -frappe.ui.form.ContactAddressQuickEntryForm = class ContactAddressQuickEntryForm extends frappe.ui.form.QuickEntryForm { +frappe.ui.form.ContactAddressQuickEntryForm = class ContactAddressQuickEntryForm extends ( + frappe.ui.form.QuickEntryForm +) { constructor(doctype, after_insert, init_callback, doc, force) { super(doctype, after_insert, init_callback, doc, force); this.skip_redirect_on_error = true; @@ -17,8 +19,8 @@ frappe.ui.form.ContactAddressQuickEntryForm = class ContactAddressQuickEntryForm * Therefor, resulting in the fields being "hidden". */ const map_field_names = { - "email_address": "email_id", - "mobile_number": "mobile_no", + email_address: "email_id", + mobile_number: "mobile_no", }; Object.entries(map_field_names).forEach(([fieldname, new_fieldname]) => { @@ -30,71 +32,73 @@ frappe.ui.form.ContactAddressQuickEntryForm = class ContactAddressQuickEntryForm } get_variant_fields() { - var variant_fields = [{ - fieldtype: "Section Break", - label: __("Primary Contact Details"), - collapsible: 1 - }, - { - label: __("Email Id"), - fieldname: "email_address", - fieldtype: "Data", - options: "Email", - }, - { - fieldtype: "Column Break" - }, - { - label: __("Mobile Number"), - fieldname: "mobile_number", - fieldtype: "Data" - }, - { - fieldtype: "Section Break", - label: __("Primary Address Details"), - collapsible: 1 - }, - { - label: __("Address Line 1"), - fieldname: "address_line1", - fieldtype: "Data" - }, - { - label: __("Address Line 2"), - fieldname: "address_line2", - fieldtype: "Data" - }, - { - label: __("ZIP Code"), - fieldname: "pincode", - fieldtype: "Data" - }, - { - fieldtype: "Column Break" - }, - { - label: __("City"), - fieldname: "city", - fieldtype: "Data" - }, - { - label: __("State"), - fieldname: "state", - fieldtype: "Data" - }, - { - label: __("Country"), - fieldname: "country", - fieldtype: "Link", - options: "Country" - }, - { - label: __("Customer POS Id"), - fieldname: "customer_pos_id", - fieldtype: "Data", - hidden: 1 - }]; + var variant_fields = [ + { + fieldtype: "Section Break", + label: __("Primary Contact Details"), + collapsible: 1, + }, + { + label: __("Email Id"), + fieldname: "email_address", + fieldtype: "Data", + options: "Email", + }, + { + fieldtype: "Column Break", + }, + { + label: __("Mobile Number"), + fieldname: "mobile_number", + fieldtype: "Data", + }, + { + fieldtype: "Section Break", + label: __("Primary Address Details"), + collapsible: 1, + }, + { + label: __("Address Line 1"), + fieldname: "address_line1", + fieldtype: "Data", + }, + { + label: __("Address Line 2"), + fieldname: "address_line2", + fieldtype: "Data", + }, + { + label: __("ZIP Code"), + fieldname: "pincode", + fieldtype: "Data", + }, + { + fieldtype: "Column Break", + }, + { + label: __("City"), + fieldname: "city", + fieldtype: "Data", + }, + { + label: __("State"), + fieldname: "state", + fieldtype: "Data", + }, + { + label: __("Country"), + fieldname: "country", + fieldtype: "Link", + options: "Country", + }, + { + label: __("Customer POS Id"), + fieldname: "customer_pos_id", + fieldtype: "Data", + hidden: 1, + }, + ]; return variant_fields; } -} +}; diff --git a/erpnext/public/js/utils/crm_activities.js b/erpnext/public/js/utils/crm_activities.js index ec79a10dfaca..a5a225458c09 100644 --- a/erpnext/public/js/utils/crm_activities.js +++ b/erpnext/public/js/utils/crm_activities.js @@ -6,21 +6,21 @@ erpnext.utils.CRMActivities = class CRMActivities { refresh() { var me = this; $(this.open_activities_wrapper).empty(); - let cur_form_footer = this.form_wrapper.find('.form-footer'); + let cur_form_footer = this.form_wrapper.find(".form-footer"); // all activities - if (!$(this.all_activities_wrapper).find('.form-footer').length) { + if (!$(this.all_activities_wrapper).find(".form-footer").length) { this.all_activities_wrapper.empty(); $(cur_form_footer).appendTo(this.all_activities_wrapper); // remove frappe-control class to avoid absolute position for action-btn - $(this.all_activities_wrapper).removeClass('frappe-control'); + $(this.all_activities_wrapper).removeClass("frappe-control"); // hide new event button - $('.timeline-actions').find('.btn-default').hide(); + $(".timeline-actions").find(".btn-default").hide(); // hide new comment box $(".comment-box").hide(); // show only communications by default - $($('.timeline-content').find('.nav-link')[0]).tab('show'); + $($(".timeline-content").find(".nav-link")[0]).tab("show"); } // open activities @@ -28,66 +28,70 @@ erpnext.utils.CRMActivities = class CRMActivities { method: "erpnext.crm.utils.get_open_activities", args: { ref_doctype: this.frm.doc.doctype, - ref_docname: this.frm.doc.name + ref_docname: this.frm.doc.name, }, callback: (r) => { if (!r.exc) { - var activities_html = frappe.render_template('crm_activities', { + var activities_html = frappe.render_template("crm_activities", { tasks: r.message.tasks, - events: r.message.events + events: r.message.events, }); $(activities_html).appendTo(me.open_activities_wrapper); - $(".open-tasks").find(".completion-checkbox").on("click", function() { - me.update_status(this, "ToDo"); - }); + $(".open-tasks") + .find(".completion-checkbox") + .on("click", function () { + me.update_status(this, "ToDo"); + }); - $(".open-events").find(".completion-checkbox").on("click", function() { - me.update_status(this, "Event"); - }); + $(".open-events") + .find(".completion-checkbox") + .on("click", function () { + me.update_status(this, "Event"); + }); me.create_task(); me.create_event(); } - } + }, }); } - create_task () { + create_task() { let me = this; let _create_task = () => { const args = { doc: me.frm.doc, frm: me.frm, - title: __("New Task") + title: __("New Task"), }; let composer = new frappe.views.InteractionComposer(args); - composer.dialog.get_field('interaction_type').set_value("ToDo"); + composer.dialog.get_field("interaction_type").set_value("ToDo"); // hide column having interaction type field - $(composer.dialog.get_field('interaction_type').wrapper).closest('.form-column').hide(); + $(composer.dialog.get_field("interaction_type").wrapper).closest(".form-column").hide(); // hide summary field - $(composer.dialog.get_field('summary').wrapper).closest('.form-section').hide(); + $(composer.dialog.get_field("summary").wrapper).closest(".form-section").hide(); }; $(".new-task-btn").click(_create_task); } - create_event () { + create_event() { let me = this; let _create_event = () => { const args = { doc: me.frm.doc, frm: me.frm, - title: __("New Event") + title: __("New Event"), }; let composer = new frappe.views.InteractionComposer(args); - composer.dialog.get_field('interaction_type').set_value("Event"); - $(composer.dialog.get_field('interaction_type').wrapper).hide(); + composer.dialog.get_field("interaction_type").set_value("Event"); + $(composer.dialog.get_field("interaction_type").wrapper).hide(); }; $(".new-event-btn").click(_create_event); } - async update_status (input_field, doctype) { + async update_status(input_field, doctype) { let completed = $(input_field).prop("checked") ? 1 : 0; let docname = $(input_field).attr("name"); if (completed) { @@ -104,132 +108,129 @@ erpnext.utils.CRMNotes = class CRMNotes { refresh() { var me = this; - this.notes_wrapper.find('.notes-section').remove(); + this.notes_wrapper.find(".notes-section").remove(); let notes = this.frm.doc.notes || []; - notes.sort( - function(a, b) { - return new Date(b.added_on) - new Date(a.added_on); - } - ); - - let notes_html = frappe.render_template( - 'crm_notes', - { - notes: notes - } - ); + notes.sort(function (a, b) { + return new Date(b.added_on) - new Date(a.added_on); + }); + + let notes_html = frappe.render_template("crm_notes", { + notes: notes, + }); $(notes_html).appendTo(this.notes_wrapper); this.add_note(); - $(".notes-section").find(".edit-note-btn").on("click", function() { - me.edit_note(this); - }); + $(".notes-section") + .find(".edit-note-btn") + .on("click", function () { + me.edit_note(this); + }); - $(".notes-section").find(".delete-note-btn").on("click", function() { - me.delete_note(this); - }); + $(".notes-section") + .find(".delete-note-btn") + .on("click", function () { + me.delete_note(this); + }); } - - add_note () { + add_note() { let me = this; let _add_note = () => { var d = new frappe.ui.Dialog({ - title: __('Add a Note'), + title: __("Add a Note"), fields: [ { - "label": "Note", - "fieldname": "note", - "fieldtype": "Text Editor", - "reqd": 1, - "enable_mentions": true, - } + label: "Note", + fieldname: "note", + fieldtype: "Text Editor", + reqd: 1, + enable_mentions: true, + }, ], - primary_action: function() { + primary_action: function () { var data = d.get_values(); frappe.call({ method: "add_note", doc: me.frm.doc, args: { - note: data.note + note: data.note, }, freeze: true, - callback: function(r) { + callback: function (r) { if (!r.exc) { me.frm.refresh_field("notes"); me.refresh(); } d.hide(); - } + }, }); }, - primary_action_label: __('Add') + primary_action_label: __("Add"), }); d.show(); }; $(".new-note-btn").click(_add_note); } - edit_note (edit_btn) { + edit_note(edit_btn) { var me = this; - let row = $(edit_btn).closest('.comment-content'); + let row = $(edit_btn).closest(".comment-content"); let row_id = row.attr("name"); let row_content = $(row).find(".content").html(); if (row_content) { var d = new frappe.ui.Dialog({ - title: __('Edit Note'), + title: __("Edit Note"), fields: [ { - "label": "Note", - "fieldname": "note", - "fieldtype": "Text Editor", - "default": row_content - } + label: "Note", + fieldname: "note", + fieldtype: "Text Editor", + default: row_content, + }, ], - primary_action: function() { + primary_action: function () { var data = d.get_values(); frappe.call({ method: "edit_note", doc: me.frm.doc, args: { note: data.note, - row_id: row_id + row_id: row_id, }, freeze: true, - callback: function(r) { + callback: function (r) { if (!r.exc) { me.frm.refresh_field("notes"); me.refresh(); d.hide(); } - - } + }, }); }, - primary_action_label: __('Done') + primary_action_label: __("Done"), }); d.show(); } } - delete_note (delete_btn) { + delete_note(delete_btn) { var me = this; - let row_id = $(delete_btn).closest('.comment-content').attr("name"); + let row_id = $(delete_btn).closest(".comment-content").attr("name"); frappe.call({ method: "delete_note", doc: me.frm.doc, args: { - row_id: row_id + row_id: row_id, }, freeze: true, - callback: function(r) { + callback: function (r) { if (!r.exc) { me.frm.refresh_field("notes"); me.refresh(); } - } + }, }); } }; diff --git a/erpnext/public/js/utils/customer_quick_entry.js b/erpnext/public/js/utils/customer_quick_entry.js index b2532085f652..e9b77a356b2e 100644 --- a/erpnext/public/js/utils/customer_quick_entry.js +++ b/erpnext/public/js/utils/customer_quick_entry.js @@ -1,3 +1,3 @@ -frappe.provide('frappe.ui.form'); +frappe.provide("frappe.ui.form"); frappe.ui.form.CustomerQuickEntryForm = frappe.ui.form.ContactAddressQuickEntryForm; diff --git a/erpnext/public/js/utils/dimension_tree_filter.js b/erpnext/public/js/utils/dimension_tree_filter.js index 27d00bacb882..36c0f1b51ae6 100644 --- a/erpnext/public/js/utils/dimension_tree_filter.js +++ b/erpnext/public/js/utils/dimension_tree_filter.js @@ -1,4 +1,4 @@ -frappe.provide('erpnext.accounts'); +frappe.provide("erpnext.accounts"); erpnext.accounts.dimensions = { setup_dimension_filters(frm, doctype) { @@ -12,36 +12,38 @@ erpnext.accounts.dimensions = { frappe.call({ method: "erpnext.accounts.doctype.accounting_dimension.accounting_dimension.get_dimensions", args: { - 'with_cost_center_and_project': true + with_cost_center_and_project: true, }, - callback: function(r) { + callback: function (r) { me.accounting_dimensions = r.message[0]; // Ignoring "Project" as it is already handled specifically in Sales Order and Delivery Note - me.accounting_dimensions = me.accounting_dimensions.filter(x=>{return x.document_type != "Project"}); + me.accounting_dimensions = me.accounting_dimensions.filter((x) => { + return x.document_type != "Project"; + }); me.default_dimensions = r.message[1]; me.setup_filters(frm, doctype); - } + }, }); }, setup_filters(frm, doctype) { - if (doctype == 'Payment Entry' && this.accounting_dimensions) { - frm.dimension_filters = this.accounting_dimensions + if (doctype == "Payment Entry" && this.accounting_dimensions) { + frm.dimension_filters = this.accounting_dimensions; } if (this.accounting_dimensions) { this.accounting_dimensions.forEach((dimension) => { - frappe.model.with_doctype(dimension['document_type'], () => { + frappe.model.with_doctype(dimension["document_type"], () => { let parent_fields = []; frappe.meta.get_docfields(doctype).forEach((df) => { - if (df.fieldtype === 'Link' && df.options === 'Account') { + if (df.fieldtype === "Link" && df.options === "Account") { parent_fields.push(df.fieldname); - } else if (df.fieldtype === 'Table') { - this.setup_child_filters(frm, df.options, df.fieldname, dimension['fieldname']); + } else if (df.fieldtype === "Table") { + this.setup_child_filters(frm, df.options, df.fieldname, dimension["fieldname"]); } - if (frappe.meta.has_field(doctype, dimension['fieldname'])) { - this.setup_account_filters(frm, dimension['fieldname'], parent_fields); + if (frappe.meta.has_field(doctype, dimension["fieldname"])) { + this.setup_account_filters(frm, dimension["fieldname"], parent_fields); } }); }); @@ -55,12 +57,12 @@ erpnext.accounts.dimensions = { if (frappe.meta.has_field(doctype, dimension)) { frappe.model.with_doctype(doctype, () => { frappe.meta.get_docfields(doctype).forEach((df) => { - if (df.fieldtype === 'Link' && df.options === 'Account') { + if (df.fieldtype === "Link" && df.options === "Account") { fields.push(df.fieldname); } }); - frm.set_query(dimension, parentfield, function(doc, cdt, cdn) { + frm.set_query(dimension, parentfield, function (doc, cdt, cdn) { let row = locals[cdt][cdn]; return erpnext.queries.get_filtered_dimensions(row, fields, dimension, doc.company); }); @@ -69,7 +71,7 @@ erpnext.accounts.dimensions = { }, setup_account_filters(frm, dimension, fields) { - frm.set_query(dimension, function(doc) { + frm.set_query(dimension, function (doc) { return erpnext.queries.get_filtered_dimensions(doc, fields, dimension, doc.company); }); }, @@ -78,18 +80,26 @@ erpnext.accounts.dimensions = { if (this.accounting_dimensions) { this.accounting_dimensions.forEach((dimension) => { if (frm.is_new()) { - if (frm.doc.company && Object.keys(this.default_dimensions || {}).length > 0 - && this.default_dimensions[frm.doc.company]) { - - let default_dimension = this.default_dimensions[frm.doc.company][dimension['fieldname']]; + if ( + frm.doc.company && + Object.keys(this.default_dimensions || {}).length > 0 && + this.default_dimensions[frm.doc.company] + ) { + let default_dimension = + this.default_dimensions[frm.doc.company][dimension["fieldname"]]; if (default_dimension) { - if (frappe.meta.has_field(doctype, dimension['fieldname'])) { - frm.set_value(dimension['fieldname'], default_dimension); + if (frappe.meta.has_field(doctype, dimension["fieldname"])) { + frm.set_value(dimension["fieldname"], default_dimension); } - $.each(frm.doc.items || frm.doc.accounts || [], function(i, row) { - frappe.model.set_value(row.doctype, row.name, dimension['fieldname'], default_dimension); + $.each(frm.doc.items || frm.doc.accounts || [], function (i, row) { + frappe.model.set_value( + row.doctype, + row.name, + dimension["fieldname"], + default_dimension + ); }); } } @@ -102,8 +112,8 @@ erpnext.accounts.dimensions = { if (frappe.meta.has_field(frm.doctype, fieldname) && this.accounting_dimensions) { this.accounting_dimensions.forEach((dimension) => { let row = frappe.get_doc(cdt, cdn); - frm.script_manager.copy_from_first_row(fieldname, row, [dimension['fieldname']]); + frm.script_manager.copy_from_first_row(fieldname, row, [dimension["fieldname"]]); }); } - } + }, }; diff --git a/erpnext/public/js/utils/item_quick_entry.js b/erpnext/public/js/utils/item_quick_entry.js index 7e0198d33b34..42c60870e0d4 100644 --- a/erpnext/public/js/utils/item_quick_entry.js +++ b/erpnext/public/js/utils/item_quick_entry.js @@ -1,4 +1,4 @@ -frappe.provide('frappe.ui.form'); +frappe.provide("frappe.ui.form"); frappe.ui.form.ItemQuickEntryForm = class ItemQuickEntryForm extends frappe.ui.form.QuickEntryForm { constructor(doctype, after_insert) { @@ -12,12 +12,14 @@ frappe.ui.form.ItemQuickEntryForm = class ItemQuickEntryForm extends frappe.ui.f super.render_dialog(); this.init_post_render_dialog_operations(); this.preset_fields_for_template(); - this.dialog.$wrapper.find('.edit-full').text(__('Edit in full page for more options like assets, serial nos, batches etc.')) + this.dialog.$wrapper + .find(".edit-full") + .text(__("Edit in full page for more options like assets, serial nos, batches etc.")); } check_naming_series_based_on() { if (frappe.defaults.get_default("item_naming_by") === "Naming Series") { - this.mandatory = this.mandatory.filter(d => d.fieldname !== "item_code"); + this.mandatory = this.mandatory.filter((d) => d.fieldname !== "item_code"); } } @@ -33,7 +35,7 @@ frappe.ui.form.ItemQuickEntryForm = class ItemQuickEntryForm extends frappe.ui.f register_primary_action() { var me = this; - this.dialog.set_primary_action(__('Save'), function() { + this.dialog.set_primary_action(__("Save"), function () { if (me.dialog.working) return; var data = me.dialog.get_values(); @@ -52,8 +54,8 @@ frappe.ui.form.ItemQuickEntryForm = class ItemQuickEntryForm extends frappe.ui.f me.dialog.working = true; var values = me.update_doc(); //patch for manufacturer type variants as extend is overwriting it. - if (variant_values['variant_based_on'] == "Manufacturer") { - values['variant_based_on'] = "Manufacturer"; + if (variant_values["variant_based_on"] == "Manufacturer") { + values["variant_based_on"] = "Manufacturer"; } $.extend(variant_values, values); me.insert(variant_values); @@ -63,13 +65,13 @@ frappe.ui.form.ItemQuickEntryForm = class ItemQuickEntryForm extends frappe.ui.f insert(variant_values) { let me = this; - return new Promise(resolve => { + return new Promise((resolve) => { frappe.call({ method: "frappe.client.insert", args: { - doc: variant_values + doc: variant_values, }, - callback: function(r) { + callback: function (r) { me.dialog.hide(); // delete the old doc frappe.model.clear_doc(me.dialog.doc.doctype, me.dialog.doc.name); @@ -84,14 +86,14 @@ frappe.ui.form.ItemQuickEntryForm = class ItemQuickEntryForm extends frappe.ui.f } } }, - error: function() { + error: function () { me.open_doc(); }, - always: function() { + always: function () { me.dialog.working = false; resolve(me.dialog.doc); }, - freeze: true + freeze: true, }); }); } @@ -101,60 +103,66 @@ frappe.ui.form.ItemQuickEntryForm = class ItemQuickEntryForm extends frappe.ui.f this.update_doc(); if (this.dialog.fields_dict.create_variant.$input.prop("checked")) { var template = this.dialog.fields_dict.item_template.input.value; - if (template) - frappe.set_route("Form", this.doctype, template); + if (template) frappe.set_route("Form", this.doctype, template); } else { - frappe.set_route('Form', this.doctype, this.doc.name); + frappe.set_route("Form", this.doctype, this.doc.name); } } get_variant_fields() { - var variant_fields = [{ - fieldname: "create_variant", - fieldtype: "Check", - label: __("Create Variant") - }, - { - fieldname: 'item_template', - label: __('Item Template'), - reqd: 0, - fieldtype: 'Link', - options: "Item", - get_query: function() { - return { - filters: { - "has_variants": 1 - } - }; - } - }]; + var variant_fields = [ + { + fieldname: "create_variant", + fieldtype: "Check", + label: __("Create Variant"), + }, + { + fieldname: "item_template", + label: __("Item Template"), + reqd: 0, + fieldtype: "Link", + options: "Item", + get_query: function () { + return { + filters: { + has_variants: 1, + }, + }; + }, + }, + ]; return variant_fields; } get_manufacturing_fields() { - this.manufacturer_fields = [{ - fieldtype: 'Link', - options: 'Manufacturer', - label: 'Manufacturer', - fieldname: "manufacturer", - hidden: 1, - reqd: 0 - }, { - fieldtype: 'Data', - label: 'Manufacturer Part Number', - fieldname: 'manufacturer_part_no', - hidden: 1, - reqd: 0 - }]; + this.manufacturer_fields = [ + { + fieldtype: "Link", + options: "Manufacturer", + label: "Manufacturer", + fieldname: "manufacturer", + hidden: 1, + reqd: 0, + }, + { + fieldtype: "Data", + label: "Manufacturer Part Number", + fieldname: "manufacturer_part_no", + hidden: 1, + reqd: 0, + }, + ]; return this.manufacturer_fields; } get_attributes_fields() { - var attribute_fields = [{ - fieldname: 'attribute_html', - fieldtype: 'HTML' - }] + var attribute_fields = [ + { + fieldname: "attribute_html", + fieldtype: "HTML", + }, + ]; attribute_fields = attribute_fields.concat(this.get_manufacturing_fields()); return attribute_fields; @@ -163,38 +171,37 @@ frappe.ui.form.ItemQuickEntryForm = class ItemQuickEntryForm extends frappe.ui.f init_for_create_variant_trigger() { var me = this; - this.dialog.fields_dict.create_variant.$input.on("click", function() { + this.dialog.fields_dict.create_variant.$input.on("click", function () { me.preset_fields_for_template(); me.init_post_template_trigger_operations(false, [], true); }); } preset_fields_for_template() { - var for_variant = this.dialog.get_value('create_variant'); + var for_variant = this.dialog.get_value("create_variant"); // setup template field, seen and mandatory if variant let template_field = this.dialog.get_field("item_template"); template_field.df.reqd = for_variant; - template_field.set_value(''); + template_field.set_value(""); template_field.df.hidden = !for_variant; template_field.refresh(); // hide properties for variant - ['item_code', 'item_name', 'item_group', 'stock_uom'].forEach((d) => { + ["item_code", "item_name", "item_group", "stock_uom"].forEach((d) => { let f = this.dialog.get_field(d); f.df.hidden = for_variant; f.refresh(); }); - this.dialog.get_field('attribute_html').toggle(false); + this.dialog.get_field("attribute_html").toggle(false); // non mandatory for variants - ['item_code', 'stock_uom', 'item_group'].forEach((d) => { + ["item_code", "stock_uom", "item_group"].forEach((d) => { let f = this.dialog.get_field(d); f.df.reqd = !for_variant; f.refresh(); }); - } init_for_item_template_trigger() { @@ -208,26 +215,29 @@ frappe.ui.form.ItemQuickEntryForm = class ItemQuickEntryForm extends frappe.ui.f method: "frappe.client.get", args: { doctype: "Item", - name: template + name: template, }, - callback: function(r) { + callback: function (r) { me.template_doc = r.message; me.is_manufacturer = false; if (me.template_doc.variant_based_on === "Manufacturer") { me.init_post_template_trigger_operations(true, [], true); } else { - - me.init_post_template_trigger_operations(false, me.template_doc.attributes, false); + me.init_post_template_trigger_operations( + false, + me.template_doc.attributes, + false + ); me.render_attributes(me.template_doc.attributes); } - } + }, }); } else { - me.dialog.get_field('attribute_html').toggle(false); + me.dialog.get_field("attribute_html").toggle(false); me.init_post_template_trigger_operations(false, [], true); } - } + }; } init_post_template_trigger_operations(is_manufacturer, attributes, attributes_flag) { @@ -238,15 +248,20 @@ frappe.ui.form.ItemQuickEntryForm = class ItemQuickEntryForm extends frappe.ui.f this.dialog.fields_dict.attribute_html.$wrapper.find(".attributes").empty(); this.is_manufacturer = is_manufacturer; this.toggle_manufacturer_fields(); - this.dialog.fields_dict.attribute_html.$wrapper.find(".attributes").toggleClass("hide-control", attributes_flag); - this.dialog.fields_dict.attribute_html.$wrapper.find(".attributes-header").toggleClass("hide-control", attributes_flag); + this.dialog.fields_dict.attribute_html.$wrapper + .find(".attributes") + .toggleClass("hide-control", attributes_flag); + this.dialog.fields_dict.attribute_html.$wrapper + .find(".attributes-header") + .toggleClass("hide-control", attributes_flag); } toggle_manufacturer_fields() { var me = this; - $.each(this.manufacturer_fields, function(i, dialog_field) { + $.each(this.manufacturer_fields, function (i, dialog_field) { me.dialog.get_field(dialog_field.fieldname).df.hidden = !me.is_manufacturer; - me.dialog.get_field(dialog_field.fieldname).df.reqd = dialog_field.fieldname == 'manufacturer' ? me.is_manufacturer : false; + me.dialog.get_field(dialog_field.fieldname).df.reqd = + dialog_field.fieldname == "manufacturer" ? me.is_manufacturer : false; me.dialog.get_field(dialog_field.fieldname).refresh(); }); } @@ -259,35 +274,48 @@ frappe.ui.form.ItemQuickEntryForm = class ItemQuickEntryForm extends frappe.ui.f render_attributes(attributes) { var me = this; - this.dialog.get_field('attribute_html').toggle(true); + this.dialog.get_field("attribute_html").toggle(true); - $.each(attributes, function(index, row) { + $.each(attributes, function (index, row) { var desc = ""; var fieldtype = "Data"; if (row.numeric_values) { fieldtype = "Float"; - desc = "Min Value: " + row.from_range + " , Max Value: " + row.to_range + ", in Increments of: " + row.increment; + desc = + "Min Value: " + + row.from_range + + " , Max Value: " + + row.to_range + + ", in Increments of: " + + row.increment; } me.init_make_control(fieldtype, row); me[row.attribute].set_value(me.attribute_values[row.attribute] || ""); - me[row.attribute].$wrapper.toggleClass("has-error", me.attribute_values[row.attribute] ? false : true); + me[row.attribute].$wrapper.toggleClass( + "has-error", + me.attribute_values[row.attribute] ? false : true + ); // Set Label explicitly as make_control is not displaying label $(me[row.attribute].label_area).text(__(row.attribute)); if (desc) { - $(repl(``, { - "desc": desc - })).insertAfter(me[row.attribute].input_area); + $( + repl(``, { + desc: desc, + }) + ).insertAfter(me[row.attribute].input_area); } if (!row.numeric_values) { me.init_awesomplete_for_attribute(row); } else { - me[row.attribute].$input.on("change", function() { + me[row.attribute].$input.on("change", function () { me.attribute_values[row.attribute] = $(this).val(); - $(this).closest(".frappe-control").toggleClass("has-error", $(this).val() ? false : true); + $(this) + .closest(".frappe-control") + .toggleClass("has-error", $(this).val() ? false : true); }); } }); @@ -296,13 +324,13 @@ frappe.ui.form.ItemQuickEntryForm = class ItemQuickEntryForm extends frappe.ui.f init_make_control(fieldtype, row) { this[row.attribute] = frappe.ui.form.make_control({ df: { - "fieldtype": fieldtype, - "label": row.attribute, - "fieldname": row.attribute, - "options": row.options || "" + fieldtype: fieldtype, + label: row.attribute, + fieldname: row.attribute, + options: row.options || "", }, parent: $(this.dialog.fields_dict.attribute_html.wrapper).find(".attributes"), - only_input: false + only_input: false, }); this[row.attribute].make_input(); } @@ -317,32 +345,37 @@ frappe.ui.form.ItemQuickEntryForm = class ItemQuickEntryForm extends frappe.ui.f list: [], }); - this[row.attribute].$input.on('input', function(e) { - frappe.call({ - method: "frappe.client.get_list", - args: { - doctype: "Item Attribute Value", - filters: [ - ["parent", "=", $(e.target).attr("data-fieldname")], - ["attribute_value", "like", e.target.value + "%"] - ], - fields: ["attribute_value"], - parent: "Item Attribute" - }, - callback: function(r) { - if (r.message) { - e.target.awesomplete.list = r.message.map(function(d) { - return d.attribute_value; - }); - } - } + this[row.attribute].$input + .on("input", function (e) { + frappe.call({ + method: "frappe.client.get_list", + args: { + doctype: "Item Attribute Value", + filters: [ + ["parent", "=", $(e.target).attr("data-fieldname")], + ["attribute_value", "like", e.target.value + "%"], + ], + fields: ["attribute_value"], + parent: "Item Attribute", + }, + callback: function (r) { + if (r.message) { + e.target.awesomplete.list = r.message.map(function (d) { + return d.attribute_value; + }); + } + }, + }); + }) + .on("focus", function (e) { + $(e.target).val("").trigger("input"); + }) + .on("awesomplete-close", function (e) { + me.attribute_values[$(e.target).attr("data-fieldname")] = e.target.value; + $(e.target) + .closest(".frappe-control") + .toggleClass("has-error", e.target.value ? false : true); }); - }).on('focus', function(e) { - $(e.target).val('').trigger('input'); - }).on("awesomplete-close", function (e) { - me.attribute_values[$(e.target).attr("data-fieldname")] = e.target.value; - $(e.target).closest(".frappe-control").toggleClass("has-error", e.target.value ? false : true); - }); } get_variant_doc() { @@ -354,31 +387,38 @@ frappe.ui.form.ItemQuickEntryForm = class ItemQuickEntryForm extends frappe.ui.f frappe.call({ method: "erpnext.controllers.item_variant.create_variant_doc_for_quick_entry", args: { - "template": me.dialog.fields_dict.item_template.$input.val(), - args: attribute + template: me.dialog.fields_dict.item_template.$input.val(), + args: attribute, }, async: false, - callback: function(r) { + callback: function (r) { if (Object.prototype.toString.call(r.message) == "[object Object]") { variant_doc = r.message; } else { - var msgprint_dialog = frappe.msgprint(__("Item Variant {0} already exists with same attributes", [repl('%(item)s', { - item: r.message - })])); - - msgprint_dialog.$wrapper.find(".variant-click").on("click", function() { + var msgprint_dialog = frappe.msgprint( + __("Item Variant {0} already exists with same attributes", [ + repl( + '%(item)s', + { + item: r.message, + } + ), + ]) + ); + + msgprint_dialog.$wrapper.find(".variant-click").on("click", function () { msgprint_dialog.hide(); me.dialog.hide(); if (frappe._from_link) { frappe._from_link.set_value($(this).attr("data-item-code")); } else { - frappe.set_route('Form', "Item", $(this).attr("data-item-code")); + frappe.set_route("Form", "Item", $(this).attr("data-item-code")); } }); } - } - }) + }, + }); } return variant_doc; } @@ -388,17 +428,17 @@ frappe.ui.form.ItemQuickEntryForm = class ItemQuickEntryForm extends frappe.ui.f var attribute = {}; var mandatory = []; - $.each(this.attributes, function(index, attr) { + $.each(this.attributes, function (index, attr) { var value = me.attribute_values[attr.attribute] || ""; if (value) { attribute[attr.attribute] = attr.numeric_values ? flt(value) : value; } else { mandatory.push(attr.attribute); } - }) + }); if (this.is_manufacturer) { - $.each(this.manufacturer_fields, function(index, field) { + $.each(this.manufacturer_fields, function (index, field) { attribute[field.fieldname] = me.dialog.fields_dict[field.fieldname].input.value; }); } diff --git a/erpnext/public/js/utils/item_selector.js b/erpnext/public/js/utils/item_selector.js index 9fc264086a3b..5d2e915022e3 100644 --- a/erpnext/public/js/utils/item_selector.js +++ b/erpnext/public/js/utils/item_selector.js @@ -3,7 +3,7 @@ erpnext.ItemSelector = class ItemSelector { $.extend(this, opts); if (!this.item_field) { - this.item_field = 'item_code'; + this.item_field = "item_code"; } if (!this.item_query) { @@ -16,39 +16,43 @@ erpnext.ItemSelector = class ItemSelector { setup() { var me = this; - if(!this.grid.add_items_button) { - this.grid.add_items_button = this.grid.add_custom_button(__('Add Items'), function() { - if(!me.dialog) { + if (!this.grid.add_items_button) { + this.grid.add_items_button = this.grid.add_custom_button(__("Add Items"), function () { + if (!me.dialog) { me.make_dialog(); } me.dialog.show(); me.render_items(); - setTimeout(function() { me.dialog.input.focus(); }, 1000); + setTimeout(function () { + me.dialog.input.focus(); + }, 1000); }); } } make_dialog() { this.dialog = new frappe.ui.Dialog({ - title: __('Add Items') + title: __("Add Items"), }); var body = $(this.dialog.body); - body.html('

              \ -
              '); + body.html( + '

              \ +
              ' + ); - this.dialog.input = body.find('.form-control'); - this.dialog.results = body.find('.results'); + this.dialog.input = body.find(".form-control"); + this.dialog.results = body.find(".results"); var me = this; - this.dialog.results.on('click', '.image-view-item', function() { - me.add_item($(this).attr('data-name')); + this.dialog.results.on("click", ".image-view-item", function () { + me.add_item($(this).attr("data-name")); }); - this.dialog.input.on('keyup', function() { - if(me.timeout_id) { + this.dialog.input.on("keyup", function () { + if (me.timeout_id) { clearTimeout(me.timeout_id); } - me.timeout_id = setTimeout(function() { + me.timeout_id = setTimeout(function () { me.render_items(); me.timeout_id = undefined; }, 500); @@ -61,33 +65,34 @@ erpnext.ItemSelector = class ItemSelector { // find row with item if exists $.each(this.frm.doc.items || [], (i, d) => { - if(d[this.item_field]===item_code) { - frappe.model.set_value(d.doctype, d.name, 'qty', d.qty + 1); - frappe.show_alert({message: __("Added {0} ({1})", [item_code, d.qty]), indicator: 'green'}); + if (d[this.item_field] === item_code) { + frappe.model.set_value(d.doctype, d.name, "qty", d.qty + 1); + frappe.show_alert({ message: __("Added {0} ({1})", [item_code, d.qty]), indicator: "green" }); added = true; return false; } }); - if(!added) { + if (!added) { var d = null; frappe.run_serially([ - () => { d = this.grid.add_new_row(); }, + () => { + d = this.grid.add_new_row(); + }, () => frappe.model.set_value(d.doctype, d.name, this.item_field, item_code), () => frappe.timeout(0.1), () => { - frappe.model.set_value(d.doctype, d.name, 'qty', 1); - frappe.show_alert({message: __("Added {0} ({1})", [item_code, 1]), indicator: 'green'}); - } + frappe.model.set_value(d.doctype, d.name, "qty", 1); + frappe.show_alert({ message: __("Added {0} ({1})", [item_code, 1]), indicator: "green" }); + }, ]); } - } render_items() { let args = { query: this.item_query, - filters: {} + filters: {}, }; args.txt = this.dialog.input.val(); args.as_dict = 1; @@ -97,14 +102,14 @@ erpnext.ItemSelector = class ItemSelector { } var me = this; - frappe.link_search("Item", args, function(r) { - $.each(r.values, function(i, d) { - if(!d.image) { + frappe.link_search("Item", args, function (r) { + $.each(r.values, function (i, d) { + if (!d.image) { d.abbr = frappe.get_abbr(d.item_name); d.color = frappe.get_palette(d.item_name); } }); - me.dialog.results.html(frappe.render_template('item_selector', {'data':r.values})); + me.dialog.results.html(frappe.render_template("item_selector", { data: r.values })); }); } }; diff --git a/erpnext/public/js/utils/party.js b/erpnext/public/js/utils/party.js index cba615c0d229..801376b2ed7d 100644 --- a/erpnext/public/js/utils/party.js +++ b/erpnext/public/js/utils/party.js @@ -3,18 +3,19 @@ frappe.provide("erpnext.utils"); -const SALES_DOCTYPES = ['Quotation', 'Sales Order', 'Delivery Note', 'Sales Invoice']; -const PURCHASE_DOCTYPES = ['Supplier Quotation','Purchase Order', 'Purchase Receipt', 'Purchase Invoice']; +const SALES_DOCTYPES = ["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"]; +const PURCHASE_DOCTYPES = ["Supplier Quotation", "Purchase Order", "Purchase Receipt", "Purchase Invoice"]; -erpnext.utils.get_party_details = function(frm, method, args, callback) { +erpnext.utils.get_party_details = function (frm, method, args, callback) { if (!method) { method = "erpnext.accounts.party.get_party_details"; } if (!args) { - if ((frm.doctype != "Purchase Order" && frm.doc.customer) - || (frm.doc.party_name && in_list(['Quotation', 'Opportunity'], frm.doc.doctype))) { - + if ( + (frm.doctype != "Purchase Order" && frm.doc.customer) || + (frm.doc.party_name && in_list(["Quotation", "Opportunity"], frm.doc.doctype)) + ) { let party_type = "Customer"; if (frm.doc.quotation_to && in_list(["Lead", "Prospect"], frm.doc.quotation_to)) { party_type = frm.doc.quotation_to; @@ -23,14 +24,14 @@ erpnext.utils.get_party_details = function(frm, method, args, callback) { args = { party: frm.doc.customer || frm.doc.party_name, party_type: party_type, - price_list: frm.doc.selling_price_list + price_list: frm.doc.selling_price_list, }; } else if (frm.doc.supplier) { args = { party: frm.doc.supplier, party_type: "Supplier", bill_date: frm.doc.bill_date, - price_list: frm.doc.buying_price_list + price_list: frm.doc.buying_price_list, }; } @@ -38,14 +39,14 @@ erpnext.utils.get_party_details = function(frm, method, args, callback) { if (in_list(SALES_DOCTYPES, frm.doc.doctype)) { args = { party: frm.doc.customer || frm.doc.party_name, - party_type: 'Customer' + party_type: "Customer", }; } if (in_list(PURCHASE_DOCTYPES, frm.doc.doctype)) { args = { party: frm.doc.supplier, - party_type: 'Supplier' + party_type: "Supplier", }; } } @@ -72,13 +73,26 @@ erpnext.utils.get_party_details = function(frm, method, args, callback) { } } - if (frappe.meta.get_docfield(frm.doc.doctype, "taxes")) { - if (!erpnext.utils.validate_mandatory(frm, "Posting / Transaction Date", - args.posting_date, args.party_type=="Customer" ? "customer": "supplier")) return; + if ( + !erpnext.utils.validate_mandatory( + frm, + "Posting / Transaction Date", + args.posting_date, + args.party_type == "Customer" ? "customer" : "supplier" + ) + ) + return; } - if (!erpnext.utils.validate_mandatory(frm, "Company", frm.doc.company, args.party_type=="Customer" ? "customer": "supplier")) { + if ( + !erpnext.utils.validate_mandatory( + frm, + "Company", + frm.doc.company, + args.party_type == "Customer" ? "customer" : "supplier" + ) + ) { return; } @@ -88,7 +102,7 @@ erpnext.utils.get_party_details = function(frm, method, args, callback) { frappe.call({ method: method, args: args, - callback: function(r) { + callback: function (r) { if (r.message) { frm.supplier_tds = r.message.supplier_tds; frm.updating_party_details = true; @@ -99,28 +113,28 @@ erpnext.utils.get_party_details = function(frm, method, args, callback) { if (callback) callback(); frm.refresh(); erpnext.utils.add_item(frm); - } + }, ]); } - } + }, }); -} +}; -erpnext.utils.add_item = function(frm) { +erpnext.utils.add_item = function (frm) { if (frm.is_new()) { var prev_route = frappe.get_prev_route(); - if (prev_route[1]==='Item' && !(frm.doc.items && frm.doc.items.length)) { + if (prev_route[1] === "Item" && !(frm.doc.items && frm.doc.items.length)) { // add row - var item = frm.add_child('items'); - frm.refresh_field('items'); + var item = frm.add_child("items"); + frm.refresh_field("items"); // set item - frappe.model.set_value(item.doctype, item.name, 'item_code', prev_route[2]); + frappe.model.set_value(item.doctype, item.name, "item_code", prev_route[2]); } } -} +}; -erpnext.utils.get_address_display = function(frm, address_field, display_field, is_your_company_address) { +erpnext.utils.get_address_display = function (frm, address_field, display_field, is_your_company_address) { if (frm.updating_party_details) return; if (!address_field) { @@ -135,29 +149,46 @@ erpnext.utils.get_address_display = function(frm, address_field, display_field, if (frm.doc[address_field]) { frappe.call({ method: "frappe.contacts.doctype.address.address.get_address_display", - args: {"address_dict": frm.doc[address_field] }, - callback: function(r) { + args: { address_dict: frm.doc[address_field] }, + callback: function (r) { if (r.message) { - frm.set_value(display_field, r.message) + frm.set_value(display_field, r.message); } - } - }) + }, + }); } else { - frm.set_value(display_field, ''); + frm.set_value(display_field, ""); } }; -erpnext.utils.set_taxes_from_address = function(frm, triggered_from_field, billing_address_field, shipping_address_field) { +erpnext.utils.set_taxes_from_address = function ( + frm, + triggered_from_field, + billing_address_field, + shipping_address_field +) { if (frm.updating_party_details) return; if (frappe.meta.get_docfield(frm.doc.doctype, "taxes")) { - if (!erpnext.utils.validate_mandatory(frm, "Lead / Customer / Supplier", - frm.doc.customer || frm.doc.supplier || frm.doc.lead || frm.doc.party_name, triggered_from_field)) { + if ( + !erpnext.utils.validate_mandatory( + frm, + "Lead / Customer / Supplier", + frm.doc.customer || frm.doc.supplier || frm.doc.lead || frm.doc.party_name, + triggered_from_field + ) + ) { return; } - if (!erpnext.utils.validate_mandatory(frm, "Posting / Transaction Date", - frm.doc.posting_date || frm.doc.transaction_date, triggered_from_field)) { + if ( + !erpnext.utils.validate_mandatory( + frm, + "Posting / Transaction Date", + frm.doc.posting_date || frm.doc.transaction_date, + triggered_from_field + ) + ) { return; } } else { @@ -167,35 +198,47 @@ erpnext.utils.set_taxes_from_address = function(frm, triggered_from_field, billi frappe.call({ method: "erpnext.accounts.party.get_address_tax_category", args: { - "tax_category": frm.doc.tax_category, - "billing_address": frm.doc[billing_address_field], - "shipping_address": frm.doc[shipping_address_field] + tax_category: frm.doc.tax_category, + billing_address: frm.doc[billing_address_field], + shipping_address: frm.doc[shipping_address_field], }, - callback: function(r) { - if (!r.exc){ + callback: function (r) { + if (!r.exc) { if (frm.doc.tax_category != r.message) { frm.set_value("tax_category", r.message); } else { erpnext.utils.set_taxes(frm, triggered_from_field); } } - } + }, }); }; -erpnext.utils.set_taxes = function(frm, triggered_from_field) { +erpnext.utils.set_taxes = function (frm, triggered_from_field) { if (frappe.meta.get_docfield(frm.doc.doctype, "taxes")) { if (!erpnext.utils.validate_mandatory(frm, "Company", frm.doc.company, triggered_from_field)) { return; } - if (!erpnext.utils.validate_mandatory(frm, "Lead / Customer / Supplier", - frm.doc.customer || frm.doc.supplier || frm.doc.lead || frm.doc.party_name, triggered_from_field)) { + if ( + !erpnext.utils.validate_mandatory( + frm, + "Lead / Customer / Supplier", + frm.doc.customer || frm.doc.supplier || frm.doc.lead || frm.doc.party_name, + triggered_from_field + ) + ) { return; } - if (!erpnext.utils.validate_mandatory(frm, "Posting / Transaction Date", - frm.doc.posting_date || frm.doc.transaction_date, triggered_from_field)) { + if ( + !erpnext.utils.validate_mandatory( + frm, + "Posting / Transaction Date", + frm.doc.posting_date || frm.doc.transaction_date, + triggered_from_field + ) + ) { return; } } else { @@ -204,15 +247,15 @@ erpnext.utils.set_taxes = function(frm, triggered_from_field) { var party_type, party; if (frm.doc.lead) { - party_type = 'Lead'; + party_type = "Lead"; party = frm.doc.lead; } else if (frm.doc.customer) { - party_type = 'Customer'; + party_type = "Customer"; party = frm.doc.customer; } else if (frm.doc.supplier) { - party_type = 'Supplier'; + party_type = "Supplier"; party = frm.doc.supplier; - } else if (frm.doc.quotation_to){ + } else if (frm.doc.quotation_to) { party_type = frm.doc.quotation_to; party = frm.doc.party_name; } @@ -224,21 +267,22 @@ erpnext.utils.set_taxes = function(frm, triggered_from_field) { frappe.call({ method: "erpnext.accounts.party.set_taxes", args: { - "party": party, - "party_type": party_type, - "posting_date": frm.doc.posting_date || frm.doc.transaction_date, - "company": frm.doc.company, - "customer_group": frm.doc.customer_group, - "supplier_group": frm.doc.supplier_group, - "tax_category": frm.doc.tax_category, - "billing_address": ((frm.doc.customer || frm.doc.lead) ? (frm.doc.customer_address) : (frm.doc.supplier_address)), - "shipping_address": frm.doc.shipping_address_name + party: party, + party_type: party_type, + posting_date: frm.doc.posting_date || frm.doc.transaction_date, + company: frm.doc.company, + customer_group: frm.doc.customer_group, + supplier_group: frm.doc.supplier_group, + tax_category: frm.doc.tax_category, + billing_address: + frm.doc.customer || frm.doc.lead ? frm.doc.customer_address : frm.doc.supplier_address, + shipping_address: frm.doc.shipping_address_name, }, - callback: function(r) { - if (r.message){ - frm.set_value("taxes_and_charges", r.message) + callback: function (r) { + if (r.message) { + frm.set_value("taxes_and_charges", r.message); } - } + }, }); }; @@ -266,20 +310,23 @@ erpnext.utils.get_contact_details = function (frm) { } }; -erpnext.utils.validate_mandatory = function(frm, label, value, trigger_on) { +erpnext.utils.validate_mandatory = function (frm, label, value, trigger_on) { if (!value) { frm.doc[trigger_on] = ""; refresh_field(trigger_on); - frappe.throw({message:__("Please enter {0} first", [label]), title:__("Mandatory")}); + frappe.throw({ message: __("Please enter {0} first", [label]), title: __("Mandatory") }); return false; } return true; -} +}; -erpnext.utils.get_shipping_address = function(frm, callback) { +erpnext.utils.get_shipping_address = function (frm, callback) { if (frm.doc.company) { - if ((frm.doc.inter_company_order_reference || frm.doc.internal_invoice_reference || - frm.doc.internal_order_reference)) { + if ( + frm.doc.inter_company_order_reference || + frm.doc.internal_invoice_reference || + frm.doc.internal_order_reference + ) { if (callback) { return callback(); } @@ -288,20 +335,20 @@ erpnext.utils.get_shipping_address = function(frm, callback) { method: "erpnext.accounts.custom.address.get_shipping_address", args: { company: frm.doc.company, - address: frm.doc.shipping_address + address: frm.doc.shipping_address, }, - callback: function(r) { + callback: function (r) { if (r.message) { - frm.set_value("shipping_address", r.message[0]) //Address title or name - frm.set_value("shipping_address_display", r.message[1]) //Address to be displayed on the page + frm.set_value("shipping_address", r.message[0]); //Address title or name + frm.set_value("shipping_address_display", r.message[1]); //Address to be displayed on the page } - if (callback){ + if (callback) { return callback(); } - } + }, }); } else { frappe.msgprint(__("Select company first")); } -} +}; diff --git a/erpnext/public/js/utils/serial_no_batch_selector.js b/erpnext/public/js/utils/serial_no_batch_selector.js index 22120988ad0f..6fd7f7f45884 100644 --- a/erpnext/public/js/utils/serial_no_batch_selector.js +++ b/erpnext/public/js/utils/serial_no_batch_selector.js @@ -1,15 +1,15 @@ - erpnext.SerialNoBatchSelector = class SerialNoBatchSelector { constructor(opts, show_dialog) { $.extend(this, opts); this.show_dialog = show_dialog; // frm, item, warehouse_details, has_batch, oldest let d = this.item; - this.has_batch = 0; this.has_serial_no = 0; + this.has_batch = 0; + this.has_serial_no = 0; if (d && d.has_batch_no && (!d.batch_no || this.show_dialog)) this.has_batch = 1; // !(this.show_dialog == false) ensures that show_dialog is implictly true, even when undefined - if(d && d.has_serial_no && !(this.show_dialog == false)) this.has_serial_no = 1; + if (d && d.has_serial_no && !(this.show_dialog == false)) this.has_serial_no = 1; this.setup(); } @@ -28,70 +28,70 @@ erpnext.SerialNoBatchSelector = class SerialNoBatchSelector { let title = ""; let fields = [ { - fieldname: 'item_code', + fieldname: "item_code", read_only: 1, - fieldtype:'Link', - options: 'Item', - label: __('Item Code'), - default: me.item_code + fieldtype: "Link", + options: "Item", + label: __("Item Code"), + default: me.item_code, }, { - fieldname: 'warehouse', - fieldtype:'Link', - options: 'Warehouse', + fieldname: "warehouse", + fieldtype: "Link", + options: "Warehouse", reqd: me.has_batch && !me.has_serial_no ? 0 : 1, label: __(me.warehouse_details.type), - default: typeof me.warehouse_details.name == "string" ? me.warehouse_details.name : '', - onchange: function(e) { + default: typeof me.warehouse_details.name == "string" ? me.warehouse_details.name : "", + onchange: function (e) { me.warehouse_details.name = this.get_value(); - if(me.has_batch && !me.has_serial_no) { + if (me.has_batch && !me.has_serial_no) { fields = fields.concat(me.get_batch_fields()); } else { fields = fields.concat(me.get_serial_no_fields()); } var batches = this.layout.fields_dict.batches; - if(batches) { + if (batches) { batches.grid.df.data = []; batches.grid.refresh(); batches.grid.add_new_row(null, null, null); } }, - get_query: function() { + get_query: function () { return { query: "erpnext.controllers.queries.warehouse_query", filters: [ ["Bin", "item_code", "=", me.item_code], ["Warehouse", "is_group", "=", 0], - ["Warehouse", "company", "=", me.frm.doc.company] - ] - } - } + ["Warehouse", "company", "=", me.frm.doc.company], + ], + }; + }, }, - {fieldtype:'Column Break'}, + { fieldtype: "Column Break" }, { - fieldname: 'qty', - fieldtype:'Float', + fieldname: "qty", + fieldtype: "Float", read_only: me.has_batch && !me.has_serial_no, - label: __(me.has_batch && !me.has_serial_no ? 'Selected Qty' : 'Qty'), + label: __(me.has_batch && !me.has_serial_no ? "Selected Qty" : "Qty"), default: flt(me.item.stock_qty) || flt(me.item.transfer_qty), }, ...get_pending_qty_fields(me), { - fieldname: 'uom', + fieldname: "uom", read_only: 1, - fieldtype: 'Link', - options: 'UOM', - label: __('UOM'), - default: me.item.uom + fieldtype: "Link", + options: "UOM", + label: __("UOM"), + default: me.item.uom, }, { - fieldname: 'auto_fetch_button', - fieldtype:'Button', + fieldname: "auto_fetch_button", + fieldtype: "Button", hidden: me.has_batch && !me.has_serial_no, - label: __('Auto Fetch'), - description: __('Fetch Serial Numbers based on FIFO'), + label: __("Auto Fetch"), + description: __("Fetch Serial Numbers based on FIFO"), click: () => { let qty = this.dialog.fields_dict.qty.get_value(); let already_selected_serial_nos = get_selected_serial_nos(me); @@ -100,11 +100,12 @@ erpnext.SerialNoBatchSelector = class SerialNoBatchSelector { args: { qty: qty, item_code: me.item_code, - warehouse: typeof me.warehouse_details.name == "string" ? me.warehouse_details.name : '', + warehouse: + typeof me.warehouse_details.name == "string" ? me.warehouse_details.name : "", batch_nos: me.item.batch_no || null, posting_date: me.frm.doc.posting_date || me.frm.doc.transaction_date, - exclude_sr_nos: already_selected_serial_nos - } + exclude_sr_nos: already_selected_serial_nos, + }, }); numbers.then((data) => { @@ -113,18 +114,23 @@ erpnext.SerialNoBatchSelector = class SerialNoBatchSelector { if (!records_length) { const warehouse = me.dialog.fields_dict.warehouse.get_value().bold(); frappe.msgprint( - __('Serial numbers unavailable for Item {0} under warehouse {1}. Please try changing warehouse.', [me.item.item_code.bold(), warehouse]) + __( + "Serial numbers unavailable for Item {0} under warehouse {1}. Please try changing warehouse.", + [me.item.item_code.bold(), warehouse] + ) ); } if (records_length < qty) { - frappe.msgprint(__('Fetched only {0} available serial numbers.', [records_length])); + frappe.msgprint( + __("Fetched only {0} available serial numbers.", [records_length]) + ); } let serial_no_list_field = this.dialog.fields_dict.serial_no; - numbers = auto_fetched_serial_numbers.join('\n'); + numbers = auto_fetched_serial_numbers.join("\n"); serial_no_list_field.set_value(numbers); }); - } - } + }, + }, ]; if (this.has_batch && !this.has_serial_no) { @@ -139,12 +145,12 @@ erpnext.SerialNoBatchSelector = class SerialNoBatchSelector { this.dialog = new frappe.ui.Dialog({ title: title, - fields: fields + fields: fields, }); - this.dialog.set_primary_action(__('Insert'), function() { + this.dialog.set_primary_action(__("Insert"), function () { me.values = me.dialog.get_values(); - if(me.validate()) { + if (me.validate()) { frappe.run_serially([ () => me.update_batch_items(), () => me.update_serial_no_item(), @@ -156,25 +162,25 @@ erpnext.SerialNoBatchSelector = class SerialNoBatchSelector { return me.callback(me.item); } }, - () => me.dialog.hide() - ]) + () => me.dialog.hide(), + ]); } }); - if(this.show_dialog) { + if (this.show_dialog) { let d = this.item; if (this.item.serial_no) { this.dialog.fields_dict.serial_no.set_value(this.item.serial_no); } if (this.has_batch && !this.has_serial_no && d.batch_no) { - this.frm.doc.items.forEach(data => { - if(data.item_code == d.item_code) { + this.frm.doc.items.forEach((data) => { + if (data.item_code == d.item_code) { this.dialog.fields_dict.batches.df.data.push({ - 'batch_no': data.batch_no, - 'actual_qty': data.actual_qty, - 'selected_qty': data.qty, - 'available_qty': data.actual_batch_qty + batch_no: data.batch_no, + actual_qty: data.actual_qty, + selected_qty: data.qty, + available_qty: data.actual_batch_qty, }); } }); @@ -191,33 +197,32 @@ erpnext.SerialNoBatchSelector = class SerialNoBatchSelector { } on_close_dialog() { - this.dialog.get_close_btn().on('click', () => { + this.dialog.get_close_btn().on("click", () => { this.on_close && this.on_close(this.item); }); } validate() { let values = this.values; - if(!values.warehouse) { + if (!values.warehouse) { frappe.throw(__("Please select a warehouse")); return false; } - if(this.has_batch && !this.has_serial_no) { - if(values.batches.length === 0 || !values.batches) { + if (this.has_batch && !this.has_serial_no) { + if (values.batches.length === 0 || !values.batches) { frappe.throw(__("Please select batches for batched item {0}", [values.item_code])); } values.batches.map((batch, i) => { - if(!batch.selected_qty || batch.selected_qty === 0 ) { + if (!batch.selected_qty || batch.selected_qty === 0) { if (!this.show_dialog) { - frappe.throw(__("Please select quantity on row {0}", [i+1])); + frappe.throw(__("Please select quantity on row {0}", [i + 1])); } } }); return true; - } else { - let serial_nos = values.serial_no || ''; - if (!serial_nos || !serial_nos.replace(/\s/g, '').length) { + let serial_nos = values.serial_no || ""; + if (!serial_nos || !serial_nos.replace(/\s/g, "").length) { frappe.throw(__("Please enter serial numbers for serialized item {0}", [values.item_code])); } return true; @@ -226,87 +231,92 @@ erpnext.SerialNoBatchSelector = class SerialNoBatchSelector { update_batch_items() { // clones an items if muliple batches are selected. - if(this.has_batch && !this.has_serial_no) { + if (this.has_batch && !this.has_serial_no) { this.values.batches.map((batch, i) => { let batch_no = batch.batch_no; - let row = ''; + let row = ""; if (i !== 0 && !this.batch_exists(batch_no)) { row = this.frm.add_child("items", { ...this.item }); } else { - row = this.frm.doc.items.find(i => i.batch_no === batch_no); + row = this.frm.doc.items.find((i) => i.batch_no === batch_no); } if (!row) { row = this.item; } // this ensures that qty & batch no is set - this.map_row_values(row, batch, 'batch_no', - 'selected_qty', this.values.warehouse); + this.map_row_values(row, batch, "batch_no", "selected_qty", this.values.warehouse); }); } } update_serial_no_item() { // just updates serial no for the item - if(this.has_serial_no && !this.has_batch) { - this.map_row_values(this.item, this.values, 'serial_no', 'qty'); + if (this.has_serial_no && !this.has_batch) { + this.map_row_values(this.item, this.values, "serial_no", "qty"); } } update_batch_serial_no_items() { // if serial no selected is from different batches, adds new rows for each batch. - if(this.has_batch && this.has_serial_no) { - const selected_serial_nos = this.values.serial_no.split(/\n/g).filter(s => s); - - return frappe.db.get_list("Serial No", { - filters: { 'name': ["in", selected_serial_nos]}, - fields: ["batch_no", "name"] - }).then((data) => { - // data = [{batch_no: 'batch-1', name: "SR-001"}, - // {batch_no: 'batch-2', name: "SR-003"}, {batch_no: 'batch-2', name: "SR-004"}] - const batch_serial_map = data.reduce((acc, d) => { - if (!acc[d['batch_no']]) acc[d['batch_no']] = []; - acc[d['batch_no']].push(d['name']) - return acc - }, {}) - // batch_serial_map = { "batch-1": ['SR-001'], "batch-2": ["SR-003", "SR-004"]} - Object.keys(batch_serial_map).map((batch_no, i) => { - let row = ''; - const serial_no = batch_serial_map[batch_no]; - if (i == 0) { - row = this.item; - this.map_row_values(row, {qty: serial_no.length, batch_no: batch_no}, 'batch_no', - 'qty', this.values.warehouse); - } else if (!this.batch_exists(batch_no)) { - row = this.frm.add_child("items", { ...this.item }); - row.batch_no = batch_no; - } else { - row = this.frm.doc.items.find(i => i.batch_no === batch_no); - } - const values = { - 'qty': serial_no.length, - 'serial_no': serial_no.join('\n') - } - this.map_row_values(row, values, 'serial_no', - 'qty', this.values.warehouse); + if (this.has_batch && this.has_serial_no) { + const selected_serial_nos = this.values.serial_no.split(/\n/g).filter((s) => s); + + return frappe.db + .get_list("Serial No", { + filters: { name: ["in", selected_serial_nos] }, + fields: ["batch_no", "name"], + }) + .then((data) => { + // data = [{batch_no: 'batch-1', name: "SR-001"}, + // {batch_no: 'batch-2', name: "SR-003"}, {batch_no: 'batch-2', name: "SR-004"}] + const batch_serial_map = data.reduce((acc, d) => { + if (!acc[d["batch_no"]]) acc[d["batch_no"]] = []; + acc[d["batch_no"]].push(d["name"]); + return acc; + }, {}); + // batch_serial_map = { "batch-1": ['SR-001'], "batch-2": ["SR-003", "SR-004"]} + Object.keys(batch_serial_map).map((batch_no, i) => { + let row = ""; + const serial_no = batch_serial_map[batch_no]; + if (i == 0) { + row = this.item; + this.map_row_values( + row, + { qty: serial_no.length, batch_no: batch_no }, + "batch_no", + "qty", + this.values.warehouse + ); + } else if (!this.batch_exists(batch_no)) { + row = this.frm.add_child("items", { ...this.item }); + row.batch_no = batch_no; + } else { + row = this.frm.doc.items.find((i) => i.batch_no === batch_no); + } + const values = { + qty: serial_no.length, + serial_no: serial_no.join("\n"), + }; + this.map_row_values(row, values, "serial_no", "qty", this.values.warehouse); + }); }); - }) } } batch_exists(batch) { - const batches = this.frm.doc.items.map(data => data.batch_no); - return (batches && in_list(batches, batch)) ? true : false; + const batches = this.frm.doc.items.map((data) => data.batch_no); + return batches && in_list(batches, batch) ? true : false; } map_row_values(row, values, number, qty_field, warehouse) { row.qty = values[qty_field]; row.transfer_qty = flt(values[qty_field]) * flt(row.conversion_factor); row[number] = values[number]; - if(this.warehouse_details.type === 'Source Warehouse') { + if (this.warehouse_details.type === "Source Warehouse") { row.s_warehouse = values.warehouse || warehouse; - } else if(this.warehouse_details.type === 'Target Warehouse') { + } else if (this.warehouse_details.type === "Target Warehouse") { row.t_warehouse = values.warehouse || warehouse; } else { row.warehouse = values.warehouse || warehouse; @@ -319,7 +329,7 @@ erpnext.SerialNoBatchSelector = class SerialNoBatchSelector { let qty_field = this.dialog.fields_dict.qty; let total_qty = 0; - this.dialog.fields_dict.batches.df.data.forEach(data => { + this.dialog.fields_dict.batches.df.data.forEach((data) => { total_qty += flt(data.selected_qty); }); @@ -346,30 +356,35 @@ erpnext.SerialNoBatchSelector = class SerialNoBatchSelector { var me = this; return [ - {fieldtype:'Section Break', label: __('Batches')}, - {fieldname: 'batches', fieldtype: 'Table', label: __('Batch Entries'), + { fieldtype: "Section Break", label: __("Batches") }, + { + fieldname: "batches", + fieldtype: "Table", + label: __("Batch Entries"), fields: [ { - 'fieldtype': 'Link', - 'read_only': 0, - 'fieldname': 'batch_no', - 'options': 'Batch', - 'label': __('Select Batch'), - 'in_list_view': 1, + fieldtype: "Link", + read_only: 0, + fieldname: "batch_no", + options: "Batch", + label: __("Select Batch"), + in_list_view: 1, get_query: function () { return { filters: { item_code: me.item_code, - warehouse: me.warehouse || typeof me.warehouse_details.name == "string" ? me.warehouse_details.name : '' + warehouse: + me.warehouse || typeof me.warehouse_details.name == "string" + ? me.warehouse_details.name + : "", }, - query: 'erpnext.controllers.queries.get_batch_no' + query: "erpnext.controllers.queries.get_batch_no", }; }, change: function () { const batch_no = this.get_value(); if (!batch_no) { - this.grid_row.on_grid_fields_dict - .available_qty.set_value(0); + this.grid_row.on_grid_fields_dict.available_qty.set_value(0); return; } let selected_batches = this.grid.grid_rows.map((row) => { @@ -383,48 +398,48 @@ erpnext.SerialNoBatchSelector = class SerialNoBatchSelector { }); if (selected_batches.includes(batch_no)) { this.set_value(""); - frappe.throw(__('Batch {0} already selected.', [batch_no])); + frappe.throw(__("Batch {0} already selected.", [batch_no])); } if (me.warehouse_details.name) { frappe.call({ - method: 'erpnext.stock.doctype.batch.batch.get_batch_qty', + method: "erpnext.stock.doctype.batch.batch.get_batch_qty", args: { batch_no, warehouse: me.warehouse_details.name, - item_code: me.item_code + item_code: me.item_code, }, callback: (r) => { - this.grid_row.on_grid_fields_dict - .available_qty.set_value(r.message || 0); - } + this.grid_row.on_grid_fields_dict.available_qty.set_value( + r.message || 0 + ); + }, }); - } else { this.set_value(""); - frappe.throw(__('Please select a warehouse to get available quantities')); + frappe.throw(__("Please select a warehouse to get available quantities")); } // e.stopImmediatePropagation(); - } + }, }, { - 'fieldtype': 'Float', - 'read_only': 1, - 'fieldname': 'available_qty', - 'label': __('Available'), - 'in_list_view': 1, - 'default': 0, + fieldtype: "Float", + read_only: 1, + fieldname: "available_qty", + label: __("Available"), + in_list_view: 1, + default: 0, change: function () { - this.grid_row.on_grid_fields_dict.selected_qty.set_value('0'); - } + this.grid_row.on_grid_fields_dict.selected_qty.set_value("0"); + }, }, { - 'fieldtype': 'Float', - 'read_only': 0, - 'fieldname': 'selected_qty', - 'label': __('Qty'), - 'in_list_view': 1, - 'default': 0, + fieldtype: "Float", + read_only: 0, + fieldname: "selected_qty", + label: __("Qty"), + in_list_view: 1, + default: 0, change: function () { var batch_no = this.grid_row.on_grid_fields_dict.batch_no.get_value(); var available_qty = this.grid_row.on_grid_fields_dict.available_qty.get_value(); @@ -433,18 +448,23 @@ erpnext.SerialNoBatchSelector = class SerialNoBatchSelector { if (batch_no.length === 0 && parseInt(selected_qty) !== 0) { frappe.throw(__("Please select a batch")); } - if (me.warehouse_details.type === 'Source Warehouse' && - parseFloat(available_qty) < parseFloat(selected_qty)) { - - this.set_value('0'); - frappe.throw(__('For transfer from source, selected quantity cannot be greater than available quantity')); + if ( + me.warehouse_details.type === "Source Warehouse" && + parseFloat(available_qty) < parseFloat(selected_qty) + ) { + this.set_value("0"); + frappe.throw( + __( + "For transfer from source, selected quantity cannot be greater than available quantity" + ) + ); } else { this.grid.refresh(); } me.update_total_qty(); me.update_pending_qtys(); - } + }, }, ], in_place_edit: true, @@ -452,7 +472,7 @@ erpnext.SerialNoBatchSelector = class SerialNoBatchSelector { get_data: function () { return this.data; }, - } + }, ]; } @@ -462,43 +482,48 @@ erpnext.SerialNoBatchSelector = class SerialNoBatchSelector { let serial_no_filters = { item_code: me.item_code, - delivery_document_no: "" - } + delivery_document_no: "", + }; if (this.item.batch_no) { serial_no_filters["batch_no"] = this.item.batch_no; } if (me.warehouse_details.name) { - serial_no_filters['warehouse'] = me.warehouse_details.name; + serial_no_filters["warehouse"] = me.warehouse_details.name; } - if (me.frm.doc.doctype === 'POS Invoice' && !this.showing_reserved_serial_nos_error) { - frappe.call({ - method: "erpnext.stock.doctype.serial_no.serial_no.get_pos_reserved_serial_nos", - args: { - filters: { - item_code: me.item_code, - warehouse: typeof me.warehouse_details.name == "string" ? me.warehouse_details.name : '', - } - } - }).then((data) => { - serial_no_filters['name'] = ["not in", data.message[0]] - }) + if (me.frm.doc.doctype === "POS Invoice" && !this.showing_reserved_serial_nos_error) { + frappe + .call({ + method: "erpnext.stock.doctype.serial_no.serial_no.get_pos_reserved_serial_nos", + args: { + filters: { + item_code: me.item_code, + warehouse: + typeof me.warehouse_details.name == "string" ? me.warehouse_details.name : "", + }, + }, + }) + .then((data) => { + serial_no_filters["name"] = ["not in", data.message[0]]; + }); } return [ - {fieldtype: 'Section Break', label: __('Serial Numbers')}, + { fieldtype: "Section Break", label: __("Serial Numbers") }, { - fieldtype: 'Link', fieldname: 'serial_no_select', options: 'Serial No', - label: __('Select to add Serial Number.'), - get_query: function() { + fieldtype: "Link", + fieldname: "serial_no_select", + options: "Serial No", + label: __("Select to add Serial Number."), + get_query: function () { return { - filters: serial_no_filters + filters: serial_no_filters, }; }, - onchange: function(e) { - if(this.in_local_change) return; + onchange: function (e) { + if (this.in_local_change) return; this.in_local_change = 1; let serial_no_list_field = this.layout.fields_dict.serial_no; @@ -506,22 +531,22 @@ erpnext.SerialNoBatchSelector = class SerialNoBatchSelector { let new_number = this.get_value(); let list_value = serial_no_list_field.get_value(); - let new_line = '\n'; - if(!list_value) { - new_line = ''; + let new_line = "\n"; + if (!list_value) { + new_line = ""; } else { me.serial_list = list_value.split(/\n/g) || []; } - if(!me.serial_list.includes(new_number)) { - this.set_new_description(''); - serial_no_list_field.set_value(me.serial_list.join('\n') + new_line + new_number); + if (!me.serial_list.includes(new_number)) { + this.set_new_description(""); + serial_no_list_field.set_value(me.serial_list.join("\n") + new_line + new_number); me.serial_list = serial_no_list_field.get_value().split(/\n/g) || []; } else { - this.set_new_description(new_number + ' is already selected.'); + this.set_new_description(new_number + " is already selected."); } - me.serial_list = me.serial_list.filter(serial => { + me.serial_list = me.serial_list.filter((serial) => { if (serial) { return true; } @@ -530,61 +555,68 @@ erpnext.SerialNoBatchSelector = class SerialNoBatchSelector { qty_field.set_input(me.serial_list.length); this.$input.val(""); this.in_local_change = 0; - } + }, }, - {fieldtype: 'Section Break'}, + { fieldtype: "Section Break" }, { - fieldname: 'serial_no', - fieldtype: 'Text', - label: __(me.has_batch && !me.has_serial_no ? 'Selected Batch Numbers' : 'Selected Serial Numbers'), - onchange: function() { + fieldname: "serial_no", + fieldtype: "Text", + label: __( + me.has_batch && !me.has_serial_no ? "Selected Batch Numbers" : "Selected Serial Numbers" + ), + onchange: function () { me.serial_list = this.get_value().split(/\n/g); - me.serial_list = me.serial_list.filter(serial => { + me.serial_list = me.serial_list.filter((serial) => { if (serial) { return true; } }); this.layout.fields_dict.qty.set_input(me.serial_list.length); - } - } + }, + }, ]; } }; function get_pending_qty_fields(me) { if (!check_can_calculate_pending_qty(me)) return []; - const { frm: { doc: { fg_completed_qty }}, item: { item_code, stock_qty }} = me; + const { + frm: { + doc: { fg_completed_qty }, + }, + item: { item_code, stock_qty }, + } = me; const { qty_consumed_per_unit } = erpnext.stock.bom.items[item_code]; const total_selected_qty = calc_total_selected_qty(me); const required_qty = flt(fg_completed_qty) * flt(qty_consumed_per_unit); const pending_qty = required_qty - (flt(stock_qty) + total_selected_qty); - const pending_qty_fields = [ - { fieldtype: 'Section Break', label: __('Pending Quantity') }, + const pending_qty_fields = [ + { fieldtype: "Section Break", label: __("Pending Quantity") }, { - fieldname: 'required_qty', + fieldname: "required_qty", read_only: 1, - fieldtype: 'Float', - label: __('Required Qty'), - default: required_qty + fieldtype: "Float", + label: __("Required Qty"), + default: required_qty, }, - { fieldtype: 'Column Break' }, + { fieldtype: "Column Break" }, { - fieldname: 'total_selected_qty', + fieldname: "total_selected_qty", read_only: 1, - fieldtype: 'Float', - label: __('Total Selected Qty'), - default: total_selected_qty + fieldtype: "Float", + label: __("Total Selected Qty"), + default: total_selected_qty, }, - { fieldtype: 'Column Break' }, + { fieldtype: "Column Break" }, { - fieldname: 'pending_qty', + fieldname: "pending_qty", read_only: 1, - fieldtype: 'Float', - label: __('Pending Qty'), - default: pending_qty + fieldtype: "Float", + label: __("Pending Qty"), + default: pending_qty, }, ]; return pending_qty_fields; @@ -592,37 +624,45 @@ function get_pending_qty_fields(me) { // get all items with same item code except row for which selector is open. function get_rows_with_same_item_code(me) { - const { frm: { doc: { items }}, item: { name, item_code }} = me; - return items.filter(item => (item.name !== name) && (item.item_code === item_code)) + const { + frm: { + doc: { items }, + }, + item: { name, item_code }, + } = me; + return items.filter((item) => item.name !== name && item.item_code === item_code); } function calc_total_selected_qty(me) { const totalSelectedQty = get_rows_with_same_item_code(me) - .map(item => flt(item.qty)) + .map((item) => flt(item.qty)) .reduce((i, j) => i + j, 0); return totalSelectedQty; } function get_selected_serial_nos(me) { const selected_serial_nos = get_rows_with_same_item_code(me) - .map(item => item.serial_no) - .filter(serial => serial) - .map(sr_no_string => sr_no_string.split('\n')) + .map((item) => item.serial_no) + .filter((serial) => serial) + .map((sr_no_string) => sr_no_string.split("\n")) .reduce((acc, arr) => acc.concat(arr), []) - .filter(serial => serial); + .filter((serial) => serial); return selected_serial_nos; -}; +} function check_can_calculate_pending_qty(me) { - const { frm: { doc }, item } = me; - const docChecks = doc.bom_no - && doc.fg_completed_qty - && erpnext.stock.bom - && erpnext.stock.bom.name === doc.bom_no; - const itemChecks = !!item - && !item.original_item - && erpnext.stock.bom && erpnext.stock.bom.items - && (item.item_code in erpnext.stock.bom.items); + const { + frm: { doc }, + item, + } = me; + const docChecks = + doc.bom_no && doc.fg_completed_qty && erpnext.stock.bom && erpnext.stock.bom.name === doc.bom_no; + const itemChecks = + !!item && + !item.original_item && + erpnext.stock.bom && + erpnext.stock.bom.items && + item.item_code in erpnext.stock.bom.items; return docChecks && itemChecks; } diff --git a/erpnext/public/js/utils/supplier_quick_entry.js b/erpnext/public/js/utils/supplier_quick_entry.js index 687b01454a22..968ef74c3a05 100644 --- a/erpnext/public/js/utils/supplier_quick_entry.js +++ b/erpnext/public/js/utils/supplier_quick_entry.js @@ -1,3 +1,3 @@ -frappe.provide('frappe.ui.form'); +frappe.provide("frappe.ui.form"); frappe.ui.form.SupplierQuickEntryForm = frappe.ui.form.ContactAddressQuickEntryForm; diff --git a/erpnext/public/js/utils/unreconcile.js b/erpnext/public/js/utils/unreconcile.js index 79490a162d3f..6864e2865d3a 100644 --- a/erpnext/public/js/utils/unreconcile.js +++ b/erpnext/public/js/utils/unreconcile.js @@ -1,27 +1,34 @@ -frappe.provide('erpnext.accounts'); +frappe.provide("erpnext.accounts"); erpnext.accounts.unreconcile_payment = { add_unreconcile_btn(frm) { if (frm.doc.docstatus == 1) { - if(((frm.doc.doctype == "Journal Entry") && (frm.doc.voucher_type != "Journal Entry")) - || !["Purchase Invoice", "Sales Invoice", "Journal Entry", "Payment Entry"].includes(frm.doc.doctype) - ) { + if ( + (frm.doc.doctype == "Journal Entry" && frm.doc.voucher_type != "Journal Entry") || + !["Purchase Invoice", "Sales Invoice", "Journal Entry", "Payment Entry"].includes( + frm.doc.doctype + ) + ) { return; } frappe.call({ - "method": "erpnext.accounts.doctype.unreconcile_payment.unreconcile_payment.doc_has_references", - "args": { - "doctype": frm.doc.doctype, - "docname": frm.doc.name + method: "erpnext.accounts.doctype.unreconcile_payment.unreconcile_payment.doc_has_references", + args: { + doctype: frm.doc.doctype, + docname: frm.doc.name, }, - callback: function(r) { + callback: function (r) { if (r.message) { - frm.add_custom_button(__("UnReconcile"), function() { - erpnext.accounts.unreconcile_payment.build_unreconcile_dialog(frm); - }, __('Actions')); + frm.add_custom_button( + __("UnReconcile"), + function () { + erpnext.accounts.unreconcile_payment.build_unreconcile_dialog(frm); + }, + __("Actions") + ); } - } + }, }); } }, @@ -30,18 +37,18 @@ erpnext.accounts.unreconcile_payment = { // assuming each row is an individual voucher // pass this to server side method that creates unreconcile doc for each row let selection_map = []; - if (['Sales Invoice', 'Purchase Invoice'].includes(frm.doc.doctype)) { - selection_map = selections.map(function(elem) { + if (["Sales Invoice", "Purchase Invoice"].includes(frm.doc.doctype)) { + selection_map = selections.map(function (elem) { return { company: elem.company, voucher_type: elem.voucher_type, voucher_no: elem.voucher_no, against_voucher_type: frm.doc.doctype, - against_voucher_no: frm.doc.name + against_voucher_no: frm.doc.name, }; }); - } else if (['Payment Entry', 'Journal Entry'].includes(frm.doc.doctype)) { - selection_map = selections.map(function(elem) { + } else if (["Payment Entry", "Journal Entry"].includes(frm.doc.doctype)) { + selection_map = selections.map(function (elem) { return { company: elem.company, voucher_type: frm.doc.doctype, @@ -55,18 +62,41 @@ erpnext.accounts.unreconcile_payment = { }, build_unreconcile_dialog(frm) { - if (['Sales Invoice', 'Purchase Invoice', 'Payment Entry', 'Journal Entry'].includes(frm.doc.doctype)) { + if ( + ["Sales Invoice", "Purchase Invoice", "Payment Entry", "Journal Entry"].includes(frm.doc.doctype) + ) { let child_table_fields = [ - { label: __("Voucher Type"), fieldname: "voucher_type", fieldtype: "Dynamic Link", options: "DocType", in_list_view: 1, read_only: 1}, - { label: __("Voucher No"), fieldname: "voucher_no", fieldtype: "Link", options: "voucher_type", in_list_view: 1, read_only: 1 }, - { label: __("Allocated Amount"), fieldname: "allocated_amount", fieldtype: "Currency", in_list_view: 1, read_only: 1 , options: "account_currency"}, - { label: __("Currency"), fieldname: "account_currency", fieldtype: "Currency", read_only: 1}, - ] + { + label: __("Voucher Type"), + fieldname: "voucher_type", + fieldtype: "Dynamic Link", + options: "DocType", + in_list_view: 1, + read_only: 1, + }, + { + label: __("Voucher No"), + fieldname: "voucher_no", + fieldtype: "Link", + options: "voucher_type", + in_list_view: 1, + read_only: 1, + }, + { + label: __("Allocated Amount"), + fieldname: "allocated_amount", + fieldtype: "Currency", + in_list_view: 1, + read_only: 1, + options: "account_currency", + }, + { label: __("Currency"), fieldname: "account_currency", fieldtype: "Currency", read_only: 1 }, + ]; let unreconcile_dialog_fields = [ { - label: __('Allocations'), - fieldname: 'allocations', - fieldtype: 'Table', + label: __("Allocations"), + fieldname: "allocations", + fieldtype: "Table", read_only: 1, fields: child_table_fields, }, @@ -74,54 +104,57 @@ erpnext.accounts.unreconcile_payment = { // get linked payments frappe.call({ - "method": "erpnext.accounts.doctype.unreconcile_payment.unreconcile_payment.get_linked_payments_for_doc", - "args": { - "company": frm.doc.company, - "doctype": frm.doc.doctype, - "docname": frm.doc.name + method: "erpnext.accounts.doctype.unreconcile_payment.unreconcile_payment.get_linked_payments_for_doc", + args: { + company: frm.doc.company, + doctype: frm.doc.doctype, + docname: frm.doc.name, }, - callback: function(r) { + callback: function (r) { if (r.message) { // populate child table with allocations unreconcile_dialog_fields[0].data = r.message; - unreconcile_dialog_fields[0].get_data = function(){ return r.message}; + unreconcile_dialog_fields[0].get_data = function () { + return r.message; + }; let d = new frappe.ui.Dialog({ - title: 'UnReconcile Allocations', + title: "UnReconcile Allocations", fields: unreconcile_dialog_fields, - size: 'large', + size: "large", cannot_add_rows: true, - primary_action_label: 'UnReconcile', + primary_action_label: "UnReconcile", primary_action(values) { - - let selected_allocations = values.allocations.filter(x=>x.__checked); + let selected_allocations = values.allocations.filter((x) => x.__checked); if (selected_allocations.length > 0) { - let selection_map = erpnext.accounts.unreconcile_payment.build_selection_map(frm, selected_allocations); - erpnext.accounts.unreconcile_payment.create_unreconcile_docs(selection_map); + let selection_map = + erpnext.accounts.unreconcile_payment.build_selection_map( + frm, + selected_allocations + ); + erpnext.accounts.unreconcile_payment.create_unreconcile_docs( + selection_map + ); d.hide(); - } else { frappe.msgprint("No Selection"); } - } + }, }); d.show(); } - } + }, }); } }, create_unreconcile_docs(selection_map) { frappe.call({ - "method": "erpnext.accounts.doctype.unreconcile_payment.unreconcile_payment.create_unreconcile_doc_for_selection", - "args": { - "selections": selection_map + method: "erpnext.accounts.doctype.unreconcile_payment.unreconcile_payment.create_unreconcile_doc_for_selection", + args: { + selections: selection_map, }, }); - } - - - -} + }, +}; diff --git a/erpnext/public/js/website_theme.js b/erpnext/public/js/website_theme.js index 0009cacf61eb..9c2b8cd11b97 100644 --- a/erpnext/public/js/website_theme.js +++ b/erpnext/public/js/website_theme.js @@ -1,14 +1,15 @@ // Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and Contributors // MIT License. See license.txt -frappe.ui.form.on('Website Theme', { +frappe.ui.form.on("Website Theme", { validate(frm) { let theme_scss = frm.doc.theme_scss; - if (theme_scss && theme_scss.includes('frappe/public/scss/website') - && !theme_scss.includes('erpnext/public/scss/website') + if ( + theme_scss && + theme_scss.includes("frappe/public/scss/website") && + !theme_scss.includes("erpnext/public/scss/website") ) { - frm.set_value('theme_scss', - `${frm.doc.theme_scss}\n@import "erpnext/public/scss/website";`); + frm.set_value("theme_scss", `${frm.doc.theme_scss}\n@import "erpnext/public/scss/website";`); } - } + }, }); diff --git a/erpnext/public/js/website_utils.js b/erpnext/public/js/website_utils.js index b5416065d791..f196d7c7adea 100644 --- a/erpnext/public/js/website_utils.js +++ b/erpnext/public/js/website_utils.js @@ -1,29 +1,29 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -if(!window.erpnext) window.erpnext = {}; +if (!window.erpnext) window.erpnext = {}; // Add / update a new Lead / Communication // subject, sender, description -frappe.send_message = function(opts, btn) { +frappe.send_message = function (opts, btn) { return frappe.call({ type: "POST", method: "erpnext.templates.utils.send_message", btn: btn, args: opts, - callback: opts.callback + callback: opts.callback, }); }; -erpnext.subscribe_to_newsletter = function(opts, btn) { +erpnext.subscribe_to_newsletter = function (opts, btn) { return frappe.call({ type: "POST", method: "frappe.email.doctype.newsletter.newsletter.subscribe", btn: btn, - args: {"email": opts.email}, - callback: opts.callback + args: { email: opts.email }, + callback: opts.callback, }); -} +}; // for backward compatibility erpnext.send_message = frappe.send_message; diff --git a/erpnext/public/js/wishlist.js b/erpnext/public/js/wishlist.js index f6599e9f6d1a..04e28bf75faa 100644 --- a/erpnext/public/js/wishlist.js +++ b/erpnext/public/js/wishlist.js @@ -5,18 +5,18 @@ frappe.provide("erpnext.e_commerce.shopping_cart"); var shopping_cart = erpnext.e_commerce.shopping_cart; $.extend(wishlist, { - set_wishlist_count: function(animate=false) { + set_wishlist_count: function (animate = false) { // set badge count for wishlist icon var wish_count = frappe.get_cookie("wish_count"); - if (frappe.session.user==="Guest") { + if (frappe.session.user === "Guest") { wish_count = 0; } if (wish_count) { - $(".wishlist").toggleClass('hidden', false); + $(".wishlist").toggleClass("hidden", false); } - var $wishlist = $('.wishlist-icon'); + var $wishlist = $(".wishlist-icon"); var $badge = $wishlist.find("#wish-count"); if (parseInt(wish_count) === 0 || wish_count === undefined) { @@ -27,9 +27,9 @@ $.extend(wishlist, { if (wish_count) { $badge.html(wish_count); if (animate) { - $wishlist.addClass('cart-animate'); + $wishlist.addClass("cart-animate"); setTimeout(() => { - $wishlist.removeClass('cart-animate'); + $wishlist.removeClass("cart-animate"); }, 500); } } else { @@ -37,19 +37,19 @@ $.extend(wishlist, { } }, - bind_move_to_cart_action: function() { + bind_move_to_cart_action: function () { // move item to cart from wishlist - $('.page_content').on("click", ".btn-add-to-cart", (e) => { + $(".page_content").on("click", ".btn-add-to-cart", (e) => { const $move_to_cart_btn = $(e.currentTarget); let item_code = $move_to_cart_btn.data("item-code"); shopping_cart.shopping_cart_update({ item_code, qty: 1, - cart_dropdown: true + cart_dropdown: true, }); - let success_action = function() { + let success_action = function () { const $card_wrapper = $move_to_cart_btn.closest(".wishlist-card"); $card_wrapper.addClass("wish-removed"); }; @@ -58,15 +58,15 @@ $.extend(wishlist, { }); }, - bind_remove_action: function() { + bind_remove_action: function () { // remove item from wishlist let me = this; - $('.page_content').on("click", ".remove-wish", (e) => { + $(".page_content").on("click", ".remove-wish", (e) => { const $remove_wish_btn = $(e.currentTarget); let item_code = $remove_wish_btn.data("item-code"); - let success_action = function() { + let success_action = function () { const $card_wrapper = $remove_wish_btn.closest(".wishlist-card"); $card_wrapper.addClass("wish-removed"); if (frappe.get_cookie("wish_count") == 0) { @@ -81,17 +81,17 @@ $.extend(wishlist, { bind_wishlist_action() { // 'wish'('like') or 'unwish' item in product listing - $('.page_content').on('click', '.like-action, .like-action-list', (e) => { + $(".page_content").on("click", ".like-action, .like-action-list", (e) => { const $btn = $(e.currentTarget); this.wishlist_action($btn); }); }, wishlist_action(btn) { - const $wish_icon = btn.find('.wish-icon'); + const $wish_icon = btn.find(".wish-icon"); let me = this; - if (frappe.session.user==="Guest") { + if (frappe.session.user === "Guest") { if (localStorage) { localStorage.setItem("last_visited", window.location.pathname); } @@ -99,30 +99,30 @@ $.extend(wishlist, { return; } - let success_action = function() { + let success_action = function () { erpnext.e_commerce.wishlist.set_wishlist_count(true); }; - if ($wish_icon.hasClass('wished')) { + if ($wish_icon.hasClass("wished")) { // un-wish item btn.removeClass("like-animate"); btn.addClass("like-action-wished"); - this.toggle_button_class($wish_icon, 'wished', 'not-wished'); + this.toggle_button_class($wish_icon, "wished", "not-wished"); - let args = { item_code: btn.data('item-code') }; - let failure_action = function() { - me.toggle_button_class($wish_icon, 'not-wished', 'wished'); + let args = { item_code: btn.data("item-code") }; + let failure_action = function () { + me.toggle_button_class($wish_icon, "not-wished", "wished"); }; this.add_remove_from_wishlist("remove", args, success_action, failure_action); } else { // wish item btn.addClass("like-animate"); btn.addClass("like-action-wished"); - this.toggle_button_class($wish_icon, 'not-wished', 'wished'); + this.toggle_button_class($wish_icon, "not-wished", "wished"); - let args = {item_code: btn.data('item-code')}; - let failure_action = function() { - me.toggle_button_class($wish_icon, 'wished', 'not-wished'); + let args = { item_code: btn.data("item-code") }; + let failure_action = function () { + me.toggle_button_class($wish_icon, "wished", "not-wished"); }; this.add_remove_from_wishlist("add", args, success_action, failure_action); } @@ -133,14 +133,14 @@ $.extend(wishlist, { button.addClass(add); }, - add_remove_from_wishlist(action, args, success_action, failure_action, async=false) { + add_remove_from_wishlist(action, args, success_action, failure_action, async = false) { /* AJAX call to add or remove Item from Wishlist action: "add" or "remove" args: args for method (item_code, price, formatted_price), success_action: method to execute on successs, failure_action: method to execute on failure, async: make call asynchronously (true/false). */ - if (frappe.session.user==="Guest") { + if (frappe.session.user === "Guest") { if (localStorage) { localStorage.setItem("last_visited", window.location.pathname); } @@ -158,23 +158,24 @@ $.extend(wishlist, { args: args, callback: function (r) { if (r.exc) { - if (failure_action && (typeof failure_action === 'function')) { + if (failure_action && typeof failure_action === "function") { failure_action(); } frappe.msgprint({ message: __("Sorry, something went wrong. Please refresh."), - indicator: "red", title: __("Note") + indicator: "red", + title: __("Note"), }); - } else if (success_action && (typeof success_action === 'function')) { + } else if (success_action && typeof success_action === "function") { success_action(); } - } + }, }); } }, redirect_guest() { - frappe.call('erpnext.e_commerce.api.get_guest_redirect_on_action').then((res) => { + frappe.call("erpnext.e_commerce.api.get_guest_redirect_on_action").then((res) => { window.location.href = res.message || "/login"; }); }, @@ -185,20 +186,18 @@ $.extend(wishlist, {
              Empty Cart
              -
              ${ __('Wishlist is empty !') }

              +
              ${__("Wishlist is empty !")}

              `); - } - + }, }); -frappe.ready(function() { +frappe.ready(function () { if (window.location.pathname !== "/wishlist") { - $(".wishlist").toggleClass('hidden', true); + $(".wishlist").toggleClass("hidden", true); wishlist.set_wishlist_count(); } else { wishlist.bind_move_to_cart_action(); wishlist.bind_remove_action(); } - -}); \ No newline at end of file +}); diff --git a/erpnext/public/scss/erpnext.scss b/erpnext/public/scss/erpnext.scss index 8ab5973debdb..6da8f24cf9b6 100644 --- a/erpnext/public/scss/erpnext.scss +++ b/erpnext/public/scss/erpnext.scss @@ -51,7 +51,7 @@ } // assessment tool -.frappe-control[data-fieldname='result_html'] { +.frappe-control[data-fieldname="result_html"] { overflow: scroll; } .assessment-result-tool { @@ -70,7 +70,9 @@ text-overflow: ellipsis; } - .total-score, .grade, .score { + .total-score, + .grade, + .score { text-align: right; } } @@ -78,13 +80,13 @@ /* pos */ body[data-route="pos"] { - .pos-bill-toolbar { padding: 10px 0px; height: 51px; } - .pos-bill-item:hover, .list-customers-table > .pos-list-row:hover { + .pos-bill-item:hover, + .list-customers-table > .pos-list-row:hover { background-color: #f5f7fa; cursor: pointer; } @@ -135,50 +137,52 @@ body[data-route="pos"] { } .pos-payment-row .col-xs-6 { - padding :15px; + padding: 15px; } .pos-payment-row { - border-bottom:1px solid var(--border-color); + border-bottom: 1px solid var(--border-color); margin: 2px 0px 5px 0px; height: 60px; margin-top: 0px; margin-bottom: 0px; } - .pos-payment-row:hover, .pos-keyboard-key:hover{ + .pos-payment-row:hover, + .pos-keyboard-key:hover { background-color: var(--bg-color); cursor: pointer; } - .pos-keyboard-key, .delete-btn { + .pos-keyboard-key, + .delete-btn { border: 1px solid var(--border-color); - height:85px; - width:85px; - margin:10px 10px; - font-size:24px; - font-weight:200; - background-color: #FDFDFD; + height: 85px; + width: 85px; + margin: 10px 10px; + font-size: 24px; + font-weight: 200; + background-color: #fdfdfd; border-color: #e8e8e8; } .numeric-keypad { border: 1px solid var(--border-color); - height:69px; - width:69px; - font-size:20px; - font-weight:200; - background-color: #FDFDFD; + height: 69px; + width: 69px; + font-size: 20px; + font-weight: 200; + background-color: #fdfdfd; border-color: #e8e8e8; - margin-left:-4px; + margin-left: -4px; } .pos-pay { - height:69px; - width:69px; - font-size:17px; - font-weight:200; - margin-left:-4px; + height: 69px; + width: 69px; + font-size: 17px; + font-weight: 200; + margin-left: -4px; } .numeric-keypad { @@ -188,7 +192,7 @@ body[data-route="pos"] { font-weight: 200; border-radius: 0; background-color: #fff; - margin-left:-4px; + margin-left: -4px; @media (max-width: var(--xl-width)) { height: 45px; @@ -253,7 +257,8 @@ body[data-route="pos"] { .amount-row h3 { font-size: 15px; } - .pos-keyboard-key, .delete-btn { + .pos-keyboard-key, + .delete-btn { height: 50px; } .multimode-payments { @@ -277,7 +282,8 @@ body[data-route="pos"] { padding: 15px 10px; } - .write_off_amount, .change_amount { + .write_off_amount, + .change_amount { margin: 15px; width: 130px; } @@ -301,10 +307,11 @@ body[data-route="pos"] { } .subject { - width: 40% + width: 40%; } - .list-row-checkbox, .list-select-all { + .list-row-checkbox, + .list-select-all { margin-right: 7px; } } @@ -397,7 +404,7 @@ body[data-route="pos"] { padding-top: 0; } - &> .pos-list-row { + & > .pos-list-row { border: none; @media (max-width: var(--xl-width)) { @@ -442,13 +449,12 @@ body[data-route="pos"] { padding: 5px 9px; border-radius: 3px; color: #fff; - } // Healthcare .exercise-card { - box-shadow: 0 1px 3px rgba(0,0,0,0.30); + box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); border-radius: 2px; padding: 6px 6px 6px 8px; margin-top: 10px; diff --git a/erpnext/public/scss/hierarchy_chart.scss b/erpnext/public/scss/hierarchy_chart.scss index 57d5e8414ae7..834d5ccb194f 100644 --- a/erpnext/public/scss/hierarchy_chart.scss +++ b/erpnext/public/scss/hierarchy_chart.scss @@ -22,12 +22,12 @@ } .node-card.exported { - box-shadow: none + box-shadow: none; } .node-image { - width: 3.0rem; - height: 3.0rem; + width: 3rem; + height: 3rem; } .node-name { @@ -61,8 +61,8 @@ display: flex; background: var(--blue-100); color: var(--blue-500); - padding: .25rem .5rem; - font-size: .75rem; + padding: 0.25rem 0.5rem; + font-size: 0.75rem; justify-content: center; box-shadow: var(--shadow-sm); margin-left: auto; @@ -77,7 +77,7 @@ display: block; } - .node-edit-icon > .icon{ + .node-edit-icon > .icon { stroke: var(--blue-500); } @@ -96,7 +96,7 @@ border-radius: 0.5rem; padding: 0.75rem; width: 15rem; - height: 3.0rem; + height: 3rem; .btn-edit-node { display: none !important; @@ -144,7 +144,7 @@ border-radius: 0.5rem; padding: 0.75rem; width: 15rem; - height: 3.0rem; + height: 3rem; .btn-edit-node { display: none !important; @@ -206,7 +206,8 @@ margin: 0px 0px 16px 0px; } -.hierarchy, .hierarchy-mobile { +.hierarchy, +.hierarchy-mobile { .level { margin-right: 8px; align-items: flex-start; diff --git a/erpnext/public/scss/order-page.scss b/erpnext/public/scss/order-page.scss index 6f5fe5d4d7a9..2b1dae282a32 100644 --- a/erpnext/public/scss/order-page.scss +++ b/erpnext/public/scss/order-page.scss @@ -1,115 +1,113 @@ #page-order { - .main-column { - .page-content-wrapper { - - .breadcrumb-container { - @media screen and (min-width: 567px) { - padding-left: var(--padding-sm); - } - } - - .container.my-4 { - background-color: var(--fg-color); - - @media screen and (min-width: 567px) { - padding: 1.25rem 1.5rem; - border-radius: var(--border-radius-md); - box-shadow: var(--card-shadow); - } - } - } - } + .main-column { + .page-content-wrapper { + .breadcrumb-container { + @media screen and (min-width: 567px) { + padding-left: var(--padding-sm); + } + } + + .container.my-4 { + background-color: var(--fg-color); + + @media screen and (min-width: 567px) { + padding: 1.25rem 1.5rem; + border-radius: var(--border-radius-md); + box-shadow: var(--card-shadow); + } + } + } + } } .indicator-container { - @media screen and (max-width: 567px) { - padding-bottom: 0.8rem; - } + @media screen and (max-width: 567px) { + padding-bottom: 0.8rem; + } } .order-items { - padding: 1.5rem 0; - border-bottom: 1px solid var(--border-color); - color: var(--gray-700); - - @media screen and (max-width: 567px) { - align-items: flex-start !important; - } - .col-2 { - @media screen and (max-width: 567px) { - flex: auto; - max-width: 28%; - } - } - - .order-item-name { - font-size: var(--text-base); - font-weight: 500; - } - - .btn:focus, - .btn:hover { - background-color: var(--control-bg); - } - - - .col-6 { - @media screen and (max-width: 567px) { - max-width: 100%; - } - - &.order-item-name { - font-size: var(--text-base); - } - } + padding: 1.5rem 0; + border-bottom: 1px solid var(--border-color); + color: var(--gray-700); + + @media screen and (max-width: 567px) { + align-items: flex-start !important; + } + .col-2 { + @media screen and (max-width: 567px) { + flex: auto; + max-width: 28%; + } + } + + .order-item-name { + font-size: var(--text-base); + font-weight: 500; + } + + .btn:focus, + .btn:hover { + background-color: var(--control-bg); + } + + .col-6 { + @media screen and (max-width: 567px) { + max-width: 100%; + } + + &.order-item-name { + font-size: var(--text-base); + } + } } .item-grand-total { - font-size: var(--text-base); + font-size: var(--text-base); } .list-item-name, .item-total, .order-container, .order-qty { - font-size: var(--text-md); + font-size: var(--text-md); } .d-s-n { - @media screen and (max-width: 567px) { - display: none; - } + @media screen and (max-width: 567px) { + display: none; + } } .d-l-n { - @media screen and (min-width: 567px) { - display: none; - } + @media screen and (min-width: 567px) { + display: none; + } } .border-btm { - border-bottom: 1px solid var(--border-color); + border-bottom: 1px solid var(--border-color); } .order-taxes { - display: flex; - - @media screen and (min-width: 567px) { - justify-content: flex-end; - } - - .col-4 { - padding-right: 0; - - .col-8 { - padding-left: 0; - padding-right: 0; - } - - @media screen and (max-width: 567px) { - padding-left: 0; - flex: auto; - max-width: 100%; - } - } -} \ No newline at end of file + display: flex; + + @media screen and (min-width: 567px) { + justify-content: flex-end; + } + + .col-4 { + padding-right: 0; + + .col-8 { + padding-left: 0; + padding-right: 0; + } + + @media screen and (max-width: 567px) { + padding-left: 0; + flex: auto; + max-width: 100%; + } + } +} diff --git a/erpnext/public/scss/point-of-sale.scss b/erpnext/public/scss/point-of-sale.scss index 7b7530b1501b..f50e2a52117d 100644 --- a/erpnext/public/scss/point-of-sale.scss +++ b/erpnext/public/scss/point-of-sale.scss @@ -185,7 +185,6 @@ font-weight: 700; } } - } } } @@ -262,12 +261,12 @@ flex-direction: column; margin-right: auto; - >.customer-name { + > .customer-name { font-weight: 700; font-size: var(--text-lg); } - >.customer-desc { + > .customer-desc { color: var(--gray-600); font-weight: 500; font-size: var(--text-sm); @@ -279,7 +278,6 @@ align-items: center; cursor: pointer; } - } > .customer-fields-container { @@ -408,7 +406,6 @@ font-size: var(--text-lg); } - > .item-name-desc { @extend .nowrap; display: flex; @@ -456,7 +453,6 @@ } } } - } } @@ -855,7 +851,7 @@ display: flex; flex: 1; height: 100%; - position: relative; + position: relative; justify-content: flex-end; > .fields-section { @@ -1136,7 +1132,6 @@ } } - > .summary-btns { display: flex; justify-content: space-between; @@ -1148,7 +1143,7 @@ > .new-btn { background-color: var(--blue-500); - color:white; + color: white; font-weight: 500; } } diff --git a/erpnext/public/scss/shopping_cart.scss b/erpnext/public/scss/shopping_cart.scss index 6ae464d2c21e..35c1fb64e366 100644 --- a/erpnext/public/scss/shopping_cart.scss +++ b/erpnext/public/scss/shopping_cart.scss @@ -1,9 +1,9 @@ @import "frappe/public/scss/common/mixins"; :root { - --green-info: #38A160; + --green-info: #38a160; --product-bg-color: white; - --body-bg-color: var(--gray-50); + --body-bg-color: var(--gray-50); } body.product-page { @@ -96,7 +96,8 @@ body.product-page { } } - .card:hover, .card:focus-within { + .card:hover, + .card:focus-within { .btn-add-to-cart-list { visibility: visible; } @@ -108,7 +109,6 @@ body.product-page { } } - .card-img-container { height: 210px; width: 100%; @@ -205,7 +205,8 @@ body.product-page { } } -#products-list-area, #products-grid-area { +#products-list-area, +#products-grid-area { padding: 0 5px; } @@ -216,7 +217,8 @@ body.product-page { border-radius: 8px; border-bottom: 1px solid var(--gray-50); - &:hover, &:focus-within { + &:hover, + &:focus-within { box-shadow: 0px 16px 60px rgba(0, 0, 0, 0.08), 0px 8px 30px -20px rgba(0, 0, 0, 0.04); transition: box-shadow 400ms; @@ -347,13 +349,13 @@ body.product-page { .btn-add-to-wishlist { svg use { - --icon-stroke: #F47A7A; + --icon-stroke: #f47a7a; } } .btn-view-in-wishlist { svg use { - fill: #F47A7A; + fill: #f47a7a; --icon-stroke: none; } } @@ -384,13 +386,12 @@ body.product-page { width: 350px; } - img { + img { object-fit: contain; } } .item-slideshow { - @media (max-width: var(--md-width)) { max-height: 320px; } @@ -411,7 +412,8 @@ body.product-page { border-radius: 4px; cursor: pointer; - &:hover, &.active { + &:hover, + &.active { border-color: var(--primary); } } @@ -460,11 +462,11 @@ body.product-page { .recommendation-header { font-size: 16px; - font-weight: 500 + font-weight: 500; } .recommendation-container { - padding: .5rem; + padding: 0.5rem; min-height: 0px; .r-item-image { @@ -476,11 +478,12 @@ body.product-page { } .no-image-r-item { - display: flex; justify-content: center; + display: flex; + justify-content: center; background-color: var(--gray-200); align-items: center; color: var(--gray-400); - margin-top: .15rem; + margin-top: 0.15rem; border-radius: 6px; height: 100%; font-size: 24px; @@ -513,16 +516,16 @@ body.product-page { } .product-code { - padding: .5rem 0; + padding: 0.5rem 0; color: var(--text-muted); font-size: 14px; .product-item-group { - padding-right: .25rem; + padding-right: 0.25rem; border-right: solid 1px var(--text-muted); } .product-item-code { - padding-left: .5rem; + padding-left: 0.5rem; } } @@ -561,14 +564,13 @@ body.product-page { } .item-group-slideshow { - .carousel-inner.rounded-carousel { border-radius: var(--card-border-radius); } } .sub-category-container { - padding-bottom: .5rem; + padding-bottom: 0.5rem; margin-bottom: 1.25rem; border-bottom: 1px solid var(--table-border-color); @@ -590,7 +592,6 @@ body.product-page { } } - .shopping-badge { position: relative; top: -10px; @@ -602,7 +603,6 @@ body.product-page { border-radius: 50%; } - .cart-animate { animation: wiggle 0.5s linear; } @@ -656,7 +656,9 @@ body.product-page { margin-bottom: 1rem; } - th, tr, td { + th, + tr, + td { border-color: var(--border-color); border-width: 1px; } @@ -725,7 +727,6 @@ body.product-page { height: 60px; font-size: 14px; } - } .cart-tax-items { @@ -759,7 +760,7 @@ body.product-page { background-color: var(--gray-100); float: right; cursor: pointer; - margin-top: .25rem; + margin-top: 0.25rem; justify-content: center; } @@ -859,11 +860,12 @@ body.product-page { .no-image-cart-item { max-height: 112px; - display: flex; justify-content: center; + display: flex; + justify-content: center; background-color: var(--gray-200); align-items: center; color: var(--gray-400); - margin-top: .15rem; + margin-top: 0.15rem; border-radius: 6px; height: 100%; font-size: 24px; @@ -911,7 +913,8 @@ body.product-page { } .address-header { - margin-top: .15rem;padding: 0; + margin-top: 0.15rem; + padding: 0; } .btn-new-address { @@ -920,7 +923,8 @@ body.product-page { color: var(--primary-color) !important; } -.btn-new-address:hover, .btn-change-address:hover { +.btn-new-address:hover, +.btn-change-address:hover { color: var(--primary-color) !important; } @@ -952,7 +956,6 @@ body.product-page { } } - .like-action { visibility: hidden; text-align: center; @@ -1013,31 +1016,31 @@ body.product-page { @keyframes expand { 30% { - transform: scale(1.3); + transform: scale(1.3); } 50% { - transform: scale(0.8); + transform: scale(0.8); } 70% { transform: scale(1.1); } 100% { - transform: scale(1); + transform: scale(1); } - } +} .not-wished { cursor: pointer; - --icon-stroke: #F47A7A !important; + --icon-stroke: #f47a7a !important; &:hover { - fill: #F47A7A; + fill: #f47a7a; } } .wished { --icon-stroke: none; - fill: #F47A7A !important; + fill: #f47a7a !important; } .list-row-checkbox { @@ -1052,7 +1055,7 @@ body.product-page { } #pay-for-order { - padding: .5rem 1rem; // Pay button in SO + padding: 0.5rem 1rem; // Pay button in SO } .btn-explore-variants { @@ -1074,7 +1077,7 @@ body.product-page { } } -.btn-add-to-cart-list{ +.btn-add-to-cart-list { visibility: hidden; box-shadow: none; margin: var(--margin-sm) 0; @@ -1108,7 +1111,7 @@ body.product-page { background-color: white; position: absolute; cursor: pointer; - top:10px; + top: 10px; right: 20px; width: 32px; height: 32px; @@ -1123,7 +1126,7 @@ body.product-page { } .item-website-specification { - font-size: .875rem; + font-size: 0.875rem; .product-title { font-size: 18px; } @@ -1150,8 +1153,8 @@ body.product-page { } .ratings-reviews-section { - border-top: 1px solid #E2E6E9; - padding: .5rem 1rem; + border-top: 1px solid #e2e6e9; + padding: 0.5rem 1rem; } .reviews-header { @@ -1165,7 +1168,7 @@ body.product-page { .btn-write-review { float: right; - padding: .5rem 1rem; + padding: 0.5rem 1rem; font-size: 14px; font-weight: 400; border: none !important; @@ -1218,7 +1221,7 @@ body.product-page { .ratings-pill { background-color: var(--gray-100); - padding: .5rem 1rem; + padding: 0.5rem 1rem; border-radius: 66px; } @@ -1226,7 +1229,7 @@ body.product-page { max-width: 80%; line-height: 1.6; padding-bottom: 0.5rem; - border-bottom: 1px solid #E2E6E9; + border-bottom: 1px solid #e2e6e9; } .review-signature { @@ -1266,7 +1269,7 @@ body.product-page { #search-results-container { border: 1px solid var(--gray-200); - padding: .25rem 1rem; + padding: 0.25rem 1rem; .category-chip { background-color: var(--gray-100); @@ -1275,7 +1278,7 @@ body.product-page { } .recent-search { - padding: .5rem .5rem; + padding: 0.5rem 0.5rem; border-radius: var(--border-radius); &:hover { @@ -1313,11 +1316,11 @@ body.product-page { } .placeholder-div { - height:80%; + height: 80%; width: -webkit-fill-available; padding: 50px; text-align: center; - background-color: #F9FAFA; + background-color: #f9fafa; border-top-left-radius: calc(0.75rem - 1px); border-top-right-radius: calc(0.75rem - 1px); } @@ -1342,7 +1345,8 @@ body.product-page { color: gray; } -.btn-next, .btn-prev { +.btn-next, +.btn-prev { font-size: 14px; } @@ -1369,7 +1373,7 @@ body.product-page { font-weight: 400; font-size: 14px; line-height: 20px; - color: #F47A7A; + color: #f47a7a; } .mt-minus-2 { @@ -1378,4 +1382,4 @@ body.product-page { .mt-minus-1 { margin-top: -1rem; -} \ No newline at end of file +} diff --git a/erpnext/public/scss/website.scss b/erpnext/public/scss/website.scss index b5e97f1c34b8..dd2ae210c769 100644 --- a/erpnext/public/scss/website.scss +++ b/erpnext/public/scss/website.scss @@ -1,4 +1,4 @@ -@import './order-page'; +@import "./order-page"; .filter-options { max-height: 300px; @@ -52,7 +52,8 @@ border-bottom: 1px solid var(--border-color); position: relative; - &:only-child, &:last-child { + &:only-child, + &:last-child { border: 0; } @@ -80,7 +81,8 @@ } } -.list-item-name, .item-total { +.list-item-name, +.item-total { font-size: var(--font-size-sm); } @@ -88,4 +90,4 @@ @media screen and (max-width: 567px) { margin-top: 1rem; } -} \ No newline at end of file +} diff --git a/erpnext/quality_management/doctype/non_conformance/non_conformance.js b/erpnext/quality_management/doctype/non_conformance/non_conformance.js index e7f5eee623e4..5524d7472b20 100644 --- a/erpnext/quality_management/doctype/non_conformance/non_conformance.js +++ b/erpnext/quality_management/doctype/non_conformance/non_conformance.js @@ -1,8 +1,7 @@ // Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Non Conformance', { +frappe.ui.form.on("Non Conformance", { // refresh: function(frm) { - // } }); diff --git a/erpnext/quality_management/doctype/quality_action/quality_action.js b/erpnext/quality_management/doctype/quality_action/quality_action.js index b44f2a203440..8261fab1ab51 100644 --- a/erpnext/quality_management/doctype/quality_action/quality_action.js +++ b/erpnext/quality_management/doctype/quality_action/quality_action.js @@ -1,6 +1,4 @@ // Copyright (c) 2018, Frappe and contributors // For license information, please see license.txt -frappe.ui.form.on('Quality Action', { - -}); +frappe.ui.form.on("Quality Action", {}); diff --git a/erpnext/quality_management/doctype/quality_feedback/quality_feedback.js b/erpnext/quality_management/doctype/quality_feedback/quality_feedback.js index 6fb326776ed7..8166c257d46c 100644 --- a/erpnext/quality_management/doctype/quality_feedback/quality_feedback.js +++ b/erpnext/quality_management/doctype/quality_feedback/quality_feedback.js @@ -1,10 +1,10 @@ // Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Quality Feedback', { - template: function(frm) { +frappe.ui.form.on("Quality Feedback", { + template: function (frm) { if (frm.doc.template) { - frm.call('set_parameters'); + frm.call("set_parameters"); } - } + }, }); diff --git a/erpnext/quality_management/doctype/quality_feedback_template/quality_feedback_template.js b/erpnext/quality_management/doctype/quality_feedback_template/quality_feedback_template.js index 490eed970659..054572a80ebc 100644 --- a/erpnext/quality_management/doctype/quality_feedback_template/quality_feedback_template.js +++ b/erpnext/quality_management/doctype/quality_feedback_template/quality_feedback_template.js @@ -1,8 +1,7 @@ // Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Quality Feedback Template', { +frappe.ui.form.on("Quality Feedback Template", { // refresh: function(frm) { - // } }); diff --git a/erpnext/quality_management/doctype/quality_goal/quality_goal.js b/erpnext/quality_management/doctype/quality_goal/quality_goal.js index 40cb4d924649..5b7cae5d22a2 100644 --- a/erpnext/quality_management/doctype/quality_goal/quality_goal.js +++ b/erpnext/quality_management/doctype/quality_goal/quality_goal.js @@ -1,7 +1,7 @@ // Copyright (c) 2018, Frappe and contributors // For license information, please see license.txt -frappe.ui.form.on('Quality Goal', { +frappe.ui.form.on("Quality Goal", { // refresh: function(frm) { // } }); diff --git a/erpnext/quality_management/doctype/quality_meeting/quality_meeting.js b/erpnext/quality_management/doctype/quality_meeting/quality_meeting.js index eb7a8c32d73c..00ab1e4c37a6 100644 --- a/erpnext/quality_management/doctype/quality_meeting/quality_meeting.js +++ b/erpnext/quality_management/doctype/quality_meeting/quality_meeting.js @@ -1,6 +1,4 @@ // Copyright (c) 2018, Frappe and contributors // For license information, please see license.txt -frappe.ui.form.on('Quality Meeting', { - -}); +frappe.ui.form.on("Quality Meeting", {}); diff --git a/erpnext/quality_management/doctype/quality_meeting/quality_meeting_list.js b/erpnext/quality_management/doctype/quality_meeting/quality_meeting_list.js index 5fd1b30eb452..ae3112f3d09e 100644 --- a/erpnext/quality_management/doctype/quality_meeting/quality_meeting_list.js +++ b/erpnext/quality_management/doctype/quality_meeting/quality_meeting_list.js @@ -1,11 +1,10 @@ -frappe.listview_settings['Quality Meeting'] = { +frappe.listview_settings["Quality Meeting"] = { add_fields: ["status"], - get_indicator: function(doc) { - if(doc.status == "Open") { + get_indicator: function (doc) { + if (doc.status == "Open") { return [__("Open"), "red", "status=,Open"]; - } - else if(doc.status == "Close") { + } else if (doc.status == "Close") { return [__("Close"), "green", ",status=,Close"]; } - } + }, }; diff --git a/erpnext/quality_management/doctype/quality_meeting_agenda/quality_meeting_agenda.js b/erpnext/quality_management/doctype/quality_meeting_agenda/quality_meeting_agenda.js index 09989dc643fc..ad037c256514 100644 --- a/erpnext/quality_management/doctype/quality_meeting_agenda/quality_meeting_agenda.js +++ b/erpnext/quality_management/doctype/quality_meeting_agenda/quality_meeting_agenda.js @@ -1,8 +1,7 @@ // Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Quality Meeting Agenda', { +frappe.ui.form.on("Quality Meeting Agenda", { // refresh: function(frm) { - // } }); diff --git a/erpnext/quality_management/doctype/quality_procedure/quality_procedure.js b/erpnext/quality_management/doctype/quality_procedure/quality_procedure.js index 79fd2ebdbe96..a2c16dddadbf 100644 --- a/erpnext/quality_management/doctype/quality_procedure/quality_procedure.js +++ b/erpnext/quality_management/doctype/quality_procedure/quality_procedure.js @@ -1,23 +1,23 @@ // Copyright (c) 2018, Frappe and contributors // For license information, please see license.txt -frappe.ui.form.on('Quality Procedure', { - refresh: function(frm) { - frm.set_query('procedure', 'processes', (frm) =>{ +frappe.ui.form.on("Quality Procedure", { + refresh: function (frm) { + frm.set_query("procedure", "processes", (frm) => { return { filters: { - name: ['not in', [frm.parent_quality_procedure, frm.name]] - } + name: ["not in", [frm.parent_quality_procedure, frm.name]], + }, }; }); - frm.set_query('parent_quality_procedure', function(){ + frm.set_query("parent_quality_procedure", function () { return { filters: { is_group: 1, - name: ['!=', frm.doc.name] - } + name: ["!=", frm.doc.name], + }, }; }); - } + }, }); diff --git a/erpnext/quality_management/doctype/quality_procedure/quality_procedure_tree.js b/erpnext/quality_management/doctype/quality_procedure/quality_procedure_tree.js index 2851fcc5969a..25f9a5906a10 100644 --- a/erpnext/quality_management/doctype/quality_procedure/quality_procedure_tree.js +++ b/erpnext/quality_management/doctype/quality_procedure/quality_procedure_tree.js @@ -1,18 +1,18 @@ frappe.treeview_settings["Quality Procedure"] = { - ignore_fields:["parent_quality_procedure"], - get_tree_nodes: 'erpnext.quality_management.doctype.quality_procedure.quality_procedure.get_children', - add_tree_node: 'erpnext.quality_management.doctype.quality_procedure.quality_procedure.add_node', + ignore_fields: ["parent_quality_procedure"], + get_tree_nodes: "erpnext.quality_management.doctype.quality_procedure.quality_procedure.get_children", + add_tree_node: "erpnext.quality_management.doctype.quality_procedure.quality_procedure.add_node", filters: [ { fieldname: "parent_quality_procedure", fieldtype: "Link", options: "Quality Procedure", label: __("Quality Procedure"), - get_query: function() { + get_query: function () { return { - filters: [["Quality Procedure", 'is_group', '=', 1]] + filters: [["Quality Procedure", "is_group", "=", 1]], }; - } + }, }, ], breadcrumb: "Quality Management", @@ -22,13 +22,13 @@ frappe.treeview_settings["Quality Procedure"] = { menu_items: [ { label: __("New Quality Procedure"), - action: function() { + action: function () { frappe.new_doc("Quality Procedure", true); }, - condition: 'frappe.boot.user.can_create.indexOf("Quality Procedure") !== -1' - } + condition: 'frappe.boot.user.can_create.indexOf("Quality Procedure") !== -1', + }, ], - onload: function(treeview) { + onload: function (treeview) { treeview.make_tree(); }, }; diff --git a/erpnext/quality_management/doctype/quality_review/quality_review.js b/erpnext/quality_management/doctype/quality_review/quality_review.js index 0e6b7034101d..504f8fceb2ec 100644 --- a/erpnext/quality_management/doctype/quality_review/quality_review.js +++ b/erpnext/quality_management/doctype/quality_review/quality_review.js @@ -1,15 +1,15 @@ // Copyright (c) 2018, Frappe and contributors // For license information, please see license.txt -frappe.ui.form.on('Quality Review', { - goal: function(frm) { +frappe.ui.form.on("Quality Review", { + goal: function (frm) { frappe.call({ - "method": "frappe.client.get", + method: "frappe.client.get", args: { doctype: "Quality Goal", - name: frm.doc.goal + name: frm.doc.goal, }, - callback: function(data){ + callback: function (data) { frm.fields_dict.reviews.grid.remove_all(); let objectives = data.message.objectives; for (var i in objectives) { @@ -19,7 +19,7 @@ frappe.ui.form.on('Quality Review', { frm.fields_dict.reviews.get_value()[i].uom = objectives[i].uom; } frm.refresh(); - } + }, }); }, }); diff --git a/erpnext/quality_management/doctype/quality_review/quality_review_list.js b/erpnext/quality_management/doctype/quality_review/quality_review_list.js index b0be783de56f..3be6c10a89d2 100644 --- a/erpnext/quality_management/doctype/quality_review/quality_review_list.js +++ b/erpnext/quality_management/doctype/quality_review/quality_review_list.js @@ -1,12 +1,10 @@ -frappe.listview_settings['Quality Review'] = { +frappe.listview_settings["Quality Review"] = { add_fields: ["action"], - get_indicator: function(doc) - { - if(doc.action == "No Action") { + get_indicator: function (doc) { + if (doc.action == "No Action") { return [__("No Action"), "green", "action,=,No Action"]; - } - else if(doc.action == "Action Initialised") { + } else if (doc.action == "Action Initialised") { return [__("Action Initialised"), "red", "action,=,Action Initialised"]; } - } + }, }; diff --git a/erpnext/regional/doctype/import_supplier_invoice/import_supplier_invoice.js b/erpnext/regional/doctype/import_supplier_invoice/import_supplier_invoice.js index 5918ec8b3160..5fbb5cb7e010 100644 --- a/erpnext/regional/doctype/import_supplier_invoice/import_supplier_invoice.js +++ b/erpnext/regional/doctype/import_supplier_invoice/import_supplier_invoice.js @@ -1,39 +1,39 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -frappe.ui.form.on('Import Supplier Invoice', { - onload: function(frm) { +frappe.ui.form.on("Import Supplier Invoice", { + onload: function (frm) { frappe.realtime.on("import_invoice_update", function (data) { frm.dashboard.show_progress(data.title, (data.count / data.total) * 100, data.message); if (data.count == data.total) { - window.setTimeout(title => frm.dashboard.hide_progress(title), 1500, data.title); + window.setTimeout((title) => frm.dashboard.hide_progress(title), 1500, data.title); } }); }, - setup: function(frm) { - frm.set_query("tax_account", function(doc) { + setup: function (frm) { + frm.set_query("tax_account", function (doc) { return { filters: { - account_type: 'Tax', - company: doc.company - } + account_type: "Tax", + company: doc.company, + }, }; }); - frm.set_query("default_buying_price_list", function(doc) { + frm.set_query("default_buying_price_list", function (doc) { return { filters: { - currency: frappe.get_doc(":Company", doc.company).default_currency - } + currency: frappe.get_doc(":Company", doc.company).default_currency, + }, }; }); }, - refresh: function(frm) { + refresh: function (frm) { frm.trigger("toggle_read_only_fields"); }, - toggle_read_only_fields: function(frm) { + toggle_read_only_fields: function (frm) { if (in_list(["File Import Completed", "Processing File Data"], frm.doc.status)) { cur_frm.set_read_only(); cur_frm.refresh_fields(); @@ -41,6 +41,5 @@ frappe.ui.form.on('Import Supplier Invoice', { } else { frm.set_df_property("import_invoices", "hidden", 0); } - } - + }, }); diff --git a/erpnext/regional/doctype/ksa_vat_sales_account/ksa_vat_sales_account.js b/erpnext/regional/doctype/ksa_vat_sales_account/ksa_vat_sales_account.js index 72613f4064ff..c70973dcc350 100644 --- a/erpnext/regional/doctype/ksa_vat_sales_account/ksa_vat_sales_account.js +++ b/erpnext/regional/doctype/ksa_vat_sales_account/ksa_vat_sales_account.js @@ -1,8 +1,7 @@ // Copyright (c) 2021, Havenir Solutions and contributors // For license information, please see license.txt -frappe.ui.form.on('KSA VAT Sales Account', { +frappe.ui.form.on("KSA VAT Sales Account", { // refresh: function(frm) { - // } }); diff --git a/erpnext/regional/doctype/ksa_vat_setting/ksa_vat_setting.js b/erpnext/regional/doctype/ksa_vat_setting/ksa_vat_setting.js index 00b62b9adfb9..5db1641f3d7f 100644 --- a/erpnext/regional/doctype/ksa_vat_setting/ksa_vat_setting.js +++ b/erpnext/regional/doctype/ksa_vat_setting/ksa_vat_setting.js @@ -1,8 +1,8 @@ // Copyright (c) 2021, Havenir Solutions and contributors // For license information, please see license.txt -frappe.ui.form.on('KSA VAT Setting', { +frappe.ui.form.on("KSA VAT Setting", { onload: function () { - frappe.breadcrumbs.add('Accounts', 'KSA VAT Setting'); - } + frappe.breadcrumbs.add("Accounts", "KSA VAT Setting"); + }, }); diff --git a/erpnext/regional/doctype/ksa_vat_setting/ksa_vat_setting_list.js b/erpnext/regional/doctype/ksa_vat_setting/ksa_vat_setting_list.js index 269cbec5fb4c..39f8584cb72c 100644 --- a/erpnext/regional/doctype/ksa_vat_setting/ksa_vat_setting_list.js +++ b/erpnext/regional/doctype/ksa_vat_setting/ksa_vat_setting_list.js @@ -1,5 +1,5 @@ -frappe.listview_settings['KSA VAT Setting'] = { - onload () { - frappe.breadcrumbs.add('Accounts'); - } -} \ No newline at end of file +frappe.listview_settings["KSA VAT Setting"] = { + onload() { + frappe.breadcrumbs.add("Accounts"); + }, +}; diff --git a/erpnext/regional/doctype/lower_deduction_certificate/lower_deduction_certificate.js b/erpnext/regional/doctype/lower_deduction_certificate/lower_deduction_certificate.js index 8257bf8a969e..02eaff53bb97 100644 --- a/erpnext/regional/doctype/lower_deduction_certificate/lower_deduction_certificate.js +++ b/erpnext/regional/doctype/lower_deduction_certificate/lower_deduction_certificate.js @@ -1,8 +1,7 @@ // Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Lower Deduction Certificate', { +frappe.ui.form.on("Lower Deduction Certificate", { // refresh: function(frm) { - // } }); diff --git a/erpnext/regional/doctype/product_tax_category/product_tax_category.js b/erpnext/regional/doctype/product_tax_category/product_tax_category.js index 9f8e7950156c..ffbdc5d149cb 100644 --- a/erpnext/regional/doctype/product_tax_category/product_tax_category.js +++ b/erpnext/regional/doctype/product_tax_category/product_tax_category.js @@ -1,8 +1,7 @@ // Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Product Tax Category', { +frappe.ui.form.on("Product Tax Category", { // refresh: function(frm) { - // } }); diff --git a/erpnext/regional/doctype/south_africa_vat_settings/south_africa_vat_settings.js b/erpnext/regional/doctype/south_africa_vat_settings/south_africa_vat_settings.js index e37a61ac853c..86384e41b347 100644 --- a/erpnext/regional/doctype/south_africa_vat_settings/south_africa_vat_settings.js +++ b/erpnext/regional/doctype/south_africa_vat_settings/south_africa_vat_settings.js @@ -1,23 +1,23 @@ // Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('South Africa VAT Settings', { - refresh: function(frm) { - frm.set_query("company", function() { +frappe.ui.form.on("South Africa VAT Settings", { + refresh: function (frm) { + frm.set_query("company", function () { return { filters: { country: "South Africa", - } + }, }; }); - frm.set_query("account", "vat_accounts", function() { + frm.set_query("account", "vat_accounts", function () { return { filters: { company: frm.doc.company, account_type: "Tax", - is_group: 0 - } + is_group: 0, + }, }; }); - } + }, }); diff --git a/erpnext/regional/doctype/uae_vat_settings/uae_vat_settings.js b/erpnext/regional/doctype/uae_vat_settings/uae_vat_settings.js index 66531412fafe..c7d0f054b514 100644 --- a/erpnext/regional/doctype/uae_vat_settings/uae_vat_settings.js +++ b/erpnext/regional/doctype/uae_vat_settings/uae_vat_settings.js @@ -1,14 +1,14 @@ // Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('UAE VAT Settings', { - onload: function(frm) { - frm.set_query('account', 'uae_vat_accounts', function() { +frappe.ui.form.on("UAE VAT Settings", { + onload: function (frm) { + frm.set_query("account", "uae_vat_accounts", function () { return { filters: { - 'company': frm.doc.company - } + company: frm.doc.company, + }, }; }); - } + }, }); diff --git a/erpnext/regional/report/electronic_invoice_register/electronic_invoice_register.js b/erpnext/regional/report/electronic_invoice_register/electronic_invoice_register.js index d7e3ac9a5d3c..1512d95a7eb7 100644 --- a/erpnext/regional/report/electronic_invoice_register/electronic_invoice_register.js +++ b/erpnext/regional/report/electronic_invoice_register/electronic_invoice_register.js @@ -3,51 +3,53 @@ /* eslint-disable */ frappe.query_reports["Electronic Invoice Register"] = { - "filters": [ + filters: [ { - "fieldname":"from_date", - "label": __("From Date"), - "fieldtype": "Date", - "default": frappe.datetime.add_months(frappe.datetime.get_today(), -1), - "width": "80" + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + default: frappe.datetime.add_months(frappe.datetime.get_today(), -1), + width: "80", }, { - "fieldname":"to_date", - "label": __("To Date"), - "fieldtype": "Date", - "default": frappe.datetime.get_today() + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + default: frappe.datetime.get_today(), }, { - "fieldname":"customer", - "label": __("Customer"), - "fieldtype": "Link", - "options": "Customer" + fieldname: "customer", + label: __("Customer"), + fieldtype: "Link", + options: "Customer", }, { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_user_default("Company") + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), }, ], - "onload": function(reportview) { - reportview.page.add_inner_button(__("Export E-Invoices"), function() { + onload: function (reportview) { + reportview.page.add_inner_button(__("Export E-Invoices"), function () { //TODO: refactor condition to disallow export if report has no data. if (!reportview.data.length) { frappe.msgprint(__("No data to export")); - return + return; } var w = window.open( frappe.urllib.get_full_url( - "/api/method/erpnext.regional.italy.utils.export_invoices?" - + "filters=" + JSON.stringify(reportview.get_filter_values()) + "/api/method/erpnext.regional.italy.utils.export_invoices?" + + "filters=" + + JSON.stringify(reportview.get_filter_values()) ) ); if (!w) { - frappe.msgprint(__("Please enable pop-ups")); return; + frappe.msgprint(__("Please enable pop-ups")); + return; } - }) - } -} + }); + }, +}; diff --git a/erpnext/regional/report/fichier_des_ecritures_comptables_[fec]/fichier_des_ecritures_comptables_[fec].js b/erpnext/regional/report/fichier_des_ecritures_comptables_[fec]/fichier_des_ecritures_comptables_[fec].js index b85b58f636ab..9a373affa297 100644 --- a/erpnext/regional/report/fichier_des_ecritures_comptables_[fec]/fichier_des_ecritures_comptables_[fec].js +++ b/erpnext/regional/report/fichier_des_ecritures_comptables_[fec]/fichier_des_ecritures_comptables_[fec].js @@ -2,40 +2,40 @@ // For license information, please see license.txt frappe.query_reports["Fichier des Ecritures Comptables [FEC]"] = { - "filters": [ + filters: [ { - "fieldname": "company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_user_default("Company"), - "reqd": 1 + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), + reqd: 1, }, { - "fieldname": "fiscal_year", - "label": __("Fiscal Year"), - "fieldtype": "Link", - "options": "Fiscal Year", - "default": erpnext.utils.get_fiscal_year(frappe.datetime.get_today()), - "reqd": 1 - } + fieldname: "fiscal_year", + label: __("Fiscal Year"), + fieldtype: "Link", + options: "Fiscal Year", + default: erpnext.utils.get_fiscal_year(frappe.datetime.get_today()), + reqd: 1, + }, ], - onload: function(query_report) { - query_report.page.add_inner_button(__("Export"), function() { + onload: function (query_report) { + query_report.page.add_inner_button(__("Export"), function () { fec_export(query_report); }); - query_report.add_make_chart_button = function() { + query_report.add_make_chart_button = function () { // }; - query_report.export_report = function() { + query_report.export_report = function () { fec_export(query_report); }; - } + }, }; -let fec_export = function(query_report) { +let fec_export = function (query_report) { const fiscal_year = query_report.get_values().fiscal_year; const company = query_report.get_values().company; @@ -46,38 +46,38 @@ let fec_export = function(query_report) { } else { frappe.db.get_value("Fiscal Year", fiscal_year, "year_end_date", (r) => { const fy = r.year_end_date; - const title = company_data + "FEC" + moment(fy).format('YYYYMMDD'); - const column_row = query_report.columns.map(col => col.label); + const title = company_data + "FEC" + moment(fy).format("YYYYMMDD"); + const column_row = query_report.columns.map((col) => col.label); const column_data = query_report.get_data_for_csv(false); const result = [column_row].concat(column_data); downloadify(result, null, title); }); - } }); }; -let downloadify = function(data, roles, title) { +let downloadify = function (data, roles, title) { if (roles && roles.length && !has_common(roles, roles)) { - frappe.msgprint(__("Export not allowed. You need {0} role to export.", [frappe.utils.comma_or(roles)])); + frappe.msgprint( + __("Export not allowed. You need {0} role to export.", [frappe.utils.comma_or(roles)]) + ); return; } const filename = title + ".txt"; let csv_data = to_tab_csv(data); - const a = document.createElement('a'); + const a = document.createElement("a"); if ("download" in a) { // Used Blob object, because it can handle large files let blob_object = new Blob([csv_data], { - type: 'text/csv;charset=UTF-8' + type: "text/csv;charset=UTF-8", }); a.href = URL.createObjectURL(blob_object); a.download = filename; - } else { // use old method - a.href = 'data:attachment/csv,' + encodeURIComponent(csv_data); + a.href = "data:attachment/csv," + encodeURIComponent(csv_data); a.download = filename; a.target = "_blank"; } @@ -88,9 +88,9 @@ let downloadify = function(data, roles, title) { document.body.removeChild(a); }; -let to_tab_csv = function(data) { +let to_tab_csv = function (data) { let res = []; - $.each(data, function(i, row) { + $.each(data, function (i, row) { res.push(row.join("\t")); }); return res.join("\n"); diff --git a/erpnext/regional/report/irs_1099/irs_1099.js b/erpnext/regional/report/irs_1099/irs_1099.js index b3508e40a9f5..385468b58aae 100644 --- a/erpnext/regional/report/irs_1099/irs_1099.js +++ b/erpnext/regional/report/irs_1099/irs_1099.js @@ -2,33 +2,33 @@ // License: GNU General Public License v3. See license.txt frappe.query_reports["IRS 1099"] = { - "filters": [ + filters: [ { - "fieldname": "company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_user_default("Company"), - "reqd": 1, - "width": 80, + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), + reqd: 1, + width: 80, }, { - "fieldname": "fiscal_year", - "label": __("Fiscal Year"), - "fieldtype": "Link", - "options": "Fiscal Year", - "default": erpnext.utils.get_fiscal_year(frappe.datetime.get_today()), - "reqd": 1, - "width": 80, + fieldname: "fiscal_year", + label: __("Fiscal Year"), + fieldtype: "Link", + options: "Fiscal Year", + default: erpnext.utils.get_fiscal_year(frappe.datetime.get_today()), + reqd: 1, + width: 80, }, { - "fieldname": "supplier_group", - "label": __("Supplier Group"), - "fieldtype": "Link", - "options": "Supplier Group", - "default": "", - "reqd": 0, - "width": 80 + fieldname: "supplier_group", + label: __("Supplier Group"), + fieldtype: "Link", + options: "Supplier Group", + default: "", + reqd: 0, + width: 80, }, ], @@ -36,12 +36,15 @@ frappe.query_reports["IRS 1099"] = { query_report.page.add_inner_button(__("Print IRS 1099 Forms"), () => { build_1099_print(query_report); }); - } + }, }; function build_1099_print(query_report) { let filters = JSON.stringify(query_report.get_values()); - let w = window.open('/api/method/erpnext.regional.report.irs_1099.irs_1099.irs_1099_print?' + - '&filters=' + encodeURIComponent(filters)); + let w = window.open( + "/api/method/erpnext.regional.report.irs_1099.irs_1099.irs_1099_print?" + + "&filters=" + + encodeURIComponent(filters) + ); // w.print(); } diff --git a/erpnext/regional/report/ksa_vat/ksa_vat.js b/erpnext/regional/report/ksa_vat/ksa_vat.js index 59e72c3e6384..b21ce6b7f708 100644 --- a/erpnext/regional/report/ksa_vat/ksa_vat.js +++ b/erpnext/regional/report/ksa_vat/ksa_vat.js @@ -4,54 +4,56 @@ frappe.query_reports["KSA VAT"] = { onload() { - frappe.breadcrumbs.add('Accounts'); + frappe.breadcrumbs.add("Accounts"); }, - "filters": [ + filters: [ { - "fieldname": "company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "reqd": 1, - "default": frappe.defaults.get_user_default("Company") + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + reqd: 1, + default: frappe.defaults.get_user_default("Company"), }, { - "fieldname": "from_date", - "label": __("From Date"), - "fieldtype": "Date", - "reqd": 1, - "default": frappe.datetime.add_months(frappe.datetime.get_today(), -1), + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + reqd: 1, + default: frappe.datetime.add_months(frappe.datetime.get_today(), -1), }, { - "fieldname": "to_date", - "label": __("To Date"), - "fieldtype": "Date", - "reqd": 1, - "default": frappe.datetime.get_today() - } + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + reqd: 1, + default: frappe.datetime.get_today(), + }, ], - "formatter": function(value, row, column, data, default_formatter) { - if (data - && (data.title=='VAT on Sales' || data.title=='VAT on Purchases') - && data.title==value) { + formatter: function (value, row, column, data, default_formatter) { + if ( + data && + (data.title == "VAT on Sales" || data.title == "VAT on Purchases") && + data.title == value + ) { value = $(`${value}`); var $value = $(value).css("font-weight", "bold"); value = $value.wrap("

              ").parent().html(); - return value - }else if (data.title=='Grand Total'){ - if (data.title==value) { + return value; + } else if (data.title == "Grand Total") { + if (data.title == value) { value = $(`${value}`); var $value = $(value).css("font-weight", "bold"); value = $value.wrap("

              ").parent().html(); - return value - }else{ + return value; + } else { value = default_formatter(value, row, column, data); value = $(`${value}`); var $value = $(value).css("font-weight", "bold"); value = $value.wrap("

              ").parent().html(); - return value + return value; } - }else{ + } else { value = default_formatter(value, row, column, data); return value; } diff --git a/erpnext/regional/report/uae_vat_201/uae_vat_201.js b/erpnext/regional/report/uae_vat_201/uae_vat_201.js index 595742477012..ddfa5d426890 100644 --- a/erpnext/regional/report/uae_vat_201/uae_vat_201.js +++ b/erpnext/regional/report/uae_vat_201/uae_vat_201.js @@ -3,34 +3,37 @@ /* eslint-disable */ frappe.query_reports["UAE VAT 201"] = { - "filters": [ + filters: [ { - "fieldname": "company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "reqd": 1, - "default": frappe.defaults.get_user_default("Company") + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + reqd: 1, + default: frappe.defaults.get_user_default("Company"), }, { - "fieldname": "from_date", - "label": __("From Date"), - "fieldtype": "Date", - "reqd": 1, - "default": frappe.datetime.add_months(frappe.datetime.get_today(), -3), + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + reqd: 1, + default: frappe.datetime.add_months(frappe.datetime.get_today(), -3), }, { - "fieldname": "to_date", - "label": __("To Date"), - "fieldtype": "Date", - "reqd": 1, - "default": frappe.datetime.get_today() + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + reqd: 1, + default: frappe.datetime.get_today(), }, ], - "formatter": function(value, row, column, data, default_formatter) { - if (data - && (data.legend=='VAT on Sales and All Other Outputs' || data.legend=='VAT on Expenses and All Other Inputs') - && data.legend==value) { + formatter: function (value, row, column, data, default_formatter) { + if ( + data && + (data.legend == "VAT on Sales and All Other Outputs" || + data.legend == "VAT on Expenses and All Other Inputs") && + data.legend == value + ) { value = $(`${value}`); var $value = $(value).css("font-weight", "bold"); value = $value.wrap("

              ").parent().html(); diff --git a/erpnext/regional/report/vat_audit_report/vat_audit_report.js b/erpnext/regional/report/vat_audit_report/vat_audit_report.js index 39ef9b563ac7..fa8c8a99e075 100644 --- a/erpnext/regional/report/vat_audit_report/vat_audit_report.js +++ b/erpnext/regional/report/vat_audit_report/vat_audit_report.js @@ -3,29 +3,29 @@ /* eslint-disable */ frappe.query_reports["VAT Audit Report"] = { - "filters": [ + filters: [ { - "fieldname": "company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "reqd": 1, - "default": frappe.defaults.get_user_default("Company") + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + reqd: 1, + default: frappe.defaults.get_user_default("Company"), }, { - "fieldname": "from_date", - "label": __("From Date"), - "fieldtype": "Date", - "reqd": 1, - "default": frappe.datetime.add_months(frappe.datetime.get_today(), -2), - "width": "80" + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + reqd: 1, + default: frappe.datetime.add_months(frappe.datetime.get_today(), -2), + width: "80", }, { - "fieldname": "to_date", - "label": __("To Date"), - "fieldtype": "Date", - "reqd": 1, - "default": frappe.datetime.get_today() - } - ] + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + reqd: 1, + default: frappe.datetime.get_today(), + }, + ], }; diff --git a/erpnext/selling/doctype/customer/customer.js b/erpnext/selling/doctype/customer/customer.js index 432abfce73b2..1507d8e923fc 100644 --- a/erpnext/selling/doctype/customer/customer.js +++ b/erpnext/selling/doctype/customer/customer.js @@ -2,147 +2,172 @@ // License: GNU General Public License v3. See license.txt frappe.ui.form.on("Customer", { - setup: function(frm) { - + setup: function (frm) { frm.make_methods = { - 'Quotation': () => frappe.model.open_mapped_doc({ - method: "erpnext.selling.doctype.customer.customer.make_quotation", - frm: cur_frm - }), - 'Opportunity': () => frappe.model.open_mapped_doc({ - method: "erpnext.selling.doctype.customer.customer.make_opportunity", - frm: cur_frm - }) - } - - frm.add_fetch('lead_name', 'company_name', 'customer_name'); - frm.add_fetch('default_sales_partner','commission_rate','default_commission_rate'); - frm.set_query('customer_group', {'is_group': 0}); - frm.set_query('default_price_list', { 'selling': 1}); - frm.set_query('account', 'accounts', function(doc, cdt, cdn) { - var d = locals[cdt][cdn]; + Quotation: () => + frappe.model.open_mapped_doc({ + method: "erpnext.selling.doctype.customer.customer.make_quotation", + frm: cur_frm, + }), + Opportunity: () => + frappe.model.open_mapped_doc({ + method: "erpnext.selling.doctype.customer.customer.make_opportunity", + frm: cur_frm, + }), + }; + + frm.add_fetch("lead_name", "company_name", "customer_name"); + frm.add_fetch("default_sales_partner", "commission_rate", "default_commission_rate"); + frm.set_query("customer_group", { is_group: 0 }); + frm.set_query("default_price_list", { selling: 1 }); + frm.set_query("account", "accounts", function (doc, cdt, cdn) { + var d = locals[cdt][cdn]; var filters = { - 'account_type': 'Receivable', - 'company': d.company, - "is_group": 0 + account_type: "Receivable", + company: d.company, + is_group: 0, }; - if(doc.party_account_currency) { - $.extend(filters, {"account_currency": doc.party_account_currency}); + if (doc.party_account_currency) { + $.extend(filters, { account_currency: doc.party_account_currency }); } return { - filters: filters - } + filters: filters, + }; }); if (frm.doc.__islocal == 1) { frm.set_value("represents_company", ""); } - frm.set_query('customer_primary_contact', function(doc) { + frm.set_query("customer_primary_contact", function (doc) { return { query: "erpnext.selling.doctype.customer.customer.get_customer_primary_contact", filters: { - 'customer': doc.name - } - } - }) - frm.set_query('customer_primary_address', function(doc) { + customer: doc.name, + }, + }; + }); + frm.set_query("customer_primary_address", function (doc) { return { filters: { - 'link_doctype': 'Customer', - 'link_name': doc.name - } - } - }) + link_doctype: "Customer", + link_name: doc.name, + }, + }; + }); - frm.set_query('default_bank_account', function() { + frm.set_query("default_bank_account", function () { return { filters: { - 'is_company_account': 1 - } - } + is_company_account: 1, + }, + }; }); }, - customer_primary_address: function(frm){ - if(frm.doc.customer_primary_address){ + customer_primary_address: function (frm) { + if (frm.doc.customer_primary_address) { frappe.call({ - method: 'frappe.contacts.doctype.address.address.get_address_display', + method: "frappe.contacts.doctype.address.address.get_address_display", args: { - "address_dict": frm.doc.customer_primary_address + address_dict: frm.doc.customer_primary_address, }, - callback: function(r) { + callback: function (r) { frm.set_value("primary_address", r.message); - } + }, }); } - if(!frm.doc.customer_primary_address){ + if (!frm.doc.customer_primary_address) { frm.set_value("primary_address", ""); } }, - is_internal_customer: function(frm) { + is_internal_customer: function (frm) { if (frm.doc.is_internal_customer == 1) { frm.toggle_reqd("represents_company", true); - } - else { + } else { frm.toggle_reqd("represents_company", false); } }, - customer_primary_contact: function(frm){ - if(!frm.doc.customer_primary_contact){ + customer_primary_contact: function (frm) { + if (!frm.doc.customer_primary_contact) { frm.set_value("mobile_no", ""); frm.set_value("email_id", ""); } }, - loyalty_program: function(frm) { - if(frm.doc.loyalty_program) { - frm.set_value('loyalty_program_tier', null); + loyalty_program: function (frm) { + if (frm.doc.loyalty_program) { + frm.set_value("loyalty_program_tier", null); } }, - refresh: function(frm) { - if(frappe.defaults.get_default("cust_master_name")!="Naming Series") { + refresh: function (frm) { + if (frappe.defaults.get_default("cust_master_name") != "Naming Series") { frm.toggle_display("naming_series", false); } else { erpnext.toggle_naming_series(); } - frappe.dynamic_link = {doc: frm.doc, fieldname: 'name', doctype: 'Customer'} + frappe.dynamic_link = { doc: frm.doc, fieldname: "name", doctype: "Customer" }; - if(!frm.doc.__islocal) { + if (!frm.doc.__islocal) { frappe.contacts.render_address_and_contact(frm); // custom buttons - frm.add_custom_button(__('Accounts Receivable'), function () { - frappe.set_route('query-report', 'Accounts Receivable', { party_type: "Customer", party: frm.doc.name }); - }, __('View')); - - frm.add_custom_button(__('Accounting Ledger'), function () { - frappe.set_route('query-report', 'General Ledger', - {party_type: 'Customer', party: frm.doc.name, party_name: frm.doc.customer_name}); - }, __('View')); + frm.add_custom_button( + __("Accounts Receivable"), + function () { + frappe.set_route("query-report", "Accounts Receivable", { + party_type: "Customer", + party: frm.doc.name, + }); + }, + __("View") + ); + + frm.add_custom_button( + __("Accounting Ledger"), + function () { + frappe.set_route("query-report", "General Ledger", { + party_type: "Customer", + party: frm.doc.name, + party_name: frm.doc.customer_name, + }); + }, + __("View") + ); - frm.add_custom_button(__('Pricing Rule'), function () { - erpnext.utils.make_pricing_rule(frm.doc.doctype, frm.doc.name); - }, __('Create')); + frm.add_custom_button( + __("Pricing Rule"), + function () { + erpnext.utils.make_pricing_rule(frm.doc.doctype, frm.doc.name); + }, + __("Create") + ); - frm.add_custom_button(__('Get Customer Group Details'), function () { - frm.trigger("get_customer_group_details"); - }, __('Actions')); + frm.add_custom_button( + __("Get Customer Group Details"), + function () { + frm.trigger("get_customer_group_details"); + }, + __("Actions") + ); if (cint(frappe.defaults.get_default("enable_common_party_accounting"))) { - frm.add_custom_button(__('Link with Supplier'), function () { - frm.trigger('show_party_link_dialog'); - }, __('Actions')); + frm.add_custom_button( + __("Link with Supplier"), + function () { + frm.trigger("show_party_link_dialog"); + }, + __("Actions") + ); } // indicator erpnext.utils.set_party_dashboard_indicators(frm); - } else { frappe.contacts.clear_address_and_contact(frm); } @@ -151,55 +176,58 @@ frappe.ui.form.on("Customer", { grid.set_column_disp("allocated_amount", false); grid.set_column_disp("incentives", false); }, - validate: function(frm) { - if(frm.doc.lead_name) frappe.model.clear_doc("Lead", frm.doc.lead_name); - + validate: function (frm) { + if (frm.doc.lead_name) frappe.model.clear_doc("Lead", frm.doc.lead_name); }, - get_customer_group_details: function(frm) { + get_customer_group_details: function (frm) { frappe.call({ method: "get_customer_group_details", doc: frm.doc, - callback: function() { + callback: function () { frm.refresh(); - } + }, }); - }, - show_party_link_dialog: function(frm) { + show_party_link_dialog: function (frm) { const dialog = new frappe.ui.Dialog({ - title: __('Select a Supplier'), - fields: [{ - fieldtype: 'Link', label: __('Supplier'), - options: 'Supplier', fieldname: 'supplier', reqd: 1 - }], - primary_action: function({ supplier }) { + title: __("Select a Supplier"), + fields: [ + { + fieldtype: "Link", + label: __("Supplier"), + options: "Supplier", + fieldname: "supplier", + reqd: 1, + }, + ], + primary_action: function ({ supplier }) { frappe.call({ - method: 'erpnext.accounts.doctype.party_link.party_link.create_party_link', + method: "erpnext.accounts.doctype.party_link.party_link.create_party_link", args: { - primary_role: 'Customer', + primary_role: "Customer", primary_party: frm.doc.name, - secondary_party: supplier + secondary_party: supplier, }, freeze: true, - callback: function() { + callback: function () { dialog.hide(); frappe.msgprint({ - message: __('Successfully linked to Supplier'), - alert: true + message: __("Successfully linked to Supplier"), + alert: true, }); }, - error: function() { + error: function () { dialog.hide(); frappe.msgprint({ - message: __('Linking to Supplier Failed. Please try again.'), - title: __('Linking Failed'), - indicator: 'red' + message: __("Linking to Supplier Failed. Please try again."), + title: __("Linking Failed"), + indicator: "red", }); - } + }, }); }, - primary_action_label: __('Create Link') + primary_action_label: __("Create Link"), }); dialog.show(); - } + }, }); diff --git a/erpnext/selling/doctype/customer/customer_list.js b/erpnext/selling/doctype/customer/customer_list.js index 38fc9ad1f13b..6149c6f873d2 100644 --- a/erpnext/selling/doctype/customer/customer_list.js +++ b/erpnext/selling/doctype/customer/customer_list.js @@ -1,3 +1,3 @@ -frappe.listview_settings['Customer'] = { +frappe.listview_settings["Customer"] = { add_fields: ["customer_name", "territory", "customer_group", "customer_type", "image"], }; diff --git a/erpnext/selling/doctype/industry_type/industry_type.js b/erpnext/selling/doctype/industry_type/industry_type.js index 3680906057fa..273e30fd1973 100644 --- a/erpnext/selling/doctype/industry_type/industry_type.js +++ b/erpnext/selling/doctype/industry_type/industry_type.js @@ -1,13 +1,7 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt - - //--------- ONLOAD ------------- -cur_frm.cscript.onload = function(doc, cdt, cdn) { - -} - -cur_frm.cscript.refresh = function(doc, cdt, cdn) { +cur_frm.cscript.onload = function (doc, cdt, cdn) {}; -} +cur_frm.cscript.refresh = function (doc, cdt, cdn) {}; diff --git a/erpnext/selling/doctype/installation_note/installation_note.js b/erpnext/selling/doctype/installation_note/installation_note.js index 27a3b35ccfbb..f26b40bdb04a 100644 --- a/erpnext/selling/doctype/installation_note/installation_note.js +++ b/erpnext/selling/doctype/installation_note/installation_note.js @@ -1,30 +1,30 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -frappe.ui.form.on('Installation Note', { - setup: function(frm) { - frappe.dynamic_link = {doc: frm.doc, fieldname: 'customer', doctype: 'Customer'} - frm.set_query('customer_address', erpnext.queries.address_query); - frm.set_query('contact_person', erpnext.queries.contact_query); - frm.set_query('customer', erpnext.queries.customer); +frappe.ui.form.on("Installation Note", { + setup: function (frm) { + frappe.dynamic_link = { doc: frm.doc, fieldname: "customer", doctype: "Customer" }; + frm.set_query("customer_address", erpnext.queries.address_query); + frm.set_query("contact_person", erpnext.queries.contact_query); + frm.set_query("customer", erpnext.queries.customer); }, - onload: function(frm) { - if(!frm.doc.status) { - frm.set_value({ status:'Draft'}); + onload: function (frm) { + if (!frm.doc.status) { + frm.set_value({ status: "Draft" }); } - if(frm.doc.__islocal) { - frm.set_value({inst_date: frappe.datetime.get_today()}); + if (frm.doc.__islocal) { + frm.set_value({ inst_date: frappe.datetime.get_today() }); } }, - customer: function(frm) { + customer: function (frm) { erpnext.utils.get_party_details(frm); }, - customer_address: function(frm) { + customer_address: function (frm) { erpnext.utils.get_address_display(frm); }, - contact_person: function(frm) { + contact_person: function (frm) { erpnext.utils.get_contact_details(frm); - } + }, }); frappe.provide("erpnext.selling"); @@ -33,9 +33,10 @@ frappe.provide("erpnext.selling"); erpnext.selling.InstallationNote = class InstallationNote extends frappe.ui.form.Controller { refresh() { var me = this; - if (this.frm.doc.docstatus===0) { - this.frm.add_custom_button(__('From Delivery Note'), - function() { + if (this.frm.doc.docstatus === 0) { + this.frm.add_custom_button( + __("From Delivery Note"), + function () { erpnext.utils.map_current_doc({ method: "erpnext.stock.doctype.delivery_note.delivery_note.make_installation_note", source_doctype: "Delivery Note", @@ -48,13 +49,15 @@ erpnext.selling.InstallationNote = class InstallationNote extends frappe.ui.form docstatus: 1, status: ["not in", ["Stopped", "Closed"]], per_installed: ["<", 99.99], - company: me.frm.doc.company - } - }) - }, "fa fa-download", "btn-default" + company: me.frm.doc.company, + }, + }); + }, + "fa fa-download", + "btn-default" ); } } }; -extend_cscript(cur_frm.cscript, new erpnext.selling.InstallationNote({frm: cur_frm})); +extend_cscript(cur_frm.cscript, new erpnext.selling.InstallationNote({ frm: cur_frm })); diff --git a/erpnext/selling/doctype/party_specific_item/party_specific_item.js b/erpnext/selling/doctype/party_specific_item/party_specific_item.js index 077b93631ecf..0decc70d7ac4 100644 --- a/erpnext/selling/doctype/party_specific_item/party_specific_item.js +++ b/erpnext/selling/doctype/party_specific_item/party_specific_item.js @@ -1,8 +1,7 @@ // Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Party Specific Item', { +frappe.ui.form.on("Party Specific Item", { // refresh: function(frm) { - // } }); diff --git a/erpnext/selling/doctype/quotation/quotation_list.js b/erpnext/selling/doctype/quotation/quotation_list.js index 32fce1f2ad83..ae744b9cba39 100644 --- a/erpnext/selling/doctype/quotation/quotation_list.js +++ b/erpnext/selling/doctype/quotation/quotation_list.js @@ -1,38 +1,37 @@ -frappe.listview_settings['Quotation'] = { - add_fields: ["customer_name", "base_grand_total", "status", - "company", "currency", 'valid_till'], +frappe.listview_settings["Quotation"] = { + add_fields: ["customer_name", "base_grand_total", "status", "company", "currency", "valid_till"], - onload: function(listview) { + onload: function (listview) { if (listview.page.fields_dict.quotation_to) { - listview.page.fields_dict.quotation_to.get_query = function() { + listview.page.fields_dict.quotation_to.get_query = function () { return { - "filters": { - "name": ["in", ["Customer", "Lead"]], - } + filters: { + name: ["in", ["Customer", "Lead"]], + }, }; }; } - listview.page.add_action_item(__("Sales Order"), ()=>{ + listview.page.add_action_item(__("Sales Order"), () => { erpnext.bulk_transaction_processing.create(listview, "Quotation", "Sales Order"); }); - listview.page.add_action_item(__("Sales Invoice"), ()=>{ + listview.page.add_action_item(__("Sales Invoice"), () => { erpnext.bulk_transaction_processing.create(listview, "Quotation", "Sales Invoice"); }); }, - get_indicator: function(doc) { - if(doc.status==="Open") { + get_indicator: function (doc) { + if (doc.status === "Open") { return [__("Open"), "orange", "status,=,Open"]; - } else if (doc.status==="Partially Ordered") { + } else if (doc.status === "Partially Ordered") { return [__("Partially Ordered"), "yellow", "status,=,Partially Ordered"]; - } else if(doc.status==="Ordered") { + } else if (doc.status === "Ordered") { return [__("Ordered"), "green", "status,=,Ordered"]; - } else if(doc.status==="Lost") { + } else if (doc.status === "Lost") { return [__("Lost"), "gray", "status,=,Lost"]; - } else if(doc.status==="Expired") { + } else if (doc.status === "Expired") { return [__("Expired"), "gray", "status,=,Expired"]; } - } + }, }; diff --git a/erpnext/selling/doctype/sales_order/sales_order_calendar.js b/erpnext/selling/doctype/sales_order/sales_order_calendar.js index cb412cfb4a76..f4c0e2ba72a9 100644 --- a/erpnext/selling/doctype/sales_order/sales_order_calendar.js +++ b/erpnext/selling/doctype/sales_order/sales_order_calendar.js @@ -3,43 +3,44 @@ frappe.views.calendar["Sales Order"] = { field_map: { - "start": "delivery_date", - "end": "delivery_date", - "id": "name", - "title": "customer_name", - "allDay": "allDay" + start: "delivery_date", + end: "delivery_date", + id: "name", + title: "customer_name", + allDay: "allDay", }, gantt: true, filters: [ { - "fieldtype": "Link", - "fieldname": "customer", - "options": "Customer", - "label": __("Customer") + fieldtype: "Link", + fieldname: "customer", + options: "Customer", + label: __("Customer"), }, { - "fieldtype": "Select", - "fieldname": "delivery_status", - "options": "Not Delivered\nFully Delivered\nPartly Delivered\nClosed\nNot Applicable", - "label": __("Delivery Status") + fieldtype: "Select", + fieldname: "delivery_status", + options: "Not Delivered\nFully Delivered\nPartly Delivered\nClosed\nNot Applicable", + label: __("Delivery Status"), }, { - "fieldtype": "Select", - "fieldname": "billing_status", - "options": "Not Billed\nFully Billed\nPartly Billed\nClosed", - "label": __("Billing Status") + fieldtype: "Select", + fieldname: "billing_status", + options: "Not Billed\nFully Billed\nPartly Billed\nClosed", + label: __("Billing Status"), }, ], get_events_method: "erpnext.selling.doctype.sales_order.sales_order.get_events", - get_css_class: function(data) { - if(data.status=="Closed") { + get_css_class: function (data) { + if (data.status == "Closed") { return "success"; - } if(data.delivery_status=="Not Delivered") { + } + if (data.delivery_status == "Not Delivered") { return "danger"; - } else if(data.delivery_status=="Partly Delivered") { + } else if (data.delivery_status == "Partly Delivered") { return "warning"; - } else if(data.delivery_status=="Fully Delivered") { + } else if (data.delivery_status == "Fully Delivered") { return "success"; } - } -} + }, +}; diff --git a/erpnext/selling/doctype/sales_order/sales_order_list.js b/erpnext/selling/doctype/sales_order/sales_order_list.js index 64c58ef5d7b2..61a29c9bcd73 100644 --- a/erpnext/selling/doctype/sales_order/sales_order_list.js +++ b/erpnext/selling/doctype/sales_order/sales_order_list.js @@ -1,6 +1,16 @@ -frappe.listview_settings['Sales Order'] = { - add_fields: ["base_grand_total", "customer_name", "currency", "delivery_date", - "per_delivered", "per_billed", "status", "order_type", "name", "skip_delivery_note"], +frappe.listview_settings["Sales Order"] = { + add_fields: [ + "base_grand_total", + "customer_name", + "currency", + "delivery_date", + "per_delivered", + "per_billed", + "status", + "order_type", + "name", + "skip_delivery_note", + ], get_indicator: function (doc) { if (doc.status === "Closed") { // Closed @@ -12,53 +22,54 @@ frappe.listview_settings['Sales Order'] = { return [__("Completed"), "green", "status,=,Completed"]; } else if (!doc.skip_delivery_note && flt(doc.per_delivered, 6) < 100) { if (frappe.datetime.get_diff(doc.delivery_date) < 0) { - // not delivered & overdue - return [__("Overdue"), "red", - "per_delivered,<,100|delivery_date,<,Today|status,!=,Closed"]; + // not delivered & overdue + return [__("Overdue"), "red", "per_delivered,<,100|delivery_date,<,Today|status,!=,Closed"]; } else if (flt(doc.grand_total) === 0) { // not delivered (zeroount order) - return [__("To Deliver"), "orange", - "per_delivered,<,100|grand_total,=,0|status,!=,Closed"]; + return [__("To Deliver"), "orange", "per_delivered,<,100|grand_total,=,0|status,!=,Closed"]; } else if (flt(doc.per_billed, 6) < 100) { // not delivered & not billed - return [__("To Deliver and Bill"), "orange", - "per_delivered,<,100|per_billed,<,100|status,!=,Closed"]; + return [ + __("To Deliver and Bill"), + "orange", + "per_delivered,<,100|per_billed,<,100|status,!=,Closed", + ]; } else { // not billed - return [__("To Deliver"), "orange", - "per_delivered,<,100|per_billed,=,100|status,!=,Closed"]; + return [__("To Deliver"), "orange", "per_delivered,<,100|per_billed,=,100|status,!=,Closed"]; } - } else if ((flt(doc.per_delivered, 6) === 100) && flt(doc.grand_total) !== 0 - && flt(doc.per_billed, 6) < 100) { + } else if ( + flt(doc.per_delivered, 6) === 100 && + flt(doc.grand_total) !== 0 && + flt(doc.per_billed, 6) < 100 + ) { // to bill - return [__("To Bill"), "orange", - "per_delivered,=,100|per_billed,<,100|status,!=,Closed"]; - } else if (doc.skip_delivery_note && flt(doc.per_billed, 6) < 100){ + return [__("To Bill"), "orange", "per_delivered,=,100|per_billed,<,100|status,!=,Closed"]; + } else if (doc.skip_delivery_note && flt(doc.per_billed, 6) < 100) { return [__("To Bill"), "orange", "per_billed,<,100|status,!=,Closed"]; } }, - onload: function(listview) { + onload: function (listview) { var method = "erpnext.selling.doctype.sales_order.sales_order.close_or_unclose_sales_orders"; - listview.page.add_menu_item(__("Close"), function() { - listview.call_for_selected_items(method, {"status": "Closed"}); + listview.page.add_menu_item(__("Close"), function () { + listview.call_for_selected_items(method, { status: "Closed" }); }); - listview.page.add_menu_item(__("Re-open"), function() { - listview.call_for_selected_items(method, {"status": "Submitted"}); + listview.page.add_menu_item(__("Re-open"), function () { + listview.call_for_selected_items(method, { status: "Submitted" }); }); - listview.page.add_action_item(__("Sales Invoice"), ()=>{ + listview.page.add_action_item(__("Sales Invoice"), () => { erpnext.bulk_transaction_processing.create(listview, "Sales Order", "Sales Invoice"); }); - listview.page.add_action_item(__("Delivery Note"), ()=>{ + listview.page.add_action_item(__("Delivery Note"), () => { erpnext.bulk_transaction_processing.create(listview, "Sales Order", "Delivery Note"); }); - listview.page.add_action_item(__("Advance Payment"), ()=>{ + listview.page.add_action_item(__("Advance Payment"), () => { erpnext.bulk_transaction_processing.create(listview, "Sales Order", "Payment Entry"); }); - - } + }, }; diff --git a/erpnext/selling/doctype/sales_partner_type/sales_partner_type.js b/erpnext/selling/doctype/sales_partner_type/sales_partner_type.js index 3e183f6e6fcd..ac5a8134f3cc 100644 --- a/erpnext/selling/doctype/sales_partner_type/sales_partner_type.js +++ b/erpnext/selling/doctype/sales_partner_type/sales_partner_type.js @@ -1,8 +1,6 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Sales Partner Type', { - refresh: function() { - - } +frappe.ui.form.on("Sales Partner Type", { + refresh: function () {}, }); diff --git a/erpnext/selling/doctype/selling_settings/selling_settings.js b/erpnext/selling/doctype/selling_settings/selling_settings.js index cf6fb2806eef..4471458fb108 100644 --- a/erpnext/selling/doctype/selling_settings/selling_settings.js +++ b/erpnext/selling/doctype/selling_settings/selling_settings.js @@ -1,8 +1,6 @@ // Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Selling Settings', { - refresh: function(frm) { - - } +frappe.ui.form.on("Selling Settings", { + refresh: function (frm) {}, }); diff --git a/erpnext/selling/doctype/sms_center/sms_center.js b/erpnext/selling/doctype/sms_center/sms_center.js index 974cfc79181e..f513213e71c9 100644 --- a/erpnext/selling/doctype/sms_center/sms_center.js +++ b/erpnext/selling/doctype/sms_center/sms_center.js @@ -8,10 +8,10 @@ extend_cscript(cur_frm.cscript, { if (total_characters > 160) { total_msg = cint(total_characters / 160); - total_msg = (total_characters % 160 == 0 ? total_msg : total_msg + 1); + total_msg = total_characters % 160 == 0 ? total_msg : total_msg + 1; } this.frm.set_value("total_characters", total_characters); this.frm.set_value("total_messages", this.frm.doc.message ? total_msg : 0); - } + }, }); diff --git a/erpnext/selling/page/point_of_sale/point_of_sale.js b/erpnext/selling/page/point_of_sale/point_of_sale.js index 6db4150be942..6e4d1d0a3732 100644 --- a/erpnext/selling/page/point_of_sale/point_of_sale.js +++ b/erpnext/selling/page/point_of_sale/point_of_sale.js @@ -1,19 +1,19 @@ -frappe.provide('erpnext.PointOfSale'); +frappe.provide("erpnext.PointOfSale"); -frappe.pages['point-of-sale'].on_page_load = function(wrapper) { +frappe.pages["point-of-sale"].on_page_load = function (wrapper) { frappe.ui.make_app_page({ parent: wrapper, - title: __('Point of Sale'), - single_column: true + title: __("Point of Sale"), + single_column: true, }); - frappe.require('point-of-sale.bundle.js', function() { + frappe.require("point-of-sale.bundle.js", function () { wrapper.pos = new erpnext.PointOfSale.Controller(wrapper); window.cur_pos = wrapper.pos; }); }; -frappe.pages['point-of-sale'].refresh = function(wrapper) { +frappe.pages["point-of-sale"].refresh = function (wrapper) { if (document.scannerDetectionData) { onScan.detachFrom(document); wrapper.pos.wrapper.html(""); diff --git a/erpnext/selling/page/point_of_sale/pos_controller.js b/erpnext/selling/page/point_of_sale/pos_controller.js index 07b1c2eb7ee1..3d42f3ea23fa 100644 --- a/erpnext/selling/page/point_of_sale/pos_controller.js +++ b/erpnext/selling/page/point_of_sale/pos_controller.js @@ -1,13 +1,15 @@ erpnext.PointOfSale.Controller = class { constructor(wrapper) { - this.wrapper = $(wrapper).find('.layout-main-section'); + this.wrapper = $(wrapper).find(".layout-main-section"); this.page = wrapper.page; this.check_opening_entry(); } fetch_opening_entry() { - return frappe.call("erpnext.selling.page.point_of_sale.point_of_sale.check_opening_entry", { "user": frappe.session.user }); + return frappe.call("erpnext.selling.page.point_of_sale.point_of_sale.check_opening_entry", { + user: frappe.session.user, + }); } check_opening_entry() { @@ -25,50 +27,62 @@ erpnext.PointOfSale.Controller = class { const me = this; const table_fields = [ { - fieldname: "mode_of_payment", fieldtype: "Link", - in_list_view: 1, label: "Mode of Payment", - options: "Mode of Payment", reqd: 1 + fieldname: "mode_of_payment", + fieldtype: "Link", + in_list_view: 1, + label: "Mode of Payment", + options: "Mode of Payment", + reqd: 1, }, { - fieldname: "opening_amount", fieldtype: "Currency", - in_list_view: 1, label: "Opening Amount", + fieldname: "opening_amount", + fieldtype: "Currency", + in_list_view: 1, + label: "Opening Amount", options: "company:company_currency", change: function () { - dialog.fields_dict.balance_details.df.data.some(d => { + dialog.fields_dict.balance_details.df.data.some((d) => { if (d.idx == this.doc.idx) { d.opening_amount = this.value; dialog.fields_dict.balance_details.grid.refresh(); return true; } }); - } - } + }, + }, ]; const fetch_pos_payment_methods = () => { const pos_profile = dialog.fields_dict.pos_profile.get_value(); if (!pos_profile) return; frappe.db.get_doc("POS Profile", pos_profile).then(({ payments }) => { dialog.fields_dict.balance_details.df.data = []; - payments.forEach(pay => { + payments.forEach((pay) => { const { mode_of_payment } = pay; - dialog.fields_dict.balance_details.df.data.push({ mode_of_payment, opening_amount: '0' }); + dialog.fields_dict.balance_details.df.data.push({ mode_of_payment, opening_amount: "0" }); }); dialog.fields_dict.balance_details.grid.refresh(); }); - } + }; const dialog = new frappe.ui.Dialog({ - title: __('Create POS Opening Entry'), + title: __("Create POS Opening Entry"), static: true, fields: [ { - fieldtype: 'Link', label: __('Company'), default: frappe.defaults.get_default('company'), - options: 'Company', fieldname: 'company', reqd: 1 + fieldtype: "Link", + label: __("Company"), + default: frappe.defaults.get_default("company"), + options: "Company", + fieldname: "company", + reqd: 1, }, { - fieldtype: 'Link', label: __('POS Profile'), - options: 'POS Profile', fieldname: 'pos_profile', reqd: 1, + fieldtype: "Link", + label: __("POS Profile"), + options: "POS Profile", + fieldname: "pos_profile", + reqd: 1, get_query: () => pos_profile_query(), - onchange: () => fetch_pos_payment_methods() + onchange: () => fetch_pos_payment_methods(), }, { fieldname: "balance_details", @@ -78,34 +92,38 @@ erpnext.PointOfSale.Controller = class { in_place_edit: true, reqd: 1, data: [], - fields: table_fields - } + fields: table_fields, + }, ], - primary_action: async function({ company, pos_profile, balance_details }) { + primary_action: async function ({ company, pos_profile, balance_details }) { if (!balance_details.length) { frappe.show_alert({ message: __("Please add Mode of payments and opening balance details."), - indicator: 'red' - }) + indicator: "red", + }); return frappe.utils.play_sound("error"); } // filter balance details for empty rows - balance_details = balance_details.filter(d => d.mode_of_payment); + balance_details = balance_details.filter((d) => d.mode_of_payment); const method = "erpnext.selling.page.point_of_sale.point_of_sale.create_opening_voucher"; - const res = await frappe.call({ method, args: { pos_profile, company, balance_details }, freeze:true }); + const res = await frappe.call({ + method, + args: { pos_profile, company, balance_details }, + freeze: true, + }); !res.exc && me.prepare_app_defaults(res.message); dialog.hide(); }, - primary_action_label: __('Submit') + primary_action_label: __("Submit"), }); dialog.show(); const pos_profile_query = () => { return { - query: 'erpnext.accounts.doctype.pos_profile.pos_profile.pos_profile_query', - filters: { company: dialog.fields_dict.company.get_value() } - } + query: "erpnext.accounts.doctype.pos_profile.pos_profile.pos_profile_query", + filters: { company: dialog.fields_dict.company.get_value() }, + }; }; } @@ -117,19 +135,19 @@ erpnext.PointOfSale.Controller = class { this.item_stock_map = {}; this.settings = {}; - frappe.db.get_value('Stock Settings', undefined, 'allow_negative_stock').then(({ message }) => { + frappe.db.get_value("Stock Settings", undefined, "allow_negative_stock").then(({ message }) => { this.allow_negative_stock = flt(message.allow_negative_stock) || false; }); frappe.call({ method: "erpnext.selling.page.point_of_sale.point_of_sale.get_pos_profile_data", - args: { "pos_profile": this.pos_profile }, + args: { pos_profile: this.pos_profile }, callback: (res) => { const profile = res.message; Object.assign(this.settings, profile); - this.settings.customer_groups = profile.customer_groups.map(group => group.name); + this.settings.customer_groups = profile.customer_groups.map((group) => group.name); this.make_app(); - } + }, }); } @@ -139,7 +157,8 @@ erpnext.PointOfSale.Controller = class { Opened at ${moment(this.pos_opening_time).format("Do MMMM, h:mma")} - `); + ` + ); } make_app() { @@ -150,11 +169,9 @@ erpnext.PointOfSale.Controller = class { } prepare_dom() { - this.wrapper.append( - `
              ` - ); + this.wrapper.append(`
              `); - this.$components_wrapper = this.wrapper.find('.point-of-sale-app'); + this.$components_wrapper = this.wrapper.find(".point-of-sale-app"); } prepare_components() { @@ -169,13 +186,18 @@ erpnext.PointOfSale.Controller = class { prepare_menu() { this.page.clear_menu(); - this.page.add_menu_item(__("Open Form View"), this.open_form_view.bind(this), false, 'Ctrl+F'); + this.page.add_menu_item(__("Open Form View"), this.open_form_view.bind(this), false, "Ctrl+F"); - this.page.add_menu_item(__("Toggle Recent Orders"), this.toggle_recent_order.bind(this), false, 'Ctrl+O'); + this.page.add_menu_item( + __("Toggle Recent Orders"), + this.toggle_recent_order.bind(this), + false, + "Ctrl+O" + ); - this.page.add_menu_item(__("Save as Draft"), this.save_draft_invoice.bind(this), false, 'Ctrl+S'); + this.page.add_menu_item(__("Save as Draft"), this.save_draft_invoice.bind(this), false, "Ctrl+S"); - this.page.add_menu_item(__('Close the POS'), this.close_pos.bind(this), false, 'Shift+Ctrl+C'); + this.page.add_menu_item(__("Close the POS"), this.close_pos.bind(this), false, "Shift+Ctrl+C"); } open_form_view() { @@ -184,7 +206,7 @@ erpnext.PointOfSale.Controller = class { } toggle_recent_order() { - const show = this.recent_order_list.$component.is(':hidden'); + const show = this.recent_order_list.$component.is(":hidden"); this.toggle_recent_order_list(show); } @@ -194,38 +216,40 @@ erpnext.PointOfSale.Controller = class { if (this.frm.doc.items.length == 0) { frappe.show_alert({ message: __("You must add atleast one item to save it as draft."), - indicator:'red' + indicator: "red", }); frappe.utils.play_sound("error"); return; } - this.frm.save(undefined, undefined, undefined, () => { - frappe.show_alert({ - message: __("There was an error saving the document."), - indicator: 'red' + this.frm + .save(undefined, undefined, undefined, () => { + frappe.show_alert({ + message: __("There was an error saving the document."), + indicator: "red", + }); + frappe.utils.play_sound("error"); + }) + .then(() => { + frappe.run_serially([ + () => frappe.dom.freeze(), + () => this.make_new_invoice(), + () => frappe.dom.unfreeze(), + ]); }); - frappe.utils.play_sound("error"); - }).then(() => { - frappe.run_serially([ - () => frappe.dom.freeze(), - () => this.make_new_invoice(), - () => frappe.dom.unfreeze(), - ]); - }); } close_pos() { if (!this.$components_wrapper.is(":visible")) return; - let voucher = frappe.model.get_new_doc('POS Closing Entry'); + let voucher = frappe.model.get_new_doc("POS Closing Entry"); voucher.pos_profile = this.frm.doc.pos_profile; voucher.user = frappe.session.user; voucher.company = this.frm.doc.company; voucher.pos_opening_entry = this.pos_opening; voucher.period_end_date = frappe.datetime.now_datetime(); voucher.posting_date = frappe.datetime.now_date(); - frappe.set_route('Form', 'POS Closing Entry', voucher.name); + frappe.set_route("Form", "POS Closing Entry", voucher.name); } init_item_selector() { @@ -234,11 +258,11 @@ erpnext.PointOfSale.Controller = class { pos_profile: this.pos_profile, settings: this.settings, events: { - item_selected: args => this.on_cart_update(args), + item_selected: (args) => this.on_cart_update(args), - get_frm: () => this.frm || {} - } - }) + get_frm: () => this.frm || {}, + }, + }); } init_item_cart() { @@ -263,9 +287,9 @@ erpnext.PointOfSale.Controller = class { this.customer_details = details; // will add/remove LP payment method this.payment.render_loyalty_points_payment_mode(); - } - } - }) + }, + }, + }); } init_item_details() { @@ -286,7 +310,7 @@ erpnext.PointOfSale.Controller = class { const args = { field, value, - item: this.item_details.current_item + item: this.item_details.current_item, }; return this.on_cart_update(args); } @@ -303,24 +327,28 @@ erpnext.PointOfSale.Controller = class { this.cart.toggle_numpad_field_edit(fieldname); }, set_value_in_current_cart_item: (selector, value) => { - this.cart.update_selector_value_in_cart_item(selector, value, this.item_details.current_item); + this.cart.update_selector_value_in_cart_item( + selector, + value, + this.item_details.current_item + ); }, clone_new_batch_item_in_frm: (batch_serial_map, item) => { // called if serial nos are 'auto_selected' and if those serial nos belongs to multiple batches // for each unique batch new item row is added in the form & cart - Object.keys(batch_serial_map).forEach(batch => { - const item_to_clone = this.frm.doc.items.find(i => i.name == item.name); + Object.keys(batch_serial_map).forEach((batch) => { + const item_to_clone = this.frm.doc.items.find((i) => i.name == item.name); const new_row = this.frm.add_child("items", { ...item_to_clone }); // update new serialno and batch new_row.batch_no = batch; new_row.serial_no = batch_serial_map[batch].join(`\n`); new_row.qty = batch_serial_map[batch].length; - this.frm.doc.items.forEach(row => { + this.frm.doc.items.forEach((row) => { if (item.item_code === row.item_code) { this.update_cart_html(row); } }); - }) + }); }, remove_item_from_cart: () => this.remove_item_from_cart(), get_item_stock_map: () => this.item_stock_map, @@ -329,8 +357,8 @@ erpnext.PointOfSale.Controller = class { this.cart.prev_action = null; this.cart.toggle_item_highlight(); }, - get_available_stock: (item_code, warehouse) => this.get_available_stock(item_code, warehouse) - } + get_available_stock: (item_code, warehouse) => this.get_available_stock(item_code, warehouse), + }, }); } @@ -344,7 +372,9 @@ erpnext.PointOfSale.Controller = class { toggle_other_sections: (show) => { if (show) { - this.item_details.$component.is(':visible') ? this.item_details.$component.css('display', 'none') : ''; + this.item_details.$component.is(":visible") + ? this.item_details.$component.css("display", "none") + : ""; this.item_selector.toggle_component(false); } else { this.item_selector.toggle_component(true); @@ -352,18 +382,17 @@ erpnext.PointOfSale.Controller = class { }, submit_invoice: () => { - this.frm.savesubmit() - .then((r) => { - this.toggle_components(false); - this.order_summary.toggle_component(true); - this.order_summary.load_summary_of(this.frm.doc, true); - frappe.show_alert({ - indicator: 'green', - message: __('POS invoice {0} created succesfully', [r.doc.name]) - }); + this.frm.savesubmit().then((r) => { + this.toggle_components(false); + this.order_summary.toggle_component(true); + this.order_summary.load_summary_of(this.frm.doc, true); + frappe.show_alert({ + indicator: "green", + message: __("POS invoice {0} created succesfully", [r.doc.name]), }); - } - } + }); + }, + }, }); } @@ -372,13 +401,13 @@ erpnext.PointOfSale.Controller = class { wrapper: this.$components_wrapper, events: { open_invoice_data: (name) => { - frappe.db.get_doc('POS Invoice', name).then((doc) => { + frappe.db.get_doc("POS Invoice", name).then((doc) => { this.order_summary.load_summary_of(doc); }); }, - reset_summary: () => this.order_summary.toggle_summary_placeholder(true) - } - }) + reset_summary: () => this.order_summary.toggle_summary_placeholder(true), + }, + }); } init_order_summary() { @@ -389,11 +418,11 @@ erpnext.PointOfSale.Controller = class { process_return: (name) => { this.recent_order_list.toggle_component(false); - frappe.db.get_doc('POS Invoice', name).then((doc) => { + frappe.db.get_doc("POS Invoice", name).then((doc) => { frappe.run_serially([ () => this.make_return_invoice(doc), () => this.cart.load_invoice(), - () => this.item_selector.toggle_component(true) + () => this.item_selector.toggle_component(true), ]); }); }, @@ -401,9 +430,9 @@ erpnext.PointOfSale.Controller = class { this.recent_order_list.toggle_component(false); frappe.run_serially([ () => this.frm.refresh(name), - () => this.frm.call('reset_mode_of_payments'), + () => this.frm.call("reset_mode_of_payments"), () => this.cart.load_invoice(), - () => this.item_selector.toggle_component(true) + () => this.item_selector.toggle_component(true), ]); }, delete_order: (name) => { @@ -418,9 +447,9 @@ erpnext.PointOfSale.Controller = class { () => this.item_selector.toggle_component(true), () => frappe.dom.unfreeze(), ]); - } - } - }) + }, + }, + }); } toggle_recent_order_list(show) { @@ -434,7 +463,7 @@ erpnext.PointOfSale.Controller = class { this.item_selector.toggle_component(show); // do not show item details or payment if recent order is toggled off - !show ? (this.item_details.toggle_component(false) || this.payment.toggle_component(false)) : ''; + !show ? this.item_details.toggle_component(false) || this.payment.toggle_component(false) : ""; } make_new_invoice() { @@ -444,23 +473,23 @@ erpnext.PointOfSale.Controller = class { () => this.set_pos_profile_data(), () => this.set_pos_profile_status(), () => this.cart.load_invoice(), - () => frappe.dom.unfreeze() + () => frappe.dom.unfreeze(), ]); } make_sales_invoice_frm() { - const doctype = 'POS Invoice'; - return new Promise(resolve => { + const doctype = "POS Invoice"; + return new Promise((resolve) => { if (this.frm) { this.frm = this.get_new_frm(this.frm); this.frm.doc.items = []; - this.frm.doc.is_pos = 1 + this.frm.doc.is_pos = 1; resolve(); } else { frappe.model.with_doctype(doctype, () => { this.frm = this.get_new_frm(); this.frm.doc.items = []; - this.frm.doc.is_pos = 1 + this.frm.doc.is_pos = 1; resolve(); }); } @@ -468,8 +497,8 @@ erpnext.PointOfSale.Controller = class { } get_new_frm(_frm) { - const doctype = 'POS Invoice'; - const page = $('
              '); + const doctype = "POS Invoice"; + const page = $("
              "); const frm = _frm || new frappe.ui.form.Form(doctype, page, false); const name = frappe.model.make_new_doc_and_get_name(doctype, true); frm.refresh(name); @@ -484,8 +513,8 @@ erpnext.PointOfSale.Controller = class { return frappe.call({ method: "erpnext.accounts.doctype.pos_invoice.pos_invoice.make_sales_return", args: { - 'source_name': doc.name, - 'target_doc': this.frm.doc + source_name: doc.name, + target_doc: this.frm.doc, }, callback: (r) => { frappe.model.sync(r.message); @@ -493,13 +522,16 @@ erpnext.PointOfSale.Controller = class { this.set_pos_profile_data().then(() => { frappe.dom.unfreeze(); }); - } + }, }); } set_pos_profile_data() { if (this.company && !this.frm.doc.company) this.frm.doc.company = this.company; - if ((this.pos_profile && !this.frm.doc.pos_profile) | (this.frm.doc.is_return && this.pos_profile != this.frm.doc.pos_profile)) { + if ( + (this.pos_profile && !this.frm.doc.pos_profile) | + (this.frm.doc.is_return && this.pos_profile != this.frm.doc.pos_profile) + ) { this.frm.doc.pos_profile = this.pos_profile; } @@ -520,16 +552,15 @@ erpnext.PointOfSale.Controller = class { item_row = this.get_item_from_frm(item); const item_row_exists = !$.isEmptyObject(item_row); - const from_selector = field === 'qty' && value === "+1"; - if (from_selector) - value = flt(item_row.stock_qty) + flt(value); + const from_selector = field === "qty" && value === "+1"; + if (from_selector) value = flt(item_row.stock_qty) + flt(value); if (item_row_exists) { - if (field === 'qty') - value = flt(value); + if (field === "qty") value = flt(value); - if (['qty', 'conversion_factor'].includes(field) && value > 0 && !this.allow_negative_stock) { - const qty_needed = field === 'qty' ? value * item_row.conversion_factor : item_row.qty * value; + if (["qty", "conversion_factor"].includes(field) && value > 0 && !this.allow_negative_stock) { + const qty_needed = + field === "qty" ? value * item_row.conversion_factor : item_row.qty * value; await this.check_stock_availability(item_row, qty_needed, this.frm.doc.set_warehouse); } @@ -537,29 +568,25 @@ erpnext.PointOfSale.Controller = class { await frappe.model.set_value(item_row.doctype, item_row.name, field, value); this.update_cart_html(item_row); } - } else { - if (!this.frm.doc.customer) - return this.raise_customer_selection_alert(); + if (!this.frm.doc.customer) return this.raise_customer_selection_alert(); const { item_code, batch_no, serial_no, rate } = item; - if (!item_code) - return; + if (!item_code) return; const new_item = { item_code, batch_no, rate, [field]: value }; if (serial_no) { await this.check_serial_no_availablilty(item_code, this.frm.doc.set_warehouse, serial_no); - new_item['serial_no'] = serial_no; + new_item["serial_no"] = serial_no; } - if (field === 'serial_no') - new_item['qty'] = value.split(`\n`).length || 0; + if (field === "serial_no") new_item["qty"] = value.split(`\n`).length || 0; - item_row = this.frm.add_child('items', new_item); + item_row = this.frm.add_child("items", new_item); - if (field === 'qty' && value !== 0 && !this.allow_negative_stock) { + if (field === "qty" && value !== 0 && !this.allow_negative_stock) { const qty_needed = value * item_row.conversion_factor; await this.check_stock_availability(item_row, qty_needed, this.frm.doc.set_warehouse); } @@ -568,13 +595,14 @@ erpnext.PointOfSale.Controller = class { this.update_cart_html(item_row); - if (this.item_details.$component.is(':visible')) - this.edit_item_details_of(item_row); + if (this.item_details.$component.is(":visible")) this.edit_item_details_of(item_row); - if (this.check_serial_batch_selection_needed(item_row) && !this.item_details.$component.is(':visible')) + if ( + this.check_serial_batch_selection_needed(item_row) && + !this.item_details.$component.is(":visible") + ) this.edit_item_details_of(item_row); } - } catch (error) { console.log(error); } finally { @@ -586,8 +614,8 @@ erpnext.PointOfSale.Controller = class { raise_customer_selection_alert() { frappe.dom.unfreeze(); frappe.show_alert({ - message: __('You must select a customer before adding an item.'), - indicator: 'orange' + message: __("You must select a customer before adding an item."), + indicator: "orange", }); frappe.utils.play_sound("error"); } @@ -595,17 +623,18 @@ erpnext.PointOfSale.Controller = class { get_item_from_frm({ name, item_code, batch_no, uom, rate }) { let item_row = null; if (name) { - item_row = this.frm.doc.items.find(i => i.name == name); + item_row = this.frm.doc.items.find((i) => i.name == name); } else { // if item is clicked twice from item selector // then "item_code, batch_no, uom, rate" will help in getting the exact item // to increase the qty by one const has_batch_no = batch_no; item_row = this.frm.doc.items.find( - i => i.item_code === item_code - && (!has_batch_no || (has_batch_no && i.batch_no === batch_no)) - && (i.uom === uom) - && (i.rate == rate) + (i) => + i.item_code === item_code && + (!has_batch_no || (has_batch_no && i.batch_no === batch_no)) && + i.uom === uom && + i.rate == rate ); } @@ -633,16 +662,19 @@ erpnext.PointOfSale.Controller = class { const no_serial_selected = !item_row.serial_no; const no_batch_selected = !item_row.batch_no; - if ((serialized && no_serial_selected) || (batched && no_batch_selected) || - (serialized && batched && (no_batch_selected || no_serial_selected))) { + if ( + (serialized && no_serial_selected) || + (batched && no_batch_selected) || + (serialized && batched && (no_batch_selected || no_serial_selected)) + ) { return true; } return false; } async trigger_new_item_events(item_row) { - await this.frm.script_manager.trigger('item_code', item_row.doctype, item_row.name); - await this.frm.script_manager.trigger('qty', item_row.doctype, item_row.name); + await this.frm.script_manager.trigger("item_code", item_row.doctype, item_row.name); + await this.frm.script_manager.trigger("qty", item_row.doctype, item_row.name); } async check_stock_availability(item_row, qty_needed, warehouse) { @@ -653,21 +685,27 @@ erpnext.PointOfSale.Controller = class { frappe.dom.unfreeze(); const bold_item_code = item_row.item_code.bold(); const bold_warehouse = warehouse.bold(); - const bold_available_qty = available_qty.toString().bold() + const bold_available_qty = available_qty.toString().bold(); if (!(available_qty > 0)) { if (is_stock_item) { frappe.model.clear_doc(item_row.doctype, item_row.name); frappe.throw({ title: __("Not Available"), - message: __('Item Code: {0} is not available under warehouse {1}.', [bold_item_code, bold_warehouse]) + message: __("Item Code: {0} is not available under warehouse {1}.", [ + bold_item_code, + bold_warehouse, + ]), }); } else { return; } } else if (is_stock_item && available_qty < qty_needed) { frappe.throw({ - message: __('Stock quantity not enough for Item Code: {0} under warehouse {1}. Available quantity {2}.', [bold_item_code, bold_warehouse, bold_available_qty]), - indicator: 'orange' + message: __( + "Stock quantity not enough for Item Code: {0} under warehouse {1}. Available quantity {2}.", + [bold_item_code, bold_warehouse, bold_available_qty] + ), + indicator: "orange", }); frappe.utils.play_sound("error"); } @@ -676,13 +714,15 @@ erpnext.PointOfSale.Controller = class { async check_serial_no_availablilty(item_code, warehouse, serial_no) { const method = "erpnext.stock.doctype.serial_no.serial_no.get_pos_reserved_serial_nos"; - const args = {filters: { item_code, warehouse }} + const args = { filters: { item_code, warehouse } }; const res = await frappe.call({ method, args }); if (res.message.includes(serial_no)) { frappe.throw({ title: __("Not Available"), - message: __('Serial No: {0} has already been transacted into another POS Invoice.', [serial_no.bold()]) + message: __("Serial No: {0} has already been transacted into another POS Invoice.", [ + serial_no.bold(), + ]), }); } } @@ -692,21 +732,20 @@ erpnext.PointOfSale.Controller = class { return frappe.call({ method: "erpnext.accounts.doctype.pos_invoice.pos_invoice.get_stock_availability", args: { - 'item_code': item_code, - 'warehouse': warehouse, + item_code: item_code, + warehouse: warehouse, }, callback(res) { - if (!me.item_stock_map[item_code]) - me.item_stock_map[item_code] = {}; + if (!me.item_stock_map[item_code]) me.item_stock_map[item_code] = {}; me.item_stock_map[item_code][warehouse] = res.message; - } + }, }); } update_item_field(value, field_or_action) { - if (field_or_action === 'checkout') { + if (field_or_action === "checkout") { this.item_details.toggle_item_details_section(null); - } else if (field_or_action === 'remove') { + } else if (field_or_action === "remove") { this.remove_item_from_cart(); } else { const field_control = this.item_details[`${field_or_action}_control`]; @@ -720,26 +759,28 @@ erpnext.PointOfSale.Controller = class { frappe.dom.freeze(); const { doctype, name, current_item } = this.item_details; - return frappe.model.set_value(doctype, name, 'qty', 0) + return frappe.model + .set_value(doctype, name, "qty", 0) .then(() => { frappe.model.clear_doc(doctype, name); this.update_cart_html(current_item, true); this.item_details.toggle_item_details_section(null); frappe.dom.unfreeze(); }) - .catch(e => console.log(e)); + .catch((e) => console.log(e)); } async save_and_checkout() { if (this.frm.is_dirty()) { let save_error = false; - await this.frm.save(null, null, null, () => save_error = true); + await this.frm.save(null, null, null, () => (save_error = true)); // only move to payment section if save is successful !save_error && this.payment.checkout(); // show checkout button on error - save_error && setTimeout(() => { - this.cart.toggle_checkout_btn(true); - }, 300); // wait for save to finish + save_error && + setTimeout(() => { + this.cart.toggle_checkout_btn(true); + }, 300); // wait for save to finish } else { this.payment.checkout(); } diff --git a/erpnext/selling/page/point_of_sale/pos_item_cart.js b/erpnext/selling/page/point_of_sale/pos_item_cart.js index eacf480ef8fd..08bebd112529 100644 --- a/erpnext/selling/page/point_of_sale/pos_item_cart.js +++ b/erpnext/selling/page/point_of_sale/pos_item_cart.js @@ -18,11 +18,9 @@ erpnext.PointOfSale.ItemCart = class { } prepare_dom() { - this.wrapper.append( - `
              ` - ) + this.wrapper.append(`
              `); - this.$component = this.wrapper.find('.customer-cart-container'); + this.$component = this.wrapper.find(".customer-cart-container"); } init_child_components() { @@ -31,16 +29,14 @@ erpnext.PointOfSale.ItemCart = class { } init_customer_selector() { - this.$component.append( - `
              ` - ) - this.$customer_section = this.$component.find('.customer-section'); + this.$component.append(`
              `); + this.$customer_section = this.$component.find(".customer-section"); this.make_customer_selector(); } reset_customer_selector() { const frm = this.events.get_frm(); - frm.set_value('customer', ''); + frm.set_value("customer", ""); this.make_customer_selector(); this.customer_field.set_focus(); } @@ -49,11 +45,11 @@ erpnext.PointOfSale.ItemCart = class { this.$component.append( `
              -
              ${__('Item Cart')}
              +
              ${__("Item Cart")}
              -
              ${__('Item')}
              -
              ${__('Quantity')}
              -
              ${__('Amount')}
              +
              ${__("Item")}
              +
              ${__("Quantity")}
              +
              ${__("Amount")}
              @@ -61,7 +57,7 @@ erpnext.PointOfSale.ItemCart = class {
              ` ); - this.$cart_container = this.$component.find('.cart-container'); + this.$cart_container = this.$component.find(".cart-container"); this.make_cart_totals_section(); this.make_cart_items_section(); @@ -69,39 +65,35 @@ erpnext.PointOfSale.ItemCart = class { } make_cart_items_section() { - this.$cart_header = this.$component.find('.cart-header'); - this.$cart_items_wrapper = this.$component.find('.cart-items-section'); + this.$cart_header = this.$component.find(".cart-header"); + this.$cart_items_wrapper = this.$component.find(".cart-items-section"); this.make_no_items_placeholder(); } make_no_items_placeholder() { - this.$cart_header.css('display', 'none'); - this.$cart_items_wrapper.html( - `
              ${__('No items in cart')}
              ` - ); + this.$cart_header.css("display", "none"); + this.$cart_items_wrapper.html(`
              ${__("No items in cart")}
              `); } get_discount_icon() { - return ( - ` + return ` - ` - ); + `; } make_cart_totals_section() { - this.$totals_section = this.$component.find('.cart-totals-section'); + this.$totals_section = this.$component.find(".cart-totals-section"); this.$totals_section.append( `
              - ${this.get_discount_icon()} ${__('Add Discount')} + ${this.get_discount_icon()} ${__("Add Discount")}
              -
              ${__('Total Items')}
              +
              ${__("Total Items")}
              0.00
              @@ -110,39 +102,39 @@ erpnext.PointOfSale.ItemCart = class {
              -
              ${__('Grand Total')}
              +
              ${__("Grand Total")}
              0.00
              -
              ${__('Checkout')}
              -
              ${__('Edit Cart')}
              ` - ) +
              ${__("Checkout")}
              +
              ${__("Edit Cart")}
              ` + ); this.$add_discount_elem = this.$component.find(".add-discount-wrapper"); } make_cart_numpad() { - this.$numpad_section = this.$component.find('.numpad-section'); + this.$numpad_section = this.$component.find(".numpad-section"); this.number_pad = new erpnext.PointOfSale.NumberPad({ wrapper: this.$numpad_section, events: { - numpad_event: this.on_numpad_event.bind(this) + numpad_event: this.on_numpad_event.bind(this), }, cols: 5, keys: [ - [ 1, 2, 3, 'Quantity' ], - [ 4, 5, 6, 'Discount' ], - [ 7, 8, 9, 'Rate' ], - [ '.', 0, 'Delete', 'Remove' ] + [1, 2, 3, "Quantity"], + [4, 5, 6, "Discount"], + [7, 8, 9, "Rate"], + [".", 0, "Delete", "Remove"], ], css_classes: [ - [ '', '', '', 'col-span-2' ], - [ '', '', '', 'col-span-2' ], - [ '', '', '', 'col-span-2' ], - [ '', '', '', 'col-span-2 remove-btn' ] + ["", "", "", "col-span-2"], + ["", "", "", "col-span-2"], + ["", "", "", "col-span-2"], + ["", "", "", "col-span-2 remove-btn"], ], - fieldnames_map: { 'Quantity': 'qty', 'Discount': 'discount_percentage' } - }) + fieldnames_map: { Quantity: "qty", Discount: "discount_percentage" }, + }); this.$numpad_section.prepend( `
              @@ -150,49 +142,49 @@ erpnext.PointOfSale.ItemCart = class {
              ` - ) + ); this.$numpad_section.append( - `
              ${__('Checkout')}
              ` - ) + `
              ${__("Checkout")}
              ` + ); } bind_events() { const me = this; - this.$customer_section.on('click', '.reset-customer-btn', function () { + this.$customer_section.on("click", ".reset-customer-btn", function () { me.reset_customer_selector(); }); - this.$customer_section.on('click', '.close-details-btn', function () { + this.$customer_section.on("click", ".close-details-btn", function () { me.toggle_customer_info(false); }); - this.$customer_section.on('click', '.customer-display', function(e) { - if ($(e.target).closest('.reset-customer-btn').length) return; + this.$customer_section.on("click", ".customer-display", function (e) { + if ($(e.target).closest(".reset-customer-btn").length) return; - const show = me.$cart_container.is(':visible'); + const show = me.$cart_container.is(":visible"); me.toggle_customer_info(show); }); - this.$cart_items_wrapper.on('click', '.cart-item-wrapper', function() { + this.$cart_items_wrapper.on("click", ".cart-item-wrapper", function () { const $cart_item = $(this); me.toggle_item_highlight(this); - const payment_section_hidden = !me.$totals_section.find('.edit-cart-btn').is(':visible'); + const payment_section_hidden = !me.$totals_section.find(".edit-cart-btn").is(":visible"); if (!payment_section_hidden) { // payment section is visible // edit cart first and then open item details section me.$totals_section.find(".edit-cart-btn").click(); } - const item_row_name = unescape($cart_item.attr('data-row-name')); + const item_row_name = unescape($cart_item.attr("data-row-name")); me.events.cart_item_clicked({ name: item_row_name }); - this.numpad_value = ''; + this.numpad_value = ""; }); - this.$component.on('click', '.checkout-btn', async function() { - if ($(this).attr('style').indexOf('--blue-500') == -1) return; + this.$component.on("click", ".checkout-btn", async function () { + if ($(this).attr("style").indexOf("--blue-500") == -1) return; await me.events.checkout(); me.toggle_checkout_btn(false); @@ -200,18 +192,18 @@ erpnext.PointOfSale.ItemCart = class { me.allow_discount_change && me.$add_discount_elem.removeClass("d-none"); }); - this.$totals_section.on('click', '.edit-cart-btn', () => { + this.$totals_section.on("click", ".edit-cart-btn", () => { this.events.edit_cart(); this.toggle_checkout_btn(true); }); - this.$component.on('click', '.add-discount-wrapper', () => { - const can_edit_discount = this.$add_discount_elem.find('.edit-discount-btn').length; + this.$component.on("click", ".add-discount-wrapper", () => { + const can_edit_discount = this.$add_discount_elem.find(".edit-discount-btn").length; - if(!this.discount_field || can_edit_discount) this.show_discount_control(); + if (!this.discount_field || can_edit_discount) this.show_discount_control(); }); - frappe.ui.form.on("POS Invoice", "paid_amount", frm => { + frappe.ui.form.on("POS Invoice", "paid_amount", (frm) => { // called when discount is applied this.update_totals_section(frm); }); @@ -220,43 +212,49 @@ erpnext.PointOfSale.ItemCart = class { attach_shortcuts() { for (let row of this.number_pad.keys) { for (let btn of row) { - if (typeof btn !== 'string') continue; // do not make shortcuts for numbers + if (typeof btn !== "string") continue; // do not make shortcuts for numbers let shortcut_key = `ctrl+${frappe.scrub(String(btn))[0]}`; - if (btn === 'Delete') shortcut_key = 'ctrl+backspace'; - if (btn === 'Remove') shortcut_key = 'shift+ctrl+backspace' - if (btn === '.') shortcut_key = 'ctrl+>'; + if (btn === "Delete") shortcut_key = "ctrl+backspace"; + if (btn === "Remove") shortcut_key = "shift+ctrl+backspace"; + if (btn === ".") shortcut_key = "ctrl+>"; // to account for fieldname map - const fieldname = this.number_pad.fieldnames[btn] ? this.number_pad.fieldnames[btn] : - typeof btn === 'string' ? frappe.scrub(btn) : btn; - - let shortcut_label = shortcut_key.split('+').map(frappe.utils.to_title_case).join('+'); - shortcut_label = frappe.utils.is_mac() ? shortcut_label.replace('Ctrl', '⌘') : shortcut_label; - this.$numpad_section.find(`.numpad-btn[data-button-value="${fieldname}"]`).attr("title", shortcut_label); + const fieldname = this.number_pad.fieldnames[btn] + ? this.number_pad.fieldnames[btn] + : typeof btn === "string" + ? frappe.scrub(btn) + : btn; + + let shortcut_label = shortcut_key.split("+").map(frappe.utils.to_title_case).join("+"); + shortcut_label = frappe.utils.is_mac() ? shortcut_label.replace("Ctrl", "⌘") : shortcut_label; + this.$numpad_section + .find(`.numpad-btn[data-button-value="${fieldname}"]`) + .attr("title", shortcut_label); frappe.ui.keys.on(`${shortcut_key}`, () => { const cart_is_visible = this.$component.is(":visible"); if (cart_is_visible && this.item_is_selected && this.$numpad_section.is(":visible")) { this.$numpad_section.find(`.numpad-btn[data-button-value="${fieldname}"]`).click(); } - }) + }); } } - const ctrl_label = frappe.utils.is_mac() ? '⌘' : 'Ctrl'; + const ctrl_label = frappe.utils.is_mac() ? "⌘" : "Ctrl"; this.$component.find(".checkout-btn").attr("title", `${ctrl_label}+Enter`); frappe.ui.keys.add_shortcut({ shortcut: "ctrl+enter", action: () => this.$component.find(".checkout-btn").click(), - condition: () => this.$component.is(":visible") && !this.$totals_section.find('.edit-cart-btn').is(':visible'), + condition: () => + this.$component.is(":visible") && !this.$totals_section.find(".edit-cart-btn").is(":visible"), description: __("Checkout Order / Submit Order / New Order"), ignore_inputs: true, - page: cur_page.page.page + page: cur_page.page.page, }); this.$component.find(".edit-cart-btn").attr("title", `${ctrl_label}+E`); frappe.ui.keys.on("ctrl+e", () => { const item_cart_visible = this.$component.is(":visible"); - const checkout_btn_invisible = !this.$totals_section.find('.checkout-btn').is('visible'); + const checkout_btn_invisible = !this.$totals_section.find(".checkout-btn").is("visible"); if (item_cart_visible && checkout_btn_invisible) { this.$component.find(".edit-cart-btn").click(); } @@ -268,7 +266,7 @@ erpnext.PointOfSale.ItemCart = class { condition: () => this.$add_discount_elem.is(":visible"), description: __("Add Order Discount"), ignore_inputs: true, - page: cur_page.page.page + page: cur_page.page.page, }); frappe.ui.keys.on("escape", () => { const item_cart_visible = this.$component.is(":visible"); @@ -284,11 +282,11 @@ erpnext.PointOfSale.ItemCart = class { if (!item || item_is_highlighted) { this.item_is_selected = false; - this.$cart_container.find('.cart-item-wrapper').css("background-color", ""); + this.$cart_container.find(".cart-item-wrapper").css("background-color", ""); } else { $cart_item.css("background-color", "var(--gray-50)"); this.item_is_selected = true; - this.$cart_container.find('.cart-item-wrapper').not(item).css("background-color", ""); + this.$cart_container.find(".cart-item-wrapper").not(item).css("background-color", ""); } } @@ -297,38 +295,38 @@ erpnext.PointOfSale.ItemCart = class {
              `); const me = this; - const query = { query: 'erpnext.controllers.queries.customer_query' }; + const query = { query: "erpnext.controllers.queries.customer_query" }; const allowed_customer_group = this.allowed_customer_groups || []; if (allowed_customer_group.length) { query.filters = { - customer_group: ['in', allowed_customer_group] - } + customer_group: ["in", allowed_customer_group], + }; } this.customer_field = frappe.ui.form.make_control({ df: { - label: __('Customer'), - fieldtype: 'Link', - options: 'Customer', - placeholder: __('Search by customer name, phone, email.'), + label: __("Customer"), + fieldtype: "Link", + options: "Customer", + placeholder: __("Search by customer name, phone, email."), get_query: () => query, - onchange: function() { + onchange: function () { if (this.value) { const frm = me.events.get_frm(); frappe.dom.freeze(); - frappe.model.set_value(frm.doc.doctype, frm.doc.name, 'customer', this.value); - frm.script_manager.trigger('customer', frm.doc.doctype, frm.doc.name).then(() => { + frappe.model.set_value(frm.doc.doctype, frm.doc.name, "customer", this.value); + frm.script_manager.trigger("customer", frm.doc.doctype, frm.doc.name).then(() => { frappe.run_serially([ () => me.fetch_customer_details(this.value), () => me.events.customer_details_updated(me.customer_info), () => me.update_customer_section(), () => me.update_totals_section(), - () => frappe.dom.unfreeze() + () => frappe.dom.unfreeze(), ]); - }) + }); } }, }, - parent: this.$customer_section.find('.customer-field'), + parent: this.$customer_section.find(".customer-field"), render_input: true, }); this.customer_field.toggle_label(false); @@ -337,66 +335,81 @@ erpnext.PointOfSale.ItemCart = class { fetch_customer_details(customer) { if (customer) { return new Promise((resolve) => { - frappe.db.get_value('Customer', customer, ["email_id", "mobile_no", "image", "loyalty_program"]).then(({ message }) => { - const { loyalty_program } = message; - // if loyalty program then fetch loyalty points too - if (loyalty_program) { - frappe.call({ - method: "erpnext.accounts.doctype.loyalty_program.loyalty_program.get_loyalty_program_details_with_points", - args: { customer, loyalty_program, "silent": true }, - callback: (r) => { - const { loyalty_points, conversion_factor } = r.message; - if (!r.exc) { - this.customer_info = { ...message, customer, loyalty_points, conversion_factor }; - resolve(); - } - } - }); - } else { - this.customer_info = { ...message, customer }; - resolve(); - } - }); + frappe.db + .get_value("Customer", customer, ["email_id", "mobile_no", "image", "loyalty_program"]) + .then(({ message }) => { + const { loyalty_program } = message; + // if loyalty program then fetch loyalty points too + if (loyalty_program) { + frappe.call({ + method: "erpnext.accounts.doctype.loyalty_program.loyalty_program.get_loyalty_program_details_with_points", + args: { customer, loyalty_program, silent: true }, + callback: (r) => { + const { loyalty_points, conversion_factor } = r.message; + if (!r.exc) { + this.customer_info = { + ...message, + customer, + loyalty_points, + conversion_factor, + }; + resolve(); + } + }, + }); + } else { + this.customer_info = { ...message, customer }; + resolve(); + } + }); }); } else { return new Promise((resolve) => { - this.customer_info = {} + this.customer_info = {}; resolve(); }); } } show_discount_control() { - this.$add_discount_elem.css({ 'padding': '0px', 'border': 'none' }); - this.$add_discount_elem.html( - `
              ` - ); + this.$add_discount_elem.css({ padding: "0px", border: "none" }); + this.$add_discount_elem.html(`
              `); const me = this; const frm = me.events.get_frm(); let discount = frm.doc.additional_discount_percentage; this.discount_field = frappe.ui.form.make_control({ df: { - label: __('Discount'), - fieldtype: 'Data', - placeholder: ( discount ? discount + '%' : __('Enter discount percentage.') ), - input_class: 'input-xs', - onchange: function() { + label: __("Discount"), + fieldtype: "Data", + placeholder: discount ? discount + "%" : __("Enter discount percentage."), + input_class: "input-xs", + onchange: function () { if (flt(this.value) != 0) { - frappe.model.set_value(frm.doc.doctype, frm.doc.name, 'additional_discount_percentage', flt(this.value)); + frappe.model.set_value( + frm.doc.doctype, + frm.doc.name, + "additional_discount_percentage", + flt(this.value) + ); me.hide_discount_control(this.value); } else { - frappe.model.set_value(frm.doc.doctype, frm.doc.name, 'additional_discount_percentage', 0); + frappe.model.set_value( + frm.doc.doctype, + frm.doc.name, + "additional_discount_percentage", + 0 + ); me.$add_discount_elem.css({ - 'border': '1px dashed var(--gray-500)', - 'padding': 'var(--padding-sm) var(--padding-md)' + border: "1px dashed var(--gray-500)", + padding: "var(--padding-sm) var(--padding-md)", }); - me.$add_discount_elem.html(`${me.get_discount_icon()} ${__('Add Discount')}`); + me.$add_discount_elem.html(`${me.get_discount_icon()} ${__("Add Discount")}`); me.discount_field = undefined; } }, }, - parent: this.$add_discount_elem.find('.add-discount-field'), + parent: this.$add_discount_elem.find(".add-discount-field"), render_input: true, }); this.discount_field.toggle_label(false); @@ -405,14 +418,12 @@ erpnext.PointOfSale.ItemCart = class { hide_discount_control(discount) { if (!discount) { - this.$add_discount_elem.css({ 'padding': '0px', 'border': 'none' }); - this.$add_discount_elem.html( - `
              ` - ); + this.$add_discount_elem.css({ padding: "0px", border: "none" }); + this.$add_discount_elem.html(`
              `); } else { this.$add_discount_elem.css({ - 'border': '1px dashed var(--dark-green-500)', - 'padding': 'var(--padding-sm) var(--padding-md)' + border: "1px dashed var(--dark-green-500)", + padding: "var(--padding-sm) var(--padding-md)", }); this.$add_discount_elem.html( `
              @@ -424,7 +435,7 @@ erpnext.PointOfSale.ItemCart = class { update_customer_section() { const me = this; - const { customer, email_id='', mobile_no='', image } = this.customer_info || {}; + const { customer, email_id = "", mobile_no = "", image } = this.customer_info || {}; if (customer) { this.$customer_section.html( @@ -450,7 +461,7 @@ erpnext.PointOfSale.ItemCart = class { function get_customer_description() { if (!email_id && !mobile_no) { - return `
              ${__('Click to add email / phone')}
              `; + return `
              ${__("Click to add email / phone")}
              `; } else if (email_id && !mobile_no) { return `
              ${email_id}
              `; } else if (mobile_no && !email_id) { @@ -459,7 +470,6 @@ erpnext.PointOfSale.ItemCart = class { return `
              ${email_id} - ${mobile_no}
              `; } } - } get_customer_image() { @@ -476,7 +486,9 @@ erpnext.PointOfSale.ItemCart = class { this.render_net_total(frm.doc.net_total); this.render_total_item_qty(frm.doc.items); - const grand_total = cint(frappe.sys_defaults.disable_rounded_total) ? frm.doc.grand_total : frm.doc.rounded_total; + const grand_total = cint(frappe.sys_defaults.disable_rounded_total) + ? frm.doc.grand_total + : frm.doc.rounded_total; this.render_grand_total(grand_total); this.render_taxes(frm.doc.taxes); @@ -484,13 +496,13 @@ erpnext.PointOfSale.ItemCart = class { render_net_total(value) { const currency = this.events.get_frm().doc.currency; - this.$totals_section.find('.net-total-container').html( - `
              ${__('Net Total')}
              ${format_currency(value, currency)}
              ` - ) + this.$totals_section + .find(".net-total-container") + .html(`
              ${__("Net Total")}
              ${format_currency(value, currency)}
              `); - this.$numpad_section.find('.numpad-net-total').html( - `
              ${__('Net Total')}: ${format_currency(value, currency)}
              ` - ); + this.$numpad_section + .find(".numpad-net-total") + .html(`
              ${__("Net Total")}: ${format_currency(value, currency)}
              `); } render_total_item_qty(items) { @@ -499,40 +511,44 @@ erpnext.PointOfSale.ItemCart = class { total_item_qty = total_item_qty + item.qty; }); - this.$totals_section.find('.item-qty-total-container').html( - `
              ${__('Total Quantity')}
              ${total_item_qty}
              ` - ); + this.$totals_section + .find(".item-qty-total-container") + .html(`
              ${__("Total Quantity")}
              ${total_item_qty}
              `); - this.$numpad_section.find('.numpad-item-qty-total').html( - `
              ${__('Total Quantity')}: ${total_item_qty}
              ` - ); + this.$numpad_section + .find(".numpad-item-qty-total") + .html(`
              ${__("Total Quantity")}: ${total_item_qty}
              `); } render_grand_total(value) { const currency = this.events.get_frm().doc.currency; - this.$totals_section.find('.grand-total-container').html( - `
              ${__('Grand Total')}
              ${format_currency(value, currency)}
              ` - ) + this.$totals_section + .find(".grand-total-container") + .html(`
              ${__("Grand Total")}
              ${format_currency(value, currency)}
              `); - this.$numpad_section.find('.numpad-grand-total').html( - `
              ${__('Grand Total')}: ${format_currency(value, currency)}
              ` - ); + this.$numpad_section + .find(".numpad-grand-total") + .html(`
              ${__("Grand Total")}: ${format_currency(value, currency)}
              `); } render_taxes(taxes) { if (taxes.length) { const currency = this.events.get_frm().doc.currency; - const taxes_html = taxes.map(t => { - if (t.tax_amount_after_discount_amount == 0.0) return; - const description = /[0-9]+/.test(t.description) ? t.description : `${t.description} @ ${t.rate}%`; - return `
              + const taxes_html = taxes + .map((t) => { + if (t.tax_amount_after_discount_amount == 0.0) return; + const description = /[0-9]+/.test(t.description) + ? t.description + : `${t.description} @ ${t.rate}%`; + return `
              ${description}
              ${format_currency(t.tax_amount_after_discount_amount, currency)}
              `; - }).join(''); - this.$totals_section.find('.taxes-container').css('display', 'flex').html(taxes_html); + }) + .join(""); + this.$totals_section.find(".taxes-container").css("display", "flex").html(taxes_html); } else { - this.$totals_section.find('.taxes-container').css('display', 'none').html(''); + this.$totals_section.find(".taxes-container").css("display", "none").html(""); } } @@ -543,7 +559,7 @@ erpnext.PointOfSale.ItemCart = class { get_item_from_frm(item) { const doc = this.events.get_frm().doc; - return doc.items.find(i => i.name == item.name); + return doc.items.find((i) => i.name == item.name); } update_item_html(item, remove_item) { @@ -556,7 +572,7 @@ erpnext.PointOfSale.ItemCart = class { this.render_cart_item(item_row, $item); } - const no_of_cart_items = this.$cart_items_wrapper.find('.cart-item-wrapper').length; + const no_of_cart_items = this.$cart_items_wrapper.find(".cart-item-wrapper").length; this.highlight_checkout_btn(no_of_cart_items > 0); this.update_empty_cart_section(no_of_cart_items); @@ -570,7 +586,7 @@ erpnext.PointOfSale.ItemCart = class { this.$cart_items_wrapper.append( `
              ` - ) + ); $item_to_update = this.get_cart_item(item_data); } @@ -583,7 +599,7 @@ erpnext.PointOfSale.ItemCart = class { ${get_description_html()}
              ${get_rate_discount_html()}` - ) + ); set_dynamic_rate_header_width(); @@ -592,8 +608,7 @@ erpnext.PointOfSale.ItemCart = class { me.$cart_header.find(".rate-amount-header").css("width", ""); me.$cart_items_wrapper.find(".item-rate-amount").css("width", ""); let max_width = rate_cols.reduce((max_width, elm) => { - if ($(elm).width() > max_width) - max_width = $(elm).width(); + if ($(elm).width() > max_width) max_width = $(elm).width(); return max_width; }, 0); @@ -613,7 +628,7 @@ erpnext.PointOfSale.ItemCart = class {
              ${format_currency(item_data.amount, currency)}
              ${format_currency(item_data.rate, currency)}
              -
              ` +
              `; } else { return `
              @@ -621,17 +636,20 @@ erpnext.PointOfSale.ItemCart = class {
              ${format_currency(item_data.rate, currency)}
              -
              ` +
              `; } } function get_description_html() { if (item_data.description) { - if (item_data.description.indexOf('
              ') != -1) { + if (item_data.description.indexOf("
              ") != -1) { try { item_data.description = $(item_data.description).text(); } catch (error) { - item_data.description = item_data.description.replace(/
              /g, ' ').replace(/<\/div>/g, ' ').replace(/ +/g, ' '); + item_data.description = item_data.description + .replace(/
              /g, " ") + .replace(/<\/div>/g, " ") + .replace(/ +/g, " "); } } item_data.description = frappe.ellipsis(item_data.description, 45); @@ -656,7 +674,7 @@ erpnext.PointOfSale.ItemCart = class { } handle_broken_image($img) { - const item_abbr = $($img).attr('alt'); + const item_abbr = $($img).attr("alt"); $($img).parent().replaceWith(`
              ${item_abbr}
              `); } @@ -667,44 +685,48 @@ erpnext.PointOfSale.ItemCart = class { toggle_checkout_btn(show_checkout) { if (show_checkout) { - this.$totals_section.find('.checkout-btn').css('display', 'flex'); - this.$totals_section.find('.edit-cart-btn').css('display', 'none'); + this.$totals_section.find(".checkout-btn").css("display", "flex"); + this.$totals_section.find(".edit-cart-btn").css("display", "none"); } else { - this.$totals_section.find('.checkout-btn').css('display', 'none'); - this.$totals_section.find('.edit-cart-btn').css('display', 'flex'); + this.$totals_section.find(".checkout-btn").css("display", "none"); + this.$totals_section.find(".edit-cart-btn").css("display", "flex"); } } highlight_checkout_btn(toggle) { if (toggle) { - this.$add_discount_elem.css('display', 'flex'); - this.$cart_container.find('.checkout-btn').css({ - 'background-color': 'var(--blue-500)' + this.$add_discount_elem.css("display", "flex"); + this.$cart_container.find(".checkout-btn").css({ + "background-color": "var(--blue-500)", }); } else { - this.$add_discount_elem.css('display', 'none'); - this.$cart_container.find('.checkout-btn').css({ - 'background-color': 'var(--blue-200)' + this.$add_discount_elem.css("display", "none"); + this.$cart_container.find(".checkout-btn").css({ + "background-color": "var(--blue-200)", }); } } update_empty_cart_section(no_of_cart_items) { - const $no_item_element = this.$cart_items_wrapper.find('.no-item-wrapper'); + const $no_item_element = this.$cart_items_wrapper.find(".no-item-wrapper"); // if cart has items and no item is present - no_of_cart_items > 0 && $no_item_element && $no_item_element.remove() && this.$cart_header.css('display', 'flex'); + no_of_cart_items > 0 && + $no_item_element && + $no_item_element.remove() && + this.$cart_header.css("display", "flex"); no_of_cart_items === 0 && !$no_item_element.length && this.make_no_items_placeholder(); } on_numpad_event($btn) { - const current_action = $btn.attr('data-button-value'); - const action_is_field_edit = ['qty', 'discount_percentage', 'rate'].includes(current_action); - const action_is_allowed = action_is_field_edit ? ( - (current_action == 'rate' && this.allow_rate_change) || - (current_action == 'discount_percentage' && this.allow_discount_change) || - (current_action == 'qty')) : true; + const current_action = $btn.attr("data-button-value"); + const action_is_field_edit = ["qty", "discount_percentage", "rate"].includes(current_action); + const action_is_allowed = action_is_field_edit + ? (current_action == "rate" && this.allow_rate_change) || + (current_action == "discount_percentage" && this.allow_discount_change) || + current_action == "qty" + : true; const action_is_pressed_twice = this.prev_action === current_action; const first_click_event = !this.prev_action; @@ -712,11 +734,11 @@ erpnext.PointOfSale.ItemCart = class { if (action_is_field_edit) { if (!action_is_allowed) { - const label = current_action == 'rate' ? 'Rate'.bold() : 'Discount'.bold(); - const message = __('Editing {0} is not allowed as per POS Profile settings', [label]); + const label = current_action == "rate" ? "Rate".bold() : "Discount".bold(); + const message = __("Editing {0} is not allowed as per POS Profile settings", [label]); frappe.show_alert({ - indicator: 'red', - message: message + indicator: "red", + message: message, }); frappe.utils.play_sound("error"); return; @@ -727,20 +749,22 @@ erpnext.PointOfSale.ItemCart = class { } else if (action_is_pressed_twice) { this.prev_action = undefined; } - this.numpad_value = ''; - - } else if (current_action === 'checkout') { + this.numpad_value = ""; + } else if (current_action === "checkout") { this.prev_action = undefined; this.toggle_item_highlight(); this.events.numpad_event(undefined, current_action); return; - } else if (current_action === 'remove') { + } else if (current_action === "remove") { this.prev_action = undefined; this.toggle_item_highlight(); this.events.numpad_event(undefined, current_action); return; } else { - this.numpad_value = current_action === 'delete' ? this.numpad_value.slice(0, -1) : this.numpad_value + current_action; + this.numpad_value = + current_action === "delete" + ? this.numpad_value.slice(0, -1) + : this.numpad_value + current_action; this.numpad_value = this.numpad_value || 0; } @@ -748,17 +772,17 @@ erpnext.PointOfSale.ItemCart = class { if (first_click_event_is_not_field_edit) { frappe.show_alert({ - indicator: 'red', - message: __('Please select a field to edit from numpad') + indicator: "red", + message: __("Please select a field to edit from numpad"), }); frappe.utils.play_sound("error"); return; } - if (flt(this.numpad_value) > 100 && this.prev_action === 'discount_percentage') { + if (flt(this.numpad_value) > 100 && this.prev_action === "discount_percentage") { frappe.show_alert({ - message: __('Discount cannot be greater than 100%'), - indicator: 'orange' + message: __("Discount cannot be greater than 100%"), + indicator: "orange", }); frappe.utils.play_sound("error"); this.numpad_value = current_action; @@ -769,48 +793,48 @@ erpnext.PointOfSale.ItemCart = class { } highlight_numpad_btn($btn, curr_action) { - const curr_action_is_highlighted = $btn.hasClass('highlighted-numpad-btn'); - const curr_action_is_action = ['qty', 'discount_percentage', 'rate', 'done'].includes(curr_action); + const curr_action_is_highlighted = $btn.hasClass("highlighted-numpad-btn"); + const curr_action_is_action = ["qty", "discount_percentage", "rate", "done"].includes(curr_action); if (!curr_action_is_highlighted) { - $btn.addClass('highlighted-numpad-btn'); + $btn.addClass("highlighted-numpad-btn"); } if (this.prev_action === curr_action && curr_action_is_highlighted) { // if Qty is pressed twice - $btn.removeClass('highlighted-numpad-btn'); + $btn.removeClass("highlighted-numpad-btn"); } if (this.prev_action && this.prev_action !== curr_action && curr_action_is_action) { // Order: Qty -> Rate then remove Qty highlight const prev_btn = $(`[data-button-value='${this.prev_action}']`); - prev_btn.removeClass('highlighted-numpad-btn'); + prev_btn.removeClass("highlighted-numpad-btn"); } - if (!curr_action_is_action || curr_action === 'done') { + if (!curr_action_is_action || curr_action === "done") { // if numbers are clicked setTimeout(() => { - $btn.removeClass('highlighted-numpad-btn'); + $btn.removeClass("highlighted-numpad-btn"); }, 200); } } toggle_numpad(show) { if (show) { - this.$totals_section.css('display', 'none'); - this.$numpad_section.css('display', 'flex'); + this.$totals_section.css("display", "none"); + this.$numpad_section.css("display", "flex"); } else { - this.$totals_section.css('display', 'flex'); - this.$numpad_section.css('display', 'none'); + this.$totals_section.css("display", "flex"); + this.$numpad_section.css("display", "none"); } this.reset_numpad(); } reset_numpad() { - this.numpad_value = ''; + this.numpad_value = ""; this.prev_action = undefined; - this.$numpad_section.find('.highlighted-numpad-btn').removeClass('highlighted-numpad-btn'); + this.$numpad_section.find(".highlighted-numpad-btn").removeClass("highlighted-numpad-btn"); } toggle_numpad_field_edit(fieldname) { - if (['qty', 'discount_percentage', 'rate'].includes(fieldname)) { + if (["qty", "discount_percentage", "rate"].includes(fieldname)) { this.$numpad_section.find(`[data-button-value="${fieldname}"]`).click(); } } @@ -819,12 +843,12 @@ erpnext.PointOfSale.ItemCart = class { if (show) { const { customer } = this.customer_info || {}; - this.$cart_container.css('display', 'none'); + this.$cart_container.css("display", "none"); this.$customer_section.css({ - 'height': '100%', - 'padding-top': '0px' + height: "100%", + "padding-top": "0px", }); - this.$customer_section.find('.customer-details').html( + this.$customer_section.find(".customer-details").html( `
              Contact Details
              @@ -853,12 +877,11 @@ erpnext.PointOfSale.ItemCart = class { this.render_customer_fields(); this.fetch_customer_transactions(); - } else { - this.$cart_container.css('display', 'flex'); + this.$cart_container.css("display", "flex"); this.$customer_section.css({ - 'height': '', - 'padding-top': '' + height: "", + "padding-top": "", }); this.update_customer_section(); @@ -866,100 +889,107 @@ erpnext.PointOfSale.ItemCart = class { } render_customer_fields() { - const $customer_form = this.$customer_section.find('.customer-fields-container'); - - const dfs = [{ - fieldname: 'email_id', - label: __('Email'), - fieldtype: 'Data', - options: 'email', - placeholder: __("Enter customer's email") - },{ - fieldname: 'mobile_no', - label: __('Phone Number'), - fieldtype: 'Data', - placeholder: __("Enter customer's phone number") - },{ - fieldname: 'loyalty_program', - label: __('Loyalty Program'), - fieldtype: 'Link', - options: 'Loyalty Program', - placeholder: __("Select Loyalty Program") - },{ - fieldname: 'loyalty_points', - label: __('Loyalty Points'), - fieldtype: 'Data', - read_only: 1 - }]; + const $customer_form = this.$customer_section.find(".customer-fields-container"); + + const dfs = [ + { + fieldname: "email_id", + label: __("Email"), + fieldtype: "Data", + options: "email", + placeholder: __("Enter customer's email"), + }, + { + fieldname: "mobile_no", + label: __("Phone Number"), + fieldtype: "Data", + placeholder: __("Enter customer's phone number"), + }, + { + fieldname: "loyalty_program", + label: __("Loyalty Program"), + fieldtype: "Link", + options: "Loyalty Program", + placeholder: __("Select Loyalty Program"), + }, + { + fieldname: "loyalty_points", + label: __("Loyalty Points"), + fieldtype: "Data", + read_only: 1, + }, + ]; const me = this; - dfs.forEach(df => { + dfs.forEach((df) => { this[`customer_${df.fieldname}_field`] = frappe.ui.form.make_control({ - df: { ...df, - onchange: handle_customer_field_change, - }, + df: { ...df, onchange: handle_customer_field_change }, parent: $customer_form.find(`.${df.fieldname}-field`), render_input: true, }); this[`customer_${df.fieldname}_field`].set_value(this.customer_info[df.fieldname]); - }) + }); function handle_customer_field_change() { const current_value = me.customer_info[this.df.fieldname]; const current_customer = me.customer_info.customer; - if (this.value && current_value != this.value && this.df.fieldname != 'loyalty_points') { + if (this.value && current_value != this.value && this.df.fieldname != "loyalty_points") { frappe.call({ - method: 'erpnext.selling.page.point_of_sale.point_of_sale.set_customer_info', + method: "erpnext.selling.page.point_of_sale.point_of_sale.set_customer_info", args: { fieldname: this.df.fieldname, customer: current_customer, - value: this.value + value: this.value, }, callback: (r) => { - if(!r.exc) { + if (!r.exc) { me.customer_info[this.df.fieldname] = this.value; frappe.show_alert({ message: __("Customer contact updated successfully."), - indicator: 'green' + indicator: "green", }); frappe.utils.play_sound("submit"); } - } + }, }); } } } fetch_customer_transactions() { - frappe.db.get_list('POS Invoice', { - filters: { customer: this.customer_info.customer, docstatus: 1 }, - fields: ['name', 'grand_total', 'status', 'posting_date', 'posting_time', 'currency'], - limit: 20 - }).then((res) => { - const transaction_container = this.$customer_section.find('.customer-transactions'); - - if (!res.length) { - transaction_container.html( - `
              No recent transactions found
              ` - ) - return; - }; - - const elapsed_time = moment(res[0].posting_date+" "+res[0].posting_time).fromNow(); - this.$customer_section.find('.customer-desc').html(`Last transacted ${elapsed_time}`); - - res.forEach(invoice => { - const posting_datetime = moment(invoice.posting_date+" "+invoice.posting_time).format("Do MMMM, h:mma"); - let indicator_color = { - 'Paid': 'green', - 'Draft': 'red', - 'Return': 'gray', - 'Consolidated': 'blue' - }; + frappe.db + .get_list("POS Invoice", { + filters: { customer: this.customer_info.customer, docstatus: 1 }, + fields: ["name", "grand_total", "status", "posting_date", "posting_time", "currency"], + limit: 20, + }) + .then((res) => { + const transaction_container = this.$customer_section.find(".customer-transactions"); + + if (!res.length) { + transaction_container.html( + `
              No recent transactions found
              ` + ); + return; + } - transaction_container.append( - `
              + const elapsed_time = moment(res[0].posting_date + " " + res[0].posting_time).fromNow(); + this.$customer_section.find(".customer-desc").html(`Last transacted ${elapsed_time}`); + + res.forEach((invoice) => { + const posting_datetime = moment(invoice.posting_date + " " + invoice.posting_time).format( + "Do MMMM, h:mma" + ); + let indicator_color = { + Paid: "green", + Draft: "red", + Return: "gray", + Consolidated: "blue", + }; + + transaction_container.append( + `
              ${invoice.name}
              ${posting_datetime}
              @@ -976,17 +1006,17 @@ erpnext.PointOfSale.ItemCart = class {
              ` - ) + ); + }); }); - }); } attach_refresh_field_event(frm) { - $(frm.wrapper).off('refresh-fields'); - $(frm.wrapper).on('refresh-fields', () => { + $(frm.wrapper).off("refresh-fields"); + $(frm.wrapper).on("refresh-fields", () => { if (frm.doc.items.length) { - this.$cart_items_wrapper.html(''); - frm.doc.items.forEach(item => { + this.$cart_items_wrapper.html(""); + frm.doc.items.forEach((item) => { this.update_item_html(item); }); } @@ -1004,9 +1034,9 @@ erpnext.PointOfSale.ItemCart = class { this.update_customer_section(); }); - this.$cart_items_wrapper.html(''); + this.$cart_items_wrapper.html(""); if (frm.doc.items.length) { - frm.doc.items.forEach(item => { + frm.doc.items.forEach((item) => { this.update_item_html(item); }); } else { @@ -1016,19 +1046,18 @@ erpnext.PointOfSale.ItemCart = class { this.update_totals_section(frm); - if(frm.doc.docstatus === 1) { - this.$totals_section.find('.checkout-btn').css('display', 'none'); - this.$totals_section.find('.edit-cart-btn').css('display', 'none'); + if (frm.doc.docstatus === 1) { + this.$totals_section.find(".checkout-btn").css("display", "none"); + this.$totals_section.find(".edit-cart-btn").css("display", "none"); } else { - this.$totals_section.find('.checkout-btn').css('display', 'flex'); - this.$totals_section.find('.edit-cart-btn').css('display', 'none'); + this.$totals_section.find(".checkout-btn").css("display", "flex"); + this.$totals_section.find(".edit-cart-btn").css("display", "none"); } this.toggle_component(true); } toggle_component(show) { - show ? this.$component.css('display', 'flex') : this.$component.css('display', 'none'); + show ? this.$component.css("display", "flex") : this.$component.css("display", "none"); } - -} +}; diff --git a/erpnext/selling/page/point_of_sale/pos_item_details.js b/erpnext/selling/page/point_of_sale/pos_item_details.js index f9b5bb2e4529..9a6d2cc36ae0 100644 --- a/erpnext/selling/page/point_of_sale/pos_item_details.js +++ b/erpnext/selling/page/point_of_sale/pos_item_details.js @@ -18,17 +18,15 @@ erpnext.PointOfSale.ItemDetails = class { } prepare_dom() { - this.wrapper.append( - `
              ` - ) + this.wrapper.append(`
              `); - this.$component = this.wrapper.find('.item-details-container'); + this.$component = this.wrapper.find(".item-details-container"); } init_child_components() { this.$component.html( `
              -
              ${__('Item Details')}
              +
              ${__("Item Details")}
              @@ -45,14 +43,14 @@ erpnext.PointOfSale.ItemDetails = class {
              ` - ) - - this.$item_name = this.$component.find('.item-name'); - this.$item_description = this.$component.find('.item-desc'); - this.$item_price = this.$component.find('.item-price'); - this.$item_image = this.$component.find('.item-image'); - this.$form_container = this.$component.find('.form-container'); - this.$dicount_section = this.$component.find('.discount-section'); + ); + + this.$item_name = this.$component.find(".item-name"); + this.$item_description = this.$component.find(".item-desc"); + this.$item_price = this.$component.find(".item-price"); + this.$item_image = this.$component.find(".item-image"); + this.$form_container = this.$component.find(".form-container"); + this.$dicount_section = this.$component.find(".discount-section"); } compare_with_current_item(item) { @@ -95,7 +93,7 @@ erpnext.PointOfSale.ItemDetails = class { validate_serial_batch_item() { const doc = this.events.get_frm().doc; - const item_row = doc.items.find(item => item.name === this.name); + const item_row = doc.items.find((item) => item.name === this.name); if (!item_row) return; @@ -104,12 +102,14 @@ erpnext.PointOfSale.ItemDetails = class { const no_serial_selected = !item_row.serial_no; const no_batch_selected = !item_row.batch_no; - if ((serialized && no_serial_selected) || (batched && no_batch_selected) || - (serialized && batched && (no_batch_selected || no_serial_selected))) { - + if ( + (serialized && no_serial_selected) || + (batched && no_batch_selected) || + (serialized && batched && (no_batch_selected || no_serial_selected)) + ) { frappe.show_alert({ message: __("Item is removed since no serial / batch no selected."), - indicator: 'orange' + indicator: "orange", }); frappe.utils.play_sound("cancel"); return this.events.remove_item_from_cart(); @@ -121,7 +121,10 @@ erpnext.PointOfSale.ItemDetails = class { function get_description_html() { if (description) { - description = description.indexOf('...') === -1 && description.length > 140 ? description.substr(0, 139) + '...' : description; + description = + description.indexOf("...") === -1 && description.length > 140 + ? description.substr(0, 139) + "..." + : description; return description; } return ``; @@ -141,11 +144,10 @@ erpnext.PointOfSale.ItemDetails = class { } else { this.$item_image.html(`
              ${frappe.get_abbr(item_name)}
              `); } - } handle_broken_image($img) { - const item_abbr = $($img).attr('alt'); + const item_abbr = $($img).attr("alt"); $($img).replaceWith(`
              ${item_abbr}
              `); } @@ -154,36 +156,36 @@ erpnext.PointOfSale.ItemDetails = class { this.$dicount_section.html( `
              ${format_currency(item.price_list_rate, this.currency)}
              ${item.discount_percentage}% off
              ` - ) + ); this.$item_price.html(format_currency(item.rate, this.currency)); } else { - this.$dicount_section.html(``) + this.$dicount_section.html(``); } } render_form(item) { const fields_to_display = this.get_form_fields(item); - this.$form_container.html(''); + this.$form_container.html(""); fields_to_display.forEach((fieldname, idx) => { this.$form_container.append( `
              ` - ) + ); - const field_meta = this.item_meta.fields.find(df => df.fieldname === fieldname); - fieldname === 'discount_percentage' ? (field_meta.label = __('Discount (%)')) : ''; + const field_meta = this.item_meta.fields.find((df) => df.fieldname === fieldname); + fieldname === "discount_percentage" ? (field_meta.label = __("Discount (%)")) : ""; const me = this; this[`${fieldname}_control`] = frappe.ui.form.make_control({ df: { ...field_meta, - onchange: function() { + onchange: function () { me.events.form_updated(me.current_item, fieldname, this.value); - } + }, }, parent: this.$form_container.find(`.${fieldname}-control`), render_input: true, - }) + }); this[`${fieldname}_control`].set_value(item[fieldname]); }); @@ -193,33 +195,40 @@ erpnext.PointOfSale.ItemDetails = class { } get_form_fields(item) { - const fields = ['qty', 'uom', 'rate', 'conversion_factor', 'discount_percentage', 'warehouse', 'actual_qty', 'price_list_rate']; - if (item.has_serial_no) fields.push('serial_no'); - if (item.has_batch_no) fields.push('batch_no'); + const fields = [ + "qty", + "uom", + "rate", + "conversion_factor", + "discount_percentage", + "warehouse", + "actual_qty", + "price_list_rate", + ]; + if (item.has_serial_no) fields.push("serial_no"); + if (item.has_batch_no) fields.push("batch_no"); return fields; } make_auto_serial_selection_btn(item) { if (item.has_serial_no) { if (!item.has_batch_no) { - this.$form_container.append( - `
              ` - ); + this.$form_container.append(`
              `); } - const label = __('Auto Fetch Serial Numbers'); + const label = __("Auto Fetch Serial Numbers"); this.$form_container.append( `
              ${label}
              ` ); - this.$form_container.find('.serial_no-control').find('textarea').css('height', '6rem'); + this.$form_container.find(".serial_no-control").find("textarea").css("height", "6rem"); } } bind_custom_control_change_event() { const me = this; if (this.rate_control) { - this.rate_control.df.onchange = function() { + this.rate_control.df.onchange = function () { if (this.value || flt(this.value) === 0) { - me.events.form_updated(me.current_item, 'rate', this.value).then(() => { + me.events.form_updated(me.current_item, "rate", this.value).then(() => { const item_row = frappe.get_doc(me.doctype, me.name); const doc = me.events.get_frm().doc; me.$item_price.html(format_currency(item_row.rate, doc.currency)); @@ -238,43 +247,48 @@ erpnext.PointOfSale.ItemDetails = class { if (this.warehouse_control) { this.warehouse_control.df.reqd = 1; - this.warehouse_control.df.onchange = function() { + this.warehouse_control.df.onchange = function () { if (this.value) { - me.events.form_updated(me.current_item, 'warehouse', this.value).then(() => { + me.events.form_updated(me.current_item, "warehouse", this.value).then(() => { me.item_stock_map = me.events.get_item_stock_map(); const available_qty = me.item_stock_map[me.item_row.item_code][this.value][0]; - const is_stock_item = Boolean(me.item_stock_map[me.item_row.item_code][this.value][1]); + const is_stock_item = Boolean( + me.item_stock_map[me.item_row.item_code][this.value][1] + ); if (available_qty === undefined) { me.events.get_available_stock(me.item_row.item_code, this.value).then(() => { // item stock map is updated now reset warehouse me.warehouse_control.set_value(this.value); - }) + }); } else if (available_qty === 0 && is_stock_item) { - me.warehouse_control.set_value(''); + me.warehouse_control.set_value(""); const bold_item_code = me.item_row.item_code.bold(); const bold_warehouse = this.value.bold(); frappe.throw( - __('Item Code: {0} is not available under warehouse {1}.', [bold_item_code, bold_warehouse]) + __("Item Code: {0} is not available under warehouse {1}.", [ + bold_item_code, + bold_warehouse, + ]) ); } me.actual_qty_control.set_value(available_qty); }); } - } + }; this.warehouse_control.df.get_query = () => { return { - filters: { company: this.events.get_frm().doc.company } - } + filters: { company: this.events.get_frm().doc.company }, + }; }; this.warehouse_control.refresh(); } if (this.serial_no_control) { this.serial_no_control.df.reqd = 1; - this.serial_no_control.df.onchange = async function() { - !me.current_item.batch_no && await me.auto_update_batch_no(); - me.events.form_updated(me.current_item, 'serial_no', this.value); - } + this.serial_no_control.df.onchange = async function () { + !me.current_item.batch_no && (await me.auto_update_batch_no()); + me.events.form_updated(me.current_item, "serial_no", this.value); + }; this.serial_no_control.refresh(); } @@ -282,25 +296,25 @@ erpnext.PointOfSale.ItemDetails = class { this.batch_no_control.df.reqd = 1; this.batch_no_control.df.get_query = () => { return { - query: 'erpnext.controllers.queries.get_batch_no', + query: "erpnext.controllers.queries.get_batch_no", filters: { item_code: me.item_row.item_code, warehouse: me.item_row.warehouse, - posting_date: me.events.get_frm().doc.posting_date - } - } + posting_date: me.events.get_frm().doc.posting_date, + }, + }; }; this.batch_no_control.refresh(); } if (this.uom_control) { - this.uom_control.df.onchange = function() { - me.events.form_updated(me.current_item, 'uom', this.value); + this.uom_control.df.onchange = function () { + me.events.form_updated(me.current_item, "uom", this.value); const item_row = frappe.get_doc(me.doctype, me.name); - me.conversion_factor_control.df.read_only = (item_row.stock_uom == this.value); + me.conversion_factor_control.df.read_only = item_row.stock_uom == this.value; me.conversion_factor_control.refresh(); - } + }; } frappe.model.on("POS Invoice Item", "*", (fieldname, value, item_row) => { @@ -316,13 +330,16 @@ erpnext.PointOfSale.ItemDetails = class { async auto_update_batch_no() { if (this.serial_no_control && this.batch_no_control) { - const selected_serial_nos = this.serial_no_control.get_value().split(`\n`).filter(s => s); + const selected_serial_nos = this.serial_no_control + .get_value() + .split(`\n`) + .filter((s) => s); if (!selected_serial_nos.length) return; // find batch nos of the selected serial no const serials_with_batch_no = await frappe.db.get_list("Serial No", { - filters: { 'name': ["in", selected_serial_nos]}, - fields: ["batch_no", "name"] + filters: { name: ["in", selected_serial_nos] }, + fields: ["batch_no", "name"], }); const batch_serial_map = serials_with_batch_no.reduce((acc, r) => { if (!acc[r.batch_no]) { @@ -335,10 +352,11 @@ erpnext.PointOfSale.ItemDetails = class { const batch_no = Object.keys(batch_serial_map)[0]; const batch_serial_nos = batch_serial_map[batch_no].join(`\n`); // eg. 10 selected serial no. -> 5 belongs to first batch other 5 belongs to second batch - const serial_nos_belongs_to_other_batch = selected_serial_nos.length !== batch_serial_map[batch_no].length; + const serial_nos_belongs_to_other_batch = + selected_serial_nos.length !== batch_serial_map[batch_no].length; const current_batch_no = this.batch_no_control.get_value(); - current_batch_no != batch_no && await this.batch_no_control.set_value(batch_no); + current_batch_no != batch_no && (await this.batch_no_control.set_value(batch_no)); if (serial_nos_belongs_to_other_batch) { this.serial_no_control.set_value(batch_serial_nos); @@ -354,13 +372,13 @@ erpnext.PointOfSale.ItemDetails = class { this.bind_auto_serial_fetch_event(); this.bind_fields_to_numpad_fields(); - this.$component.on('click', '.close-btn', () => { + this.$component.on("click", ".close-btn", () => { this.events.close_item_details(); }); } attach_shortcuts() { - this.wrapper.find('.close-btn').attr("title", "Esc"); + this.wrapper.find(".close-btn").attr("title", "Esc"); frappe.ui.keys.on("escape", () => { const item_details_visible = this.$component.is(":visible"); if (item_details_visible) { @@ -371,8 +389,8 @@ erpnext.PointOfSale.ItemDetails = class { bind_fields_to_numpad_fields() { const me = this; - this.$form_container.on('click', '.input-with-feedback', function() { - const fieldname = $(this).attr('data-fieldname'); + this.$form_container.on("click", ".input-with-feedback", function () { + const fieldname = $(this).attr("data-fieldname"); if (this.last_field_focused != fieldname) { me.events.item_field_focused(fieldname); this.last_field_focused = fieldname; @@ -381,8 +399,8 @@ erpnext.PointOfSale.ItemDetails = class { } bind_auto_serial_fetch_event() { - this.$form_container.on('click', '.auto-fetch-btn', () => { - this.batch_no_control && this.batch_no_control.set_value(''); + this.$form_container.on("click", ".auto-fetch-btn", () => { + this.batch_no_control && this.batch_no_control.set_value(""); let qty = this.qty_control.get_value(); let conversion_factor = this.conversion_factor_control.get_value(); let expiry_date = this.item_row.has_batch_no ? this.events.get_frm().doc.posting_date : ""; @@ -392,11 +410,11 @@ erpnext.PointOfSale.ItemDetails = class { args: { qty: qty * conversion_factor, item_code: this.current_item.item_code, - warehouse: this.warehouse_control.get_value() || '', - batch_nos: this.current_item.batch_no || '', + warehouse: this.warehouse_control.get_value() || "", + batch_nos: this.current_item.batch_no || "", posting_date: expiry_date, - for_doctype: 'POS Invoice' - } + for_doctype: "POS Invoice", + }, }); numbers.then((data) => { @@ -406,21 +424,22 @@ erpnext.PointOfSale.ItemDetails = class { const warehouse = this.warehouse_control.get_value().bold(); const item_code = this.current_item.item_code.bold(); frappe.msgprint( - __('Serial numbers unavailable for Item {0} under warehouse {1}. Please try changing warehouse.', [item_code, warehouse]) + __( + "Serial numbers unavailable for Item {0} under warehouse {1}. Please try changing warehouse.", + [item_code, warehouse] + ) ); } else if (records_length < qty) { - frappe.msgprint( - __('Fetched only {0} available serial numbers.', [records_length]) - ); + frappe.msgprint(__("Fetched only {0} available serial numbers.", [records_length])); this.qty_control.set_value(records_length); } numbers = auto_fetched_serial_numbers.join(`\n`); this.serial_no_control.set_value(numbers); }); - }) + }); } toggle_component(show) { - show ? this.$component.css('display', 'flex') : this.$component.css('display', 'none'); + show ? this.$component.css("display", "flex") : this.$component.css("display", "none"); } -} +}; diff --git a/erpnext/selling/page/point_of_sale/pos_item_selector.js b/erpnext/selling/page/point_of_sale/pos_item_selector.js index b5eb0489f9d2..dba36bd2429f 100644 --- a/erpnext/selling/page/point_of_sale/pos_item_selector.js +++ b/erpnext/selling/page/point_of_sale/pos_item_selector.js @@ -1,4 +1,4 @@ -import onScan from 'onscan.js'; +import onScan from "onscan.js"; erpnext.PointOfSale.ItemSelector = class { // eslint-disable-next-line no-unused-vars @@ -24,7 +24,7 @@ erpnext.PointOfSale.ItemSelector = class { this.wrapper.append( `
              -
              ${__('All Items')}
              +
              ${__("All Items")}
              @@ -32,13 +32,13 @@ erpnext.PointOfSale.ItemSelector = class {
              ` ); - this.$component = this.wrapper.find('.items-selector'); - this.$items_container = this.$component.find('.items-container'); + this.$component = this.wrapper.find(".items-selector"); + this.$items_container = this.$component.find(".items-container"); } async load_items_data() { if (!this.item_group) { - const res = await frappe.db.get_value("Item Group", {lft: 1, is_group: 1}, "name"); + const res = await frappe.db.get_value("Item Group", { lft: 1, is_group: 1 }, "name"); this.parent_item_group = res.message.name; } if (!this.price_list) { @@ -46,12 +46,12 @@ erpnext.PointOfSale.ItemSelector = class { this.price_list = res.message.selling_price_list; } - this.get_items({}).then(({message}) => { + this.get_items({}).then(({ message }) => { this.render_item_list(message.items); }); } - get_items({start = 0, page_length = 40, search_term=''}) { + get_items({ start = 0, page_length = 40, search_term = "" }) { const doc = this.events.get_frm().doc; const price_list = (doc && doc.selling_price_list) || this.price_list; let { item_group, pos_profile } = this; @@ -65,11 +65,10 @@ erpnext.PointOfSale.ItemSelector = class { }); } - render_item_list(items) { - this.$items_container.html(''); + this.$items_container.html(""); - items.forEach(item => { + items.forEach((item) => { const item_html = this.get_item_html(item); this.$items_container.append(item_html); }); @@ -84,15 +83,15 @@ erpnext.PointOfSale.ItemSelector = class { let qty_to_display = actual_qty; if (item.is_stock_item) { - indicator_color = (actual_qty > 10 ? "green" : actual_qty <= 0 ? "red" : "orange"); + indicator_color = actual_qty > 10 ? "green" : actual_qty <= 0 ? "red" : "orange"; if (Math.round(qty_to_display) > 999) { - qty_to_display = Math.round(qty_to_display)/1000; - qty_to_display = qty_to_display.toFixed(1) + 'K'; + qty_to_display = Math.round(qty_to_display) / 1000; + qty_to_display = qty_to_display.toFixed(1) + "K"; } } else { - indicator_color = ''; - qty_to_display = ''; + indicator_color = ""; + qty_to_display = ""; } function get_item_image_html() { @@ -115,8 +114,7 @@ erpnext.PointOfSale.ItemSelector = class { } } - return ( - `
              ${format_currency(price_list_rate, item.currency, precision) || 0}
              -
              ` - ); +
              `; } handle_broken_image($img) { - const item_abbr = $($img).attr('alt'); + const item_abbr = $($img).attr("alt"); $($img).parent().replaceWith(`
              ${item_abbr}
              `); } make_search_bar() { const me = this; const doc = me.events.get_frm().doc; - this.$component.find('.search-field').html(''); - this.$component.find('.item-group-field').html(''); + this.$component.find(".search-field").html(""); + this.$component.find(".item-group-field").html(""); this.search_field = frappe.ui.form.make_control({ df: { - label: __('Search'), - fieldtype: 'Data', - placeholder: __('Search by item code, serial number or barcode') + label: __("Search"), + fieldtype: "Data", + placeholder: __("Search by item code, serial number or barcode"), }, - parent: this.$component.find('.search-field'), + parent: this.$component.find(".search-field"), render_input: true, }); this.item_group_field = frappe.ui.form.make_control({ df: { - label: __('Item Group'), - fieldtype: 'Link', - options: 'Item Group', - placeholder: __('Select item group'), - onchange: function() { + label: __("Item Group"), + fieldtype: "Link", + options: "Item Group", + placeholder: __("Select item group"), + onchange: function () { me.item_group = this.value; !me.item_group && (me.item_group = me.parent_item_group); me.filter_items(); }, get_query: function () { return { - query: 'erpnext.selling.page.point_of_sale.point_of_sale.item_group_query', + query: "erpnext.selling.page.point_of_sale.point_of_sale.item_group_query", filters: { - pos_profile: doc ? doc.pos_profile : '' - } + pos_profile: doc ? doc.pos_profile : "", + }, }; }, }, - parent: this.$component.find('.item-group-field'), + parent: this.$component.find(".item-group-field"), render_input: true, }); this.search_field.toggle_label(false); @@ -184,18 +181,18 @@ erpnext.PointOfSale.ItemSelector = class { } attach_clear_btn() { - this.search_field.$wrapper.find('.control-input').append( + this.search_field.$wrapper.find(".control-input").append( ` - ${frappe.utils.icon('close', 'sm')} + ${frappe.utils.icon("close", "sm")} ` ); - this.$clear_search_btn = this.search_field.$wrapper.find('.link-btn'); + this.$clear_search_btn = this.search_field.$wrapper.find(".link-btn"); - this.$clear_search_btn.on('click', 'a', () => { - this.set_search_value(''); + this.$clear_search_btn.on("click", "a", () => { + this.set_search_value(""); this.search_field.set_focus(); }); } @@ -217,39 +214,43 @@ erpnext.PointOfSale.ItemSelector = class { case iCode >= 186 && iCode <= 194: // (; = , - . / `) case iCode >= 219 && iCode <= 222: // ([ \ ] ') case iCode == 32: // spacebar - if (oEvent.key !== undefined && oEvent.key !== '') { + if (oEvent.key !== undefined && oEvent.key !== "") { return oEvent.key; } var sDecoded = String.fromCharCode(iCode); switch (oEvent.shiftKey) { - case false: sDecoded = sDecoded.toLowerCase(); break; - case true: sDecoded = sDecoded.toUpperCase(); break; + case false: + sDecoded = sDecoded.toLowerCase(); + break; + case true: + sDecoded = sDecoded.toUpperCase(); + break; } return sDecoded; case iCode >= 96 && iCode <= 105: // numbers on numeric keypad return 0 + (iCode - 96); } - return ''; + return ""; }; onScan.attachTo(document, { onScan: (sScancode) => { - if (this.search_field && this.$component.is(':visible')) { + if (this.search_field && this.$component.is(":visible")) { this.search_field.set_focus(); this.set_search_value(sScancode); this.barcode_scanned = true; } - } + }, }); - this.$component.on('click', '.item-wrapper', function() { + this.$component.on("click", ".item-wrapper", function () { const $item = $(this); - const item_code = unescape($item.attr('data-item-code')); - let batch_no = unescape($item.attr('data-batch-no')); - let serial_no = unescape($item.attr('data-serial-no')); - let uom = unescape($item.attr('data-uom')); - let rate = unescape($item.attr('data-rate')); + const item_code = unescape($item.attr("data-item-code")); + let batch_no = unescape($item.attr("data-batch-no")); + let serial_no = unescape($item.attr("data-serial-no")); + let uom = unescape($item.attr("data-uom")); + let rate = unescape($item.attr("data-rate")); // escape(undefined) returns "undefined" then unescape returns "undefined" batch_no = batch_no === "undefined" ? undefined : batch_no; @@ -258,76 +259,72 @@ erpnext.PointOfSale.ItemSelector = class { rate = rate === "undefined" ? undefined : rate; me.events.item_selected({ - field: 'qty', + field: "qty", value: "+1", - item: { item_code, batch_no, serial_no, uom, rate } + item: { item_code, batch_no, serial_no, uom, rate }, }); me.search_field.set_focus(); }); - this.search_field.$input.on('input', (e) => { + this.search_field.$input.on("input", (e) => { clearTimeout(this.last_search); this.last_search = setTimeout(() => { const search_term = e.target.value; this.filter_items({ search_term }); }, 300); - this.$clear_search_btn.toggle( - Boolean(this.search_field.$input.val()) - ); + this.$clear_search_btn.toggle(Boolean(this.search_field.$input.val())); }); - this.search_field.$input.on('focus', () => { - this.$clear_search_btn.toggle( - Boolean(this.search_field.$input.val()) - ); + this.search_field.$input.on("focus", () => { + this.$clear_search_btn.toggle(Boolean(this.search_field.$input.val())); }); } attach_shortcuts() { - const ctrl_label = frappe.utils.is_mac() ? '⌘' : 'Ctrl'; + const ctrl_label = frappe.utils.is_mac() ? "⌘" : "Ctrl"; this.search_field.parent.attr("title", `${ctrl_label}+I`); frappe.ui.keys.add_shortcut({ shortcut: "ctrl+i", action: () => this.search_field.set_focus(), - condition: () => this.$component.is(':visible'), + condition: () => this.$component.is(":visible"), description: __("Focus on search input"), ignore_inputs: true, - page: cur_page.page.page + page: cur_page.page.page, }); this.item_group_field.parent.attr("title", `${ctrl_label}+G`); frappe.ui.keys.add_shortcut({ shortcut: "ctrl+g", action: () => this.item_group_field.set_focus(), - condition: () => this.$component.is(':visible'), + condition: () => this.$component.is(":visible"), description: __("Focus on Item Group filter"), ignore_inputs: true, - page: cur_page.page.page + page: cur_page.page.page, }); // for selecting the last filtered item on search frappe.ui.keys.on("enter", () => { - const selector_is_visible = this.$component.is(':visible'); + const selector_is_visible = this.$component.is(":visible"); if (!selector_is_visible || this.search_field.get_value() === "") return; if (this.items.length == 1) { this.$items_container.find(".item-wrapper").click(); frappe.utils.play_sound("submit"); - this.set_search_value(''); + this.set_search_value(""); } else if (this.items.length == 0 && this.barcode_scanned) { // only show alert of barcode is scanned and enter is pressed frappe.show_alert({ message: __("No items found. Scan barcode again."), - indicator: 'orange' + indicator: "orange", }); frappe.utils.play_sound("error"); this.barcode_scanned = false; - this.set_search_value(''); + this.set_search_value(""); } }); } - filter_items({ search_term='' }={}) { + filter_items({ search_term = "" } = {}) { if (search_term) { search_term = search_term.toLowerCase(); @@ -342,44 +339,47 @@ erpnext.PointOfSale.ItemSelector = class { } } - this.get_items({ search_term }) - .then(({ message }) => { - // eslint-disable-next-line no-unused-vars - const { items, serial_no, batch_no, barcode } = message; - if (search_term && !barcode) { - this.search_index[search_term] = items; - } - this.items = items; - this.render_item_list(items); - this.auto_add_item && this.items.length == 1 && this.add_filtered_item_to_cart(); - }); + this.get_items({ search_term }).then(({ message }) => { + // eslint-disable-next-line no-unused-vars + const { items, serial_no, batch_no, barcode } = message; + if (search_term && !barcode) { + this.search_index[search_term] = items; + } + this.items = items; + this.render_item_list(items); + this.auto_add_item && this.items.length == 1 && this.add_filtered_item_to_cart(); + }); } add_filtered_item_to_cart() { this.$items_container.find(".item-wrapper").click(); - this.set_search_value(''); + this.set_search_value(""); } resize_selector(minimize) { - minimize ? - this.$component.find('.filter-section').css('grid-template-columns', 'repeat(1, minmax(0, 1fr))') : - this.$component.find('.filter-section').css('grid-template-columns', 'repeat(12, minmax(0, 1fr))'); - - minimize ? - this.$component.find('.search-field').css('margin', 'var(--margin-sm) 0px') : - this.$component.find('.search-field').css('margin', '0px var(--margin-sm)'); - - minimize ? - this.$component.css('grid-column', 'span 2 / span 2') : - this.$component.css('grid-column', 'span 6 / span 6'); - - minimize ? - this.$items_container.css('grid-template-columns', 'repeat(1, minmax(0, 1fr))') : - this.$items_container.css('grid-template-columns', 'repeat(4, minmax(0, 1fr))'); + minimize + ? this.$component + .find(".filter-section") + .css("grid-template-columns", "repeat(1, minmax(0, 1fr))") + : this.$component + .find(".filter-section") + .css("grid-template-columns", "repeat(12, minmax(0, 1fr))"); + + minimize + ? this.$component.find(".search-field").css("margin", "var(--margin-sm) 0px") + : this.$component.find(".search-field").css("margin", "0px var(--margin-sm)"); + + minimize + ? this.$component.css("grid-column", "span 2 / span 2") + : this.$component.css("grid-column", "span 6 / span 6"); + + minimize + ? this.$items_container.css("grid-template-columns", "repeat(1, minmax(0, 1fr))") + : this.$items_container.css("grid-template-columns", "repeat(4, minmax(0, 1fr))"); } toggle_component(show) { - this.set_search_value(''); - this.$component.css('display', show ? 'flex': 'none'); + this.set_search_value(""); + this.$component.css("display", show ? "flex" : "none"); } }; diff --git a/erpnext/selling/page/point_of_sale/pos_number_pad.js b/erpnext/selling/page/point_of_sale/pos_number_pad.js index f27b0d55ef68..c77f206308df 100644 --- a/erpnext/selling/page/point_of_sale/pos_number_pad.js +++ b/erpnext/selling/page/point_of_sale/pos_number_pad.js @@ -20,28 +20,40 @@ erpnext.PointOfSale.NumberPad = class { function get_keys() { return keys.reduce((a, row, i) => { - return a + row.reduce((a2, number, j) => { - const class_to_append = css_classes && css_classes[i] ? css_classes[i][j] : ''; - const fieldname = fieldnames && fieldnames[number] ? - fieldnames[number] : typeof number === 'string' ? frappe.scrub(number) : number; + return ( + a + + row.reduce((a2, number, j) => { + const class_to_append = css_classes && css_classes[i] ? css_classes[i][j] : ""; + const fieldname = + fieldnames && fieldnames[number] + ? fieldnames[number] + : typeof number === "string" + ? frappe.scrub(number) + : number; - return a2 + `
              ${__(number)}
              `; - }, ''); - }, ''); + return ( + a2 + + `
              ${__( + number + )}
              ` + ); + }, "") + ); + }, ""); } this.wrapper.html( `
              ${get_keys()}
              ` - ) + ); } bind_events() { const me = this; - this.wrapper.on('click', '.numpad-btn', function() { + this.wrapper.on("click", ".numpad-btn", function () { const $btn = $(this); me.events.numpad_event($btn); }); } -} +}; diff --git a/erpnext/selling/page/point_of_sale/pos_past_order_list.js b/erpnext/selling/page/point_of_sale/pos_past_order_list.js index a0475c70d0d3..c450d8a109a6 100644 --- a/erpnext/selling/page/point_of_sale/pos_past_order_list.js +++ b/erpnext/selling/page/point_of_sale/pos_past_order_list.js @@ -16,7 +16,7 @@ erpnext.PointOfSale.PastOrderList = class { this.wrapper.append( `
              -
              ${__('Recent Orders')}
              +
              ${__("Recent Orders")}
              @@ -24,12 +24,12 @@ erpnext.PointOfSale.PastOrderList = class {
              ` ); - this.$component = this.wrapper.find('.past-order-list'); - this.$invoices_container = this.$component.find('.invoices-container'); + this.$component = this.wrapper.find(".past-order-list"); + this.$invoices_container = this.$component.find(".invoices-container"); } bind_events() { - this.search_field.$input.on('input', (e) => { + this.search_field.$input.on("input", (e) => { clearTimeout(this.last_search); this.last_search = setTimeout(() => { const search_term = e.target.value; @@ -37,8 +37,8 @@ erpnext.PointOfSale.PastOrderList = class { }, 300); }); const me = this; - this.$invoices_container.on('click', '.invoice-wrapper', function() { - const invoice_name = unescape($(this).attr('data-invoice-name')); + this.$invoices_container.on("click", ".invoice-wrapper", function () { + const invoice_name = unescape($(this).attr("data-invoice-name")); me.events.open_invoice_data(invoice_name); }); @@ -48,29 +48,29 @@ erpnext.PointOfSale.PastOrderList = class { const me = this; this.search_field = frappe.ui.form.make_control({ df: { - label: __('Search'), - fieldtype: 'Data', - placeholder: __('Search by invoice id or customer name') + label: __("Search"), + fieldtype: "Data", + placeholder: __("Search by invoice id or customer name"), }, - parent: this.$component.find('.search-field'), + parent: this.$component.find(".search-field"), render_input: true, }); this.status_field = frappe.ui.form.make_control({ df: { - label: __('Invoice Status'), - fieldtype: 'Select', + label: __("Invoice Status"), + fieldtype: "Select", options: `Draft\nPaid\nConsolidated\nReturn`, - placeholder: __('Filter by invoice status'), - onchange: function() { - if (me.$component.is(':visible')) me.refresh_list(); - } + placeholder: __("Filter by invoice status"), + onchange: function () { + if (me.$component.is(":visible")) me.refresh_list(); + }, }, - parent: this.$component.find('.status-field'), + parent: this.$component.find(".status-field"), render_input: true, }); this.search_field.toggle_label(false); this.status_field.toggle_label(false); - this.status_field.set_value('Draft'); + this.status_field.set_value("Draft"); } refresh_list() { @@ -79,7 +79,7 @@ erpnext.PointOfSale.PastOrderList = class { const search_term = this.search_field.get_value(); const status = this.status_field.get_value(); - this.$invoices_container.html(''); + this.$invoices_container.html(""); return frappe.call({ method: "erpnext.selling.page.point_of_sale.point_of_sale.get_past_order_list", @@ -87,18 +87,19 @@ erpnext.PointOfSale.PastOrderList = class { args: { search_term, status }, callback: (response) => { frappe.dom.unfreeze(); - response.message.forEach(invoice => { + response.message.forEach((invoice) => { const invoice_html = this.get_invoice_html(invoice); this.$invoices_container.append(invoice_html); }); - } + }, }); } get_invoice_html(invoice) { - const posting_datetime = moment(invoice.posting_date+" "+invoice.posting_time).format("Do MMMM, h:mma"); - return ( - `
              + const posting_datetime = moment(invoice.posting_date + " " + invoice.posting_time).format( + "Do MMMM, h:mma" + ); + return `
              ${invoice.name}
              @@ -113,11 +114,12 @@ erpnext.PointOfSale.PastOrderList = class {
              ${posting_datetime}
              -
              ` - ); +
              `; } toggle_component(show) { - show ? this.$component.css('display', 'flex') && this.refresh_list() : this.$component.css('display', 'none'); + show + ? this.$component.css("display", "flex") && this.refresh_list() + : this.$component.css("display", "none"); } }; diff --git a/erpnext/selling/page/point_of_sale/pos_past_order_summary.js b/erpnext/selling/page/point_of_sale/pos_past_order_summary.js index eeb8523f19c7..53fedbf56cf3 100644 --- a/erpnext/selling/page/point_of_sale/pos_past_order_summary.js +++ b/erpnext/selling/page/point_of_sale/pos_past_order_summary.js @@ -17,16 +17,16 @@ erpnext.PointOfSale.PastOrderSummary = class { this.wrapper.append( `
              - ${__('Select an invoice to load summary data')} + ${__("Select an invoice to load summary data")}
              -
              ${__('Items')}
              +
              ${__("Items")}
              -
              ${__('Totals')}
              +
              ${__("Totals")}
              -
              ${__('Payments')}
              +
              ${__("Payments")}
              @@ -34,55 +34,53 @@ erpnext.PointOfSale.PastOrderSummary = class {
              ` ); - this.$component = this.wrapper.find('.past-order-summary'); - this.$summary_wrapper = this.$component.find('.invoice-summary-wrapper'); - this.$summary_container = this.$component.find('.abs-container'); - this.$upper_section = this.$summary_container.find('.upper-section'); - this.$items_container = this.$summary_container.find('.items-container'); - this.$totals_container = this.$summary_container.find('.totals-container'); - this.$payment_container = this.$summary_container.find('.payments-container'); - this.$summary_btns = this.$summary_container.find('.summary-btns'); + this.$component = this.wrapper.find(".past-order-summary"); + this.$summary_wrapper = this.$component.find(".invoice-summary-wrapper"); + this.$summary_container = this.$component.find(".abs-container"); + this.$upper_section = this.$summary_container.find(".upper-section"); + this.$items_container = this.$summary_container.find(".items-container"); + this.$totals_container = this.$summary_container.find(".totals-container"); + this.$payment_container = this.$summary_container.find(".payments-container"); + this.$summary_btns = this.$summary_container.find(".summary-btns"); } init_email_print_dialog() { const email_dialog = new frappe.ui.Dialog({ - title: 'Email Receipt', + title: "Email Receipt", fields: [ - {fieldname: 'email_id', fieldtype: 'Data', options: 'Email', label: 'Email ID'}, + { fieldname: "email_id", fieldtype: "Data", options: "Email", label: "Email ID" }, // {fieldname:'remarks', fieldtype:'Text', label:'Remarks (if any)'} ], primary_action: () => { this.send_email(); }, - primary_action_label: __('Send'), + primary_action_label: __("Send"), }); this.email_dialog = email_dialog; const print_dialog = new frappe.ui.Dialog({ - title: 'Print Receipt', - fields: [ - {fieldname: 'print', fieldtype: 'Data', label: 'Print Preview'} - ], + title: "Print Receipt", + fields: [{ fieldname: "print", fieldtype: "Data", label: "Print Preview" }], primary_action: () => { this.print_receipt(); }, - primary_action_label: __('Print'), + primary_action_label: __("Print"), }); this.print_dialog = print_dialog; } get_upper_section_html(doc) { const { status } = doc; - let indicator_color = ''; + let indicator_color = ""; - in_list(['Paid', 'Consolidated'], status) && (indicator_color = 'green'); - status === 'Draft' && (indicator_color = 'red'); - status === 'Return' && (indicator_color = 'grey'); + in_list(["Paid", "Consolidated"], status) && (indicator_color = "green"); + status === "Draft" && (indicator_color = "red"); + status === "Return" && (indicator_color = "grey"); return `
              ${doc.customer}
              ${this.customer_email}
              -
              ${__('Sold by')}: ${doc.owner}
              +
              ${__("Sold by")}: ${doc.owner}
              @@ -103,7 +101,10 @@ erpnext.PointOfSale.PastOrderSummary = class { return `(${item_data.discount_percentage}% off)
              ${format_currency(item_data.rate, doc.currency)}
              `; } else { - return `
              ${format_currency(item_data.price_list_rate || item_data.rate, doc.currency)}
              `; + return `
              ${format_currency( + item_data.price_list_rate || item_data.rate, + doc.currency + )}
              `; } } } @@ -121,30 +122,34 @@ erpnext.PointOfSale.PastOrderSummary = class { get_net_total_html(doc) { return `
              -
              ${__('Net Total')}
              +
              ${__("Net Total")}
              ${format_currency(doc.net_total, doc.currency)}
              `; } get_taxes_html(doc) { - if (!doc.taxes.length) return ''; - - let taxes_html = doc.taxes.map(t => { - const description = /[0-9]+/.test(t.description) ? t.description : `${t.description} @ ${t.rate}%`; - return ` + if (!doc.taxes.length) return ""; + + let taxes_html = doc.taxes + .map((t) => { + const description = /[0-9]+/.test(t.description) + ? t.description + : `${t.description} @ ${t.rate}%`; + return `
              ${description}
              ${format_currency(t.tax_amount_after_discount_amount, doc.currency)}
              `; - }).join(''); + }) + .join(""); return `
              ${taxes_html}
              `; } get_grand_total_html(doc) { return `
              -
              ${__('Grand Total')}
              +
              ${__("Grand Total")}
              ${format_currency(doc.grand_total, doc.currency)}
              `; } @@ -157,26 +162,26 @@ erpnext.PointOfSale.PastOrderSummary = class { } bind_events() { - this.$summary_container.on('click', '.return-btn', () => { + this.$summary_container.on("click", ".return-btn", () => { this.events.process_return(this.doc.name); this.toggle_component(false); - this.$component.find('.no-summary-placeholder').css('display', 'flex'); - this.$summary_wrapper.css('display', 'none'); + this.$component.find(".no-summary-placeholder").css("display", "flex"); + this.$summary_wrapper.css("display", "none"); }); - this.$summary_container.on('click', '.edit-btn', () => { + this.$summary_container.on("click", ".edit-btn", () => { this.events.edit_order(this.doc.name); this.toggle_component(false); - this.$component.find('.no-summary-placeholder').css('display', 'flex'); - this.$summary_wrapper.css('display', 'none'); + this.$component.find(".no-summary-placeholder").css("display", "flex"); + this.$summary_wrapper.css("display", "none"); }); - this.$summary_container.on('click', '.delete-btn', () => { + this.$summary_container.on("click", ".delete-btn", () => { this.events.delete_order(this.doc.name); this.show_summary_placeholder(); }); - this.$summary_container.on('click', '.delete-btn', () => { + this.$summary_container.on("click", ".delete-btn", () => { this.events.delete_order(this.doc.name); this.show_summary_placeholder(); // this.toggle_component(false); @@ -184,19 +189,19 @@ erpnext.PointOfSale.PastOrderSummary = class { // this.$summary_wrapper.addClass('d-none'); }); - this.$summary_container.on('click', '.new-btn', () => { + this.$summary_container.on("click", ".new-btn", () => { this.events.new_order(); this.toggle_component(false); - this.$component.find('.no-summary-placeholder').css('display', 'flex'); - this.$summary_wrapper.css('display', 'none'); + this.$component.find(".no-summary-placeholder").css("display", "flex"); + this.$summary_wrapper.css("display", "none"); }); - this.$summary_container.on('click', '.email-btn', () => { + this.$summary_container.on("click", ".email-btn", () => { this.email_dialog.fields_dict.email_id.set_value(this.customer_email); this.email_dialog.show(); }); - this.$summary_container.on('click', '.print-btn', () => { + this.$summary_container.on("click", ".print-btn", () => { this.print_receipt(); }); } @@ -213,29 +218,31 @@ erpnext.PointOfSale.PastOrderSummary = class { } attach_shortcuts() { - const ctrl_label = frappe.utils.is_mac() ? '⌘' : 'Ctrl'; - this.$summary_container.find('.print-btn').attr("title", `${ctrl_label}+P`); + const ctrl_label = frappe.utils.is_mac() ? "⌘" : "Ctrl"; + this.$summary_container.find(".print-btn").attr("title", `${ctrl_label}+P`); frappe.ui.keys.add_shortcut({ shortcut: "ctrl+p", - action: () => this.$summary_container.find('.print-btn').click(), - condition: () => this.$component.is(':visible') && this.$summary_container.find('.print-btn').is(":visible"), + action: () => this.$summary_container.find(".print-btn").click(), + condition: () => + this.$component.is(":visible") && this.$summary_container.find(".print-btn").is(":visible"), description: __("Print Receipt"), - page: cur_page.page.page + page: cur_page.page.page, }); - this.$summary_container.find('.new-btn').attr("title", `${ctrl_label}+Enter`); + this.$summary_container.find(".new-btn").attr("title", `${ctrl_label}+Enter`); frappe.ui.keys.on("ctrl+enter", () => { const summary_is_visible = this.$component.is(":visible"); - if (summary_is_visible && this.$summary_container.find('.new-btn').is(":visible")) { - this.$summary_container.find('.new-btn').click(); + if (summary_is_visible && this.$summary_container.find(".new-btn").is(":visible")) { + this.$summary_container.find(".new-btn").click(); } }); - this.$summary_container.find('.edit-btn').attr("title", `${ctrl_label}+E`); + this.$summary_container.find(".edit-btn").attr("title", `${ctrl_label}+E`); frappe.ui.keys.add_shortcut({ shortcut: "ctrl+e", - action: () => this.$summary_container.find('.edit-btn').click(), - condition: () => this.$component.is(':visible') && this.$summary_container.find('.edit-btn').is(":visible"), + action: () => this.$summary_container.find(".edit-btn").click(), + condition: () => + this.$component.is(":visible") && this.$summary_container.find(".edit-btn").is(":visible"), description: __("Edit Receipt"), - page: cur_page.page.page + page: cur_page.page.page, }); } @@ -249,42 +256,43 @@ erpnext.PointOfSale.PastOrderSummary = class { method: "frappe.core.doctype.communication.email.make", args: { recipients: recipients, - subject: __(frm.meta.name) + ': ' + doc.name, + subject: __(frm.meta.name) + ": " + doc.name, doctype: doc.doctype, name: doc.name, send_email: 1, print_format, sender_full_name: frappe.user.full_name(), - _lang: doc.language + _lang: doc.language, }, - callback: r => { + callback: (r) => { if (!r.exc) { frappe.utils.play_sound("email"); if (r.message["emails_not_sent_to"]) { - frappe.msgprint(__( - "Email not sent to {0} (unsubscribed / disabled)", - [ frappe.utils.escape_html(r.message["emails_not_sent_to"]) ] - )); + frappe.msgprint( + __("Email not sent to {0} (unsubscribed / disabled)", [ + frappe.utils.escape_html(r.message["emails_not_sent_to"]), + ]) + ); } else { frappe.show_alert({ - message: __('Email sent successfully.'), - indicator: 'green' + message: __("Email sent successfully."), + indicator: "green", }); } this.email_dialog.hide(); } else { frappe.msgprint(__("There were errors while sending email. Please try again.")); } - } + }, }); } add_summary_btns(map) { - this.$summary_btns.html(''); - map.forEach(m => { + this.$summary_btns.html(""); + map.forEach((m) => { if (m.condition) { - m.visible_btns.forEach(b => { - const class_name = b.split(' ')[0].toLowerCase(); + m.visible_btns.forEach((b) => { + const class_name = b.split(" ")[0].toLowerCase(); const btn = __(b); this.$summary_btns.append( `
              ${btn}
              ` @@ -292,34 +300,40 @@ erpnext.PointOfSale.PastOrderSummary = class { }); } }); - this.$summary_btns.children().last().removeClass('mr-4'); + this.$summary_btns.children().last().removeClass("mr-4"); } toggle_summary_placeholder(show) { if (show) { - this.$summary_wrapper.css('display', 'none'); - this.$component.find('.no-summary-placeholder').css('display', 'flex'); + this.$summary_wrapper.css("display", "none"); + this.$component.find(".no-summary-placeholder").css("display", "flex"); } else { - this.$summary_wrapper.css('display', 'flex'); - this.$component.find('.no-summary-placeholder').css('display', 'none'); + this.$summary_wrapper.css("display", "flex"); + this.$component.find(".no-summary-placeholder").css("display", "none"); } } get_condition_btn_map(after_submission) { if (after_submission) - return [{ condition: true, visible_btns: ['Print Receipt', 'Email Receipt', 'New Order'] }]; + return [{ condition: true, visible_btns: ["Print Receipt", "Email Receipt", "New Order"] }]; return [ - { condition: this.doc.docstatus === 0, visible_btns: ['Edit Order', 'Delete Order'] }, - { condition: !this.doc.is_return && this.doc.docstatus === 1, visible_btns: ['Print Receipt', 'Email Receipt', 'Return']}, - { condition: this.doc.is_return && this.doc.docstatus === 1, visible_btns: ['Print Receipt', 'Email Receipt']} + { condition: this.doc.docstatus === 0, visible_btns: ["Edit Order", "Delete Order"] }, + { + condition: !this.doc.is_return && this.doc.docstatus === 1, + visible_btns: ["Print Receipt", "Email Receipt", "Return"], + }, + { + condition: this.doc.is_return && this.doc.docstatus === 1, + visible_btns: ["Print Receipt", "Email Receipt"], + }, ]; } - load_summary_of(doc, after_submission=false) { - after_submission ? - this.$component.css('grid-column', 'span 10 / span 10') : - this.$component.css('grid-column', 'span 6 / span 6'); + load_summary_of(doc, after_submission = false) { + after_submission + ? this.$component.css("grid-column", "span 10 / span 10") + : this.$component.css("grid-column", "span 6 / span 6"); this.toggle_summary_placeholder(false); @@ -339,16 +353,16 @@ erpnext.PointOfSale.PastOrderSummary = class { } attach_document_info(doc) { - frappe.db.get_value('Customer', this.doc.customer, 'email_id').then(({ message }) => { - this.customer_email = message.email_id || ''; + frappe.db.get_value("Customer", this.doc.customer, "email_id").then(({ message }) => { + this.customer_email = message.email_id || ""; const upper_section_dom = this.get_upper_section_html(doc); this.$upper_section.html(upper_section_dom); }); } attach_items_info(doc) { - this.$items_container.html(''); - doc.items.forEach(item => { + this.$items_container.html(""); + doc.items.forEach((item) => { const item_dom = this.get_item_html(doc, item); this.$items_container.append(item_dom); this.set_dynamic_rate_header_width(); @@ -359,8 +373,7 @@ erpnext.PointOfSale.PastOrderSummary = class { const rate_cols = Array.from(this.$items_container.find(".item-rate-disc")); this.$items_container.find(".item-rate-disc").css("width", ""); let max_width = rate_cols.reduce((max_width, elm) => { - if ($(elm).width() > max_width) - max_width = $(elm).width(); + if ($(elm).width() > max_width) max_width = $(elm).width(); return max_width; }, 0); @@ -371,8 +384,8 @@ erpnext.PointOfSale.PastOrderSummary = class { } attach_payments_info(doc) { - this.$payment_container.html(''); - doc.payments.forEach(p => { + this.$payment_container.html(""); + doc.payments.forEach((p) => { if (p.amount) { const payment_dom = this.get_payment_html(doc, p); this.$payment_container.append(payment_dom); @@ -380,7 +393,7 @@ erpnext.PointOfSale.PastOrderSummary = class { }); if (doc.redeem_loyalty_points && doc.loyalty_amount) { const payment_dom = this.get_payment_html(doc, { - mode_of_payment: 'Loyalty Points', + mode_of_payment: "Loyalty Points", amount: doc.loyalty_amount, }); this.$payment_container.append(payment_dom); @@ -388,7 +401,7 @@ erpnext.PointOfSale.PastOrderSummary = class { } attach_totals_info(doc) { - this.$totals_container.html(''); + this.$totals_container.html(""); const net_total_dom = this.get_net_total_html(doc); const taxes_dom = this.get_taxes_html(doc); @@ -401,6 +414,6 @@ erpnext.PointOfSale.PastOrderSummary = class { } toggle_component(show) { - show ? this.$component.css('display', 'flex') : this.$component.css('display', 'none'); + show ? this.$component.css("display", "flex") : this.$component.css("display", "none"); } }; diff --git a/erpnext/selling/page/point_of_sale/pos_payment.js b/erpnext/selling/page/point_of_sale/pos_payment.js index 89ce61ab1680..232b6a02123f 100644 --- a/erpnext/selling/page/point_of_sale/pos_payment.js +++ b/erpnext/selling/page/point_of_sale/pos_payment.js @@ -12,17 +12,16 @@ erpnext.PointOfSale.Payment = class { this.initialize_numpad(); this.bind_events(); this.attach_shortcuts(); - } prepare_dom() { this.wrapper.append( `
              - +
              - +
              @@ -33,12 +32,12 @@ erpnext.PointOfSale.Payment = class {
              ${__("Complete Order")}
              ` ); - this.$component = this.wrapper.find('.payment-container'); - this.$payment_modes = this.$component.find('.payment-modes'); - this.$totals_section = this.$component.find('.totals-section'); - this.$totals = this.$component.find('.totals'); - this.$numpad = this.$component.find('.number-pad'); - this.$invoice_fields_section = this.$component.find('.fields-section'); + this.$component = this.wrapper.find(".payment-container"); + this.$payment_modes = this.$component.find(".payment-modes"); + this.$totals_section = this.$component.find(".totals-section"); + this.$totals = this.$component.find(".totals"); + this.$numpad = this.$component.find(".number-pad"); + this.$invoice_fields_section = this.$component.find(".fields-section"); } make_invoice_fields_control() { @@ -46,33 +45,33 @@ erpnext.PointOfSale.Payment = class { const fields = doc.invoice_fields; if (!fields.length) return; - this.$invoice_fields = this.$invoice_fields_section.find('.invoice-fields'); - this.$invoice_fields.html(''); + this.$invoice_fields = this.$invoice_fields_section.find(".invoice-fields"); + this.$invoice_fields.html(""); const frm = this.events.get_frm(); - fields.forEach(df => { + fields.forEach((df) => { this.$invoice_fields.append( `
              ` ); let df_events = { - onchange: function() { + onchange: function () { frm.set_value(this.df.fieldname, this.get_value()); - } + }, }; if (df.fieldtype == "Button") { df_events = { - click: function() { + click: function () { if (frm.script_manager.has_handlers(df.fieldname, frm.doc.doctype)) { frm.script_manager.trigger(df.fieldname, frm.doc.doctype, frm.doc.docname); } - } + }, }; } this[`${df.fieldname}_field`] = frappe.ui.form.make_control({ df: { ...df, - ...df_events + ...df_events, }, parent: this.$invoice_fields.find(`.${df.fieldname}-field`), render_input: true, @@ -87,34 +86,35 @@ erpnext.PointOfSale.Payment = class { this.number_pad = new erpnext.PointOfSale.NumberPad({ wrapper: this.$numpad, events: { - numpad_event: function($btn) { + numpad_event: function ($btn) { me.on_numpad_clicked($btn); - } + }, }, cols: 3, keys: [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ], - [ '.', 0, 'Delete' ] + [1, 2, 3], + [4, 5, 6], + [7, 8, 9], + [".", 0, "Delete"], ], }); - this.numpad_value = ''; + this.numpad_value = ""; } on_numpad_clicked($btn) { - const button_value = $btn.attr('data-button-value'); + const button_value = $btn.attr("data-button-value"); highlight_numpad_btn($btn); - this.numpad_value = button_value === 'delete' ? this.numpad_value.slice(0, -1) : this.numpad_value + button_value; + this.numpad_value = + button_value === "delete" ? this.numpad_value.slice(0, -1) : this.numpad_value + button_value; this.selected_mode.$input.get(0).focus(); this.selected_mode.set_value(this.numpad_value); function highlight_numpad_btn($btn) { - $btn.addClass('shadow-base-inner bg-selected'); + $btn.addClass("shadow-base-inner bg-selected"); setTimeout(() => { - $btn.removeClass('shadow-base-inner bg-selected'); + $btn.removeClass("shadow-base-inner bg-selected"); }, 100); } } @@ -122,36 +122,37 @@ erpnext.PointOfSale.Payment = class { bind_events() { const me = this; - this.$payment_modes.on('click', '.mode-of-payment', function(e) { + this.$payment_modes.on("click", ".mode-of-payment", function (e) { const mode_clicked = $(this); // if clicked element doesn't have .mode-of-payment class then return if (!$(e.target).is(mode_clicked)) return; - const scrollLeft = mode_clicked.offset().left - me.$payment_modes.offset().left + me.$payment_modes.scrollLeft(); + const scrollLeft = + mode_clicked.offset().left - me.$payment_modes.offset().left + me.$payment_modes.scrollLeft(); me.$payment_modes.animate({ scrollLeft }); - const mode = mode_clicked.attr('data-mode'); + const mode = mode_clicked.attr("data-mode"); // hide all control fields and shortcuts - $(`.mode-of-payment-control`).css('display', 'none'); - $(`.cash-shortcuts`).css('display', 'none'); - me.$payment_modes.find(`.pay-amount`).css('display', 'inline'); - me.$payment_modes.find(`.loyalty-amount-name`).css('display', 'none'); + $(`.mode-of-payment-control`).css("display", "none"); + $(`.cash-shortcuts`).css("display", "none"); + me.$payment_modes.find(`.pay-amount`).css("display", "inline"); + me.$payment_modes.find(`.loyalty-amount-name`).css("display", "none"); // remove highlight from all mode-of-payments - $('.mode-of-payment').removeClass('border-primary'); + $(".mode-of-payment").removeClass("border-primary"); - if (mode_clicked.hasClass('border-primary')) { + if (mode_clicked.hasClass("border-primary")) { // clicked one is selected then unselect it - mode_clicked.removeClass('border-primary'); - me.selected_mode = ''; + mode_clicked.removeClass("border-primary"); + me.selected_mode = ""; } else { // clicked one is not selected then select it - mode_clicked.addClass('border-primary'); - mode_clicked.find('.mode-of-payment-control').css('display', 'flex'); - mode_clicked.find('.cash-shortcuts').css('display', 'grid'); - me.$payment_modes.find(`.${mode}-amount`).css('display', 'none'); - me.$payment_modes.find(`.${mode}-name`).css('display', 'inline'); + mode_clicked.addClass("border-primary"); + mode_clicked.find(".mode-of-payment-control").css("display", "flex"); + mode_clicked.find(".cash-shortcuts").css("display", "grid"); + me.$payment_modes.find(`.${mode}-amount`).css("display", "none"); + me.$payment_modes.find(`.${mode}-name`).css("display", "inline"); me.selected_mode = me[`${mode}_control`]; me.selected_mode && me.selected_mode.$input.get(0).focus(); @@ -159,33 +160,33 @@ erpnext.PointOfSale.Payment = class { } }); - frappe.ui.form.on('POS Invoice', 'contact_mobile', (frm) => { + frappe.ui.form.on("POS Invoice", "contact_mobile", (frm) => { const contact = frm.doc.contact_mobile; const request_button = $(this.request_for_payment_field?.$input[0]); if (contact) { - request_button.removeClass('btn-default').addClass('btn-primary'); + request_button.removeClass("btn-default").addClass("btn-primary"); } else { - request_button.removeClass('btn-primary').addClass('btn-default'); + request_button.removeClass("btn-primary").addClass("btn-default"); } }); - frappe.ui.form.on('POS Invoice', 'coupon_code', (frm) => { + frappe.ui.form.on("POS Invoice", "coupon_code", (frm) => { if (frm.doc.coupon_code && !frm.applying_pos_coupon_code) { if (!frm.doc.ignore_pricing_rule) { frm.applying_pos_coupon_code = true; frappe.run_serially([ - () => frm.doc.ignore_pricing_rule=1, - () => frm.trigger('ignore_pricing_rule'), - () => frm.doc.ignore_pricing_rule=0, - () => frm.trigger('apply_pricing_rule'), + () => (frm.doc.ignore_pricing_rule = 1), + () => frm.trigger("ignore_pricing_rule"), + () => (frm.doc.ignore_pricing_rule = 0), + () => frm.trigger("apply_pricing_rule"), () => frm.save(), () => this.update_totals_section(frm.doc), - () => (frm.applying_pos_coupon_code = false) + () => (frm.applying_pos_coupon_code = false), ]); } else if (frm.doc.ignore_pricing_rule) { frappe.show_alert({ message: __("Ignore Pricing Rule is enabled. Cannot apply coupon code."), - indicator: "orange" + indicator: "orange", }); } } @@ -193,18 +194,20 @@ erpnext.PointOfSale.Payment = class { this.setup_listener_for_payments(); - this.$payment_modes.on('click', '.shortcut', function() { - const value = $(this).attr('data-value'); + this.$payment_modes.on("click", ".shortcut", function () { + const value = $(this).attr("data-value"); me.selected_mode.set_value(value); }); - this.$component.on('click', '.submit-order-btn', () => { + this.$component.on("click", ".submit-order-btn", () => { const doc = this.events.get_frm().doc; const paid_amount = doc.paid_amount; const items = doc.items; if (paid_amount == 0 || !items.length) { - const message = items.length ? __("You cannot submit the order without payment.") : __("You cannot submit empty order."); + const message = items.length + ? __("You cannot submit the order without payment.") + : __("You cannot submit empty order."); frappe.show_alert({ message, indicator: "orange" }); frappe.utils.play_sound("error"); return; @@ -213,17 +216,18 @@ erpnext.PointOfSale.Payment = class { this.events.submit_invoice(); }); - frappe.ui.form.on('POS Invoice', 'paid_amount', (frm) => { + frappe.ui.form.on("POS Invoice", "paid_amount", (frm) => { this.update_totals_section(frm.doc); // need to re calculate cash shortcuts after discount is applied - const is_cash_shortcuts_invisible = !this.$payment_modes.find('.cash-shortcuts').is(':visible'); + const is_cash_shortcuts_invisible = !this.$payment_modes.find(".cash-shortcuts").is(":visible"); this.attach_cash_shortcuts(frm.doc); - !is_cash_shortcuts_invisible && this.$payment_modes.find('.cash-shortcuts').css('display', 'grid'); + !is_cash_shortcuts_invisible && + this.$payment_modes.find(".cash-shortcuts").css("display", "grid"); this.render_payment_mode_dom(); }); - frappe.ui.form.on('POS Invoice', 'loyalty_amount', (frm) => { + frappe.ui.form.on("POS Invoice", "loyalty_amount", (frm) => { const formatted_currency = format_currency(frm.doc.loyalty_amount, frm.doc.currency); this.$payment_modes.find(`.loyalty-amount-amount`).html(formatted_currency); }); @@ -246,28 +250,36 @@ erpnext.PointOfSale.Payment = class { if (success) { title = __("Payment Received"); - const grand_total = cint(frappe.sys_defaults.disable_rounded_total) ? doc.grand_total : doc.rounded_total; + const grand_total = cint(frappe.sys_defaults.disable_rounded_total) + ? doc.grand_total + : doc.rounded_total; if (amount >= grand_total) { frappe.dom.unfreeze(); - message = __("Payment of {0} received successfully.", [format_currency(amount, doc.currency, 0)]); + message = __("Payment of {0} received successfully.", [ + format_currency(amount, doc.currency, 0), + ]); this.events.submit_invoice(); cur_frm.reload_doc(); - } else { - message = __("Payment of {0} received successfully. Waiting for other requests to complete...", [format_currency(amount, doc.currency, 0)]); + message = __( + "Payment of {0} received successfully. Waiting for other requests to complete...", + [format_currency(amount, doc.currency, 0)] + ); } } else if (failure_message) { message = failure_message; title = __("Payment Failed"); } - frappe.msgprint({ "message": message, "title": title }); + frappe.msgprint({ message: message, title: title }); }); } auto_set_remaining_amount() { const doc = this.events.get_frm().doc; - const grand_total = cint(frappe.sys_defaults.disable_rounded_total) ? doc.grand_total : doc.rounded_total; + const grand_total = cint(frappe.sys_defaults.disable_rounded_total) + ? doc.grand_total + : doc.rounded_total; const remaining_amount = grand_total - doc.paid_amount; const current_value = this.selected_mode ? this.selected_mode.get_value() : undefined; if (!current_value && remaining_amount > 0 && this.selected_mode) { @@ -276,13 +288,13 @@ erpnext.PointOfSale.Payment = class { } attach_shortcuts() { - const ctrl_label = frappe.utils.is_mac() ? '⌘' : 'Ctrl'; - this.$component.find('.submit-order-btn').attr("title", `${ctrl_label}+Enter`); + const ctrl_label = frappe.utils.is_mac() ? "⌘" : "Ctrl"; + this.$component.find(".submit-order-btn").attr("title", `${ctrl_label}+Enter`); frappe.ui.keys.on("ctrl+enter", () => { const payment_is_visible = this.$component.is(":visible"); const active_mode = this.$payment_modes.find(".border-primary"); if (payment_is_visible && active_mode.length) { - this.$component.find('.submit-order-btn').click(); + this.$component.find(".submit-order-btn").click(); } }); @@ -295,19 +307,24 @@ erpnext.PointOfSale.Payment = class { if (!active_mode) return; - const mode_of_payments = Array.from(this.$payment_modes.find(".mode-of-payment")).map(m => $(m).attr("data-mode")); + const mode_of_payments = Array.from(this.$payment_modes.find(".mode-of-payment")).map((m) => + $(m).attr("data-mode") + ); const mode_index = mode_of_payments.indexOf(active_mode); const next_mode_index = (mode_index + 1) % mode_of_payments.length; - const next_mode_to_be_clicked = this.$payment_modes.find(`.mode-of-payment[data-mode="${mode_of_payments[next_mode_index]}"]`); + const next_mode_to_be_clicked = this.$payment_modes.find( + `.mode-of-payment[data-mode="${mode_of_payments[next_mode_index]}"]` + ); if (payment_is_visible && mode_index != next_mode_index) { next_mode_to_be_clicked.click(); } }, - condition: () => this.$component.is(':visible') && this.$payment_modes.find(".border-primary").length, + condition: () => + this.$component.is(":visible") && this.$payment_modes.find(".border-primary").length, description: __("Switch Between Payment Modes"), ignore_inputs: true, - page: cur_page.page.page + page: cur_page.page.page, }); } @@ -341,20 +358,20 @@ erpnext.PointOfSale.Payment = class { } toggle_remarks_control() { - if (this.$remarks.find('.frappe-control').length) { - this.$remarks.html('+ Add Remark'); + if (this.$remarks.find(".frappe-control").length) { + this.$remarks.html("+ Add Remark"); } else { - this.$remarks.html(''); + this.$remarks.html(""); this[`remark_control`] = frappe.ui.form.make_control({ df: { - label: __('Remark'), - fieldtype: 'Data', - onchange: function() {} + label: __("Remark"), + fieldtype: "Data", + onchange: function () {}, }, parent: this.$totals_section.find(`.remarks`), render_input: true, }); - this[`remark_control`].set_value(''); + this[`remark_control`].set_value(""); } } @@ -363,14 +380,15 @@ erpnext.PointOfSale.Payment = class { const payments = doc.payments; const currency = doc.currency; - this.$payment_modes.html(`${ - payments.map((p, i) => { - const mode = p.mode_of_payment.replace(/ +/g, "_").toLowerCase(); - const payment_type = p.type; - const margin = i % 2 === 0 ? 'pr-2' : 'pl-2'; - const amount = p.amount > 0 ? format_currency(p.amount, currency) : ''; + this.$payment_modes.html( + `${payments + .map((p, i) => { + const mode = p.mode_of_payment.replace(/ +/g, "_").toLowerCase(); + const payment_type = p.type; + const margin = i % 2 === 0 ? "pr-2" : "pl-2"; + const amount = p.amount > 0 ? format_currency(p.amount, currency) : ""; - return (` + return `
              ${p.mode_of_payment} @@ -378,29 +396,30 @@ erpnext.PointOfSale.Payment = class {
              - `); - }).join('') - }`); + `; + }) + .join("")}` + ); - payments.forEach(p => { + payments.forEach((p) => { const mode = p.mode_of_payment.replace(/ +/g, "_").toLowerCase(); const me = this; this[`${mode}_control`] = frappe.ui.form.make_control({ df: { label: p.mode_of_payment, - fieldtype: 'Currency', - placeholder: __('Enter {0} amount.', [p.mode_of_payment]), - onchange: function() { - const current_value = frappe.model.get_value(p.doctype, p.name, 'amount'); + fieldtype: "Currency", + placeholder: __("Enter {0} amount.", [p.mode_of_payment]), + onchange: function () { + const current_value = frappe.model.get_value(p.doctype, p.name, "amount"); if (current_value != this.value) { frappe.model - .set_value(p.doctype, p.name, 'amount', flt(this.value)) - .then(() => me.update_totals_section()) + .set_value(p.doctype, p.name, "amount", flt(this.value)) + .then(() => me.update_totals_section()); const formatted_currency = format_currency(this.value, currency); me.$payment_modes.find(`.${mode}-amount`).html(formatted_currency); } - } + }, }, parent: this.$payment_modes.find(`.${mode}.mode-of-payment-control`), render_input: true, @@ -417,7 +436,7 @@ erpnext.PointOfSale.Payment = class { focus_on_default_mop() { const doc = this.events.get_frm().doc; const payments = doc.payments; - payments.forEach(p => { + payments.forEach((p) => { const mode = p.mode_of_payment.replace(/ +/g, "_").toLowerCase(); if (p.default) { setTimeout(() => { @@ -428,17 +447,23 @@ erpnext.PointOfSale.Payment = class { } attach_cash_shortcuts(doc) { - const grand_total = cint(frappe.sys_defaults.disable_rounded_total) ? doc.grand_total : doc.rounded_total; + const grand_total = cint(frappe.sys_defaults.disable_rounded_total) + ? doc.grand_total + : doc.rounded_total; const currency = doc.currency; const shortcuts = this.get_cash_shortcuts(flt(grand_total)); - this.$payment_modes.find('.cash-shortcuts').remove(); - let shortcuts_html = shortcuts.map(s => { - return `
              ${format_currency(s, currency, 0)}
              `; - }).join(''); + this.$payment_modes.find(".cash-shortcuts").remove(); + let shortcuts_html = shortcuts + .map((s) => { + return `
              ${format_currency(s, currency, 0)}
              `; + }) + .join(""); - this.$payment_modes.find('[data-payment-type="Cash"]').find('.mode-of-payment-control') + this.$payment_modes + .find('[data-payment-type="Cash"]') + .find(".mode-of-payment-control") .after(`
              ${shortcuts_html}
              `); } @@ -446,10 +471,10 @@ erpnext.PointOfSale.Payment = class { let steps = [1, 5, 10]; const digits = String(Math.round(grand_total)).length; - steps = steps.map(x => x * (10 ** (digits - 2))); + steps = steps.map((x) => x * 10 ** (digits - 2)); const get_nearest = (amount, x) => { - let nearest_x = Math.ceil((amount / x)) * x; + let nearest_x = Math.ceil(amount / x) * x; return nearest_x === amount ? nearest_x + x : nearest_x; }; @@ -474,13 +499,16 @@ erpnext.PointOfSale.Payment = class { description = __("You don't have enough points to redeem."); read_only = true; } else { - max_redeemable_amount = flt(flt(loyalty_points) * flt(conversion_factor), precision("loyalty_amount", doc)); + max_redeemable_amount = flt( + flt(loyalty_points) * flt(conversion_factor), + precision("loyalty_amount", doc) + ); description = __("You can redeem upto {0}.", [format_currency(max_redeemable_amount)]); read_only = false; } - const margin = this.$payment_modes.children().length % 2 === 0 ? 'pr-2' : 'pl-2'; - const amount = doc.loyalty_amount > 0 ? format_currency(doc.loyalty_amount, doc.currency) : ''; + const margin = this.$payment_modes.children().length % 2 === 0 ? "pr-2" : "pl-2"; + const amount = doc.loyalty_amount > 0 ? format_currency(doc.loyalty_amount, doc.currency) : ""; this.$payment_modes.append( `
              @@ -492,35 +520,47 @@ erpnext.PointOfSale.Payment = class {
              ` ); - this['loyalty-amount_control'] = frappe.ui.form.make_control({ + this["loyalty-amount_control"] = frappe.ui.form.make_control({ df: { label: __("Redeem Loyalty Points"), - fieldtype: 'Currency', + fieldtype: "Currency", placeholder: __("Enter amount to be redeemed."), - options: 'company:currency', + options: "company:currency", read_only, - onchange: async function() { + onchange: async function () { if (!loyalty_points) return; if (this.value > max_redeemable_amount) { frappe.show_alert({ - message: __("You cannot redeem more than {0}.", [format_currency(max_redeemable_amount)]), - indicator: "red" + message: __("You cannot redeem more than {0}.", [ + format_currency(max_redeemable_amount), + ]), + indicator: "red", }); frappe.utils.play_sound("submit"); - me['loyalty-amount_control'].set_value(0); + me["loyalty-amount_control"].set_value(0); return; } const redeem_loyalty_points = this.value > 0 ? 1 : 0; - await frappe.model.set_value(doc.doctype, doc.name, 'redeem_loyalty_points', redeem_loyalty_points); - frappe.model.set_value(doc.doctype, doc.name, 'loyalty_points', parseInt(this.value / conversion_factor)); + await frappe.model.set_value( + doc.doctype, + doc.name, + "redeem_loyalty_points", + redeem_loyalty_points + ); + frappe.model.set_value( + doc.doctype, + doc.name, + "loyalty_points", + parseInt(this.value / conversion_factor) + ); }, - description + description, }, parent: this.$payment_modes.find(`.loyalty-amount.mode-of-payment-control`), render_input: true, }); - this['loyalty-amount_control'].toggle_label(false); + this["loyalty-amount_control"].toggle_label(false); // this.render_add_payment_method_dom(); } @@ -538,20 +578,22 @@ erpnext.PointOfSale.Payment = class { update_totals_section(doc) { if (!doc) doc = this.events.get_frm().doc; const paid_amount = doc.paid_amount; - const grand_total = cint(frappe.sys_defaults.disable_rounded_total) ? doc.grand_total : doc.rounded_total; + const grand_total = cint(frappe.sys_defaults.disable_rounded_total) + ? doc.grand_total + : doc.rounded_total; const remaining = grand_total - doc.paid_amount; const change = doc.change_amount || remaining <= 0 ? -1 * remaining : undefined; const currency = doc.currency; - const label = change ? __('Change') : __('To Be Paid'); + const label = change ? __("Change") : __("To Be Paid"); this.$totals.html( `
              -
              ${__('Grand Total')}
              +
              ${__("Grand Total")}
              ${format_currency(grand_total, currency)}
              -
              ${__('Paid Amount')}
              +
              ${__("Paid Amount")}
              ${format_currency(paid_amount, currency)}
              @@ -563,6 +605,6 @@ erpnext.PointOfSale.Payment = class { } toggle_component(show) { - show ? this.$component.css('display', 'flex') : this.$component.css('display', 'none'); + show ? this.$component.css("display", "flex") : this.$component.css("display", "none"); } }; diff --git a/erpnext/selling/page/sales_funnel/sales_funnel.js b/erpnext/selling/page/sales_funnel/sales_funnel.js index c37c72663620..d8546ba51cee 100644 --- a/erpnext/selling/page/sales_funnel/sales_funnel.js +++ b/erpnext/selling/page/sales_funnel/sales_funnel.js @@ -1,23 +1,23 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -frappe.pages['sales-funnel'].on_page_load = function(wrapper) { +frappe.pages["sales-funnel"].on_page_load = function (wrapper) { frappe.ui.make_app_page({ parent: wrapper, - title: __('Sales Funnel'), - single_column: true + title: __("Sales Funnel"), + single_column: true, }); wrapper.sales_funnel = new erpnext.SalesFunnel(wrapper); frappe.breadcrumbs.add("Selling"); -} +}; erpnext.SalesFunnel = class SalesFunnel { constructor(wrapper) { var me = this; // 0 setTimeout hack - this gives time for canvas to get width and height - setTimeout(function() { + setTimeout(function () { me.setup(wrapper); me.get_data(); }, 0); @@ -26,50 +26,65 @@ erpnext.SalesFunnel = class SalesFunnel { setup(wrapper) { var me = this; - this.company_field = wrapper.page.add_field({"fieldtype": "Link", "fieldname": "company", "options": "Company", - "label": __("Company"), "reqd": 1, "default": frappe.defaults.get_user_default('company'), - change: function() { - me.company = this.value || frappe.defaults.get_user_default('company'); + (this.company_field = wrapper.page.add_field({ + fieldtype: "Link", + fieldname: "company", + options: "Company", + label: __("Company"), + reqd: 1, + default: frappe.defaults.get_user_default("company"), + change: function () { + me.company = this.value || frappe.defaults.get_user_default("company"); me.get_data(); - } - }), - - this.elements = { - layout: $(wrapper).find(".layout-main"), - from_date: wrapper.page.add_date(__("From Date")), - to_date: wrapper.page.add_date(__("To Date")), - chart: wrapper.page.add_select(__("Chart"), [{value: 'sales_funnel', label:__("Sales Funnel")}, - {value: 'sales_pipeline', label:__("Sales Pipeline")}, - {value: 'opp_by_lead_source', label:__("Opportunities by lead source")}]), - refresh_btn: wrapper.page.set_primary_action(__("Refresh"), - function() { me.get_data(); }, "fa fa-refresh"), - }; + }, + })), + (this.elements = { + layout: $(wrapper).find(".layout-main"), + from_date: wrapper.page.add_date(__("From Date")), + to_date: wrapper.page.add_date(__("To Date")), + chart: wrapper.page.add_select(__("Chart"), [ + { value: "sales_funnel", label: __("Sales Funnel") }, + { value: "sales_pipeline", label: __("Sales Pipeline") }, + { value: "opp_by_lead_source", label: __("Opportunities by lead source") }, + ]), + refresh_btn: wrapper.page.set_primary_action( + __("Refresh"), + function () { + me.get_data(); + }, + "fa fa-refresh" + ), + }); - this.elements.no_data = $('
              ' + __("No Data") + '
              ') + this.elements.no_data = $('
              ' + __("No Data") + "
              ") .toggle(false) .appendTo(this.elements.layout); - this.elements.funnel_wrapper = $('
              ') - .appendTo(this.elements.layout); + this.elements.funnel_wrapper = $('
              ').appendTo( + this.elements.layout + ); - this.company = frappe.defaults.get_user_default('company'); + this.company = frappe.defaults.get_user_default("company"); this.options = { from_date: frappe.datetime.add_months(frappe.datetime.get_today(), -1), to_date: frappe.datetime.get_today(), - chart: 'sales_funnel' + chart: "sales_funnel", }; // set defaults and bind on change - $.each(this.options, function(k, v) { - if (['from_date', 'to_date'].includes(k)) { + $.each(this.options, function (k, v) { + if (["from_date", "to_date"].includes(k)) { me.elements[k].val(frappe.datetime.str_to_user(v)); } else { me.elements[k].val(v); } - me.elements[k].on("change", function() { - if (['from_date', 'to_date'].includes(k)) { - me.options[k] = frappe.datetime.user_to_str($(this).val()) != 'Invalid date' ? frappe.datetime.user_to_str($(this).val()) : frappe.datetime.get_today(); + me.elements[k].on("change", function () { + if (["from_date", "to_date"].includes(k)) { + me.options[k] = + frappe.datetime.user_to_str($(this).val()) != "Invalid date" + ? frappe.datetime.user_to_str($(this).val()) + : frappe.datetime.get_today(); } else { me.options.chart = $(this).val(); } @@ -78,12 +93,12 @@ erpnext.SalesFunnel = class SalesFunnel { }); // bind refresh - this.elements.refresh_btn.on("click", function() { + this.elements.refresh_btn.on("click", function () { me.get_data(this); }); // bind resize - $(window).resize(function() { + $(window).resize(function () { me.render(); }); } @@ -95,39 +110,39 @@ erpnext.SalesFunnel = class SalesFunnel { } const method_map = { - "sales_funnel": "erpnext.selling.page.sales_funnel.sales_funnel.get_funnel_data", - "opp_by_lead_source": "erpnext.selling.page.sales_funnel.sales_funnel.get_opp_by_lead_source", - "sales_pipeline": "erpnext.selling.page.sales_funnel.sales_funnel.get_pipeline_data" + sales_funnel: "erpnext.selling.page.sales_funnel.sales_funnel.get_funnel_data", + opp_by_lead_source: "erpnext.selling.page.sales_funnel.sales_funnel.get_opp_by_lead_source", + sales_pipeline: "erpnext.selling.page.sales_funnel.sales_funnel.get_pipeline_data", }; frappe.call({ method: method_map[this.options.chart], args: { from_date: this.options.from_date, to_date: this.options.to_date, - company: this.company + company: this.company, }, btn: btn, - callback: function(r) { - if(!r.exc) { + callback: function (r) { + if (!r.exc) { me.options.data = r.message; - if (me.options.data=='empty') { + if (me.options.data == "empty") { const $parent = me.elements.funnel_wrapper; - $parent.html(__('No data for this period')); + $parent.html(__("No data for this period")); } else { me.render(); } } - } + }, }); } render() { let me = this; - if (me.options.chart == 'sales_funnel'){ + if (me.options.chart == "sales_funnel") { me.render_funnel(); - } else if (me.options.chart == 'opp_by_lead_source'){ + } else if (me.options.chart == "opp_by_lead_source") { me.render_chart("Sales Opportunities by Source"); - } else if (me.options.chart == 'sales_pipeline'){ + } else if (me.options.chart == "sales_pipeline") { me.render_chart("Sales Pipeline by Stage"); } } @@ -143,12 +158,12 @@ erpnext.SalesFunnel = class SalesFunnel { y = 0, y_old = 0.0; - if(this.options.total_value === 0) { + if (this.options.total_value === 0) { this.elements.no_data.toggle(true); return; } - this.options.data.forEach(function(d) { + this.options.data.forEach(function (d) { context.fillStyle = d.color; context.strokeStyle = d.color; me.draw_triangle(x_start, x_mid, x_end, y, me.options.height); @@ -175,21 +190,22 @@ erpnext.SalesFunnel = class SalesFunnel { this.elements.no_data.toggle(false); // calculate width and height options - this.options.width = $(this.elements.funnel_wrapper).width() * 2.0 / 3.0; + this.options.width = ($(this.elements.funnel_wrapper).width() * 2.0) / 3.0; this.options.height = (Math.sqrt(3) * this.options.width) / 2.0; // calculate total weightage // as height decreases, area decreases by the square of the reduction // hence, compensating by squaring the index value - this.options.total_weightage = this.options.data.reduce( - function(prev, curr, i) { return prev + Math.pow(i+1, 2) * curr.value; }, 0.0); + this.options.total_weightage = this.options.data.reduce(function (prev, curr, i) { + return prev + Math.pow(i + 1, 2) * curr.value; + }, 0.0); // calculate height for each data - $.each(this.options.data, function(i, d) { - d.height = me.options.height * d.value * Math.pow(i+1, 2) / me.options.total_weightage; + $.each(this.options.data, function (i, d) { + d.height = (me.options.height * d.value * Math.pow(i + 1, 2)) / me.options.total_weightage; }); - this.elements.canvas = $('') + this.elements.canvas = $("") .appendTo(this.elements.funnel_wrapper.empty()) .attr("width", $(this.elements.funnel_wrapper).width()) .attr("height", this.options.height); @@ -211,7 +227,7 @@ erpnext.SalesFunnel = class SalesFunnel { draw_legend(x_mid, y_mid, width, height, title) { var context = this.elements.context; - if(y_mid == 0) { + if (y_mid == 0) { y_mid = 7; } @@ -246,13 +262,13 @@ erpnext.SalesFunnel = class SalesFunnel { title: title, height: 400, data: chart_data, - type: 'bar', + type: "bar", barOptions: { - stacked: 1 + stacked: 1, }, tooltipOptions: { - formatTooltipY: d => format_currency(d, currency), - } + formatTooltipY: (d) => format_currency(d, currency), + }, }); } }; diff --git a/erpnext/selling/report/address_and_contacts/address_and_contacts.js b/erpnext/selling/report/address_and_contacts/address_and_contacts.js index ef87586f66e8..26265480416a 100644 --- a/erpnext/selling/report/address_and_contacts/address_and_contacts.js +++ b/erpnext/selling/report/address_and_contacts/address_and_contacts.js @@ -3,32 +3,32 @@ /* eslint-disable */ frappe.query_reports["Address And Contacts"] = { - "filters": [ + filters: [ { - "reqd": 1, - "fieldname":"party_type", - "label": __("Party Type"), - "fieldtype": "Link", - "options": "DocType", - "get_query": function() { + reqd: 1, + fieldname: "party_type", + label: __("Party Type"), + fieldtype: "Link", + options: "DocType", + get_query: function () { return { - "filters": { - "name": ["in","Customer,Supplier,Sales Partner"], - } - } - } + filters: { + name: ["in", "Customer,Supplier,Sales Partner"], + }, + }; + }, }, { - "fieldname":"party_name", - "label": __("Party Name"), - "fieldtype": "Dynamic Link", - "get_options": function() { - let party_type = frappe.query_report.get_filter_value('party_type'); - if(!party_type) { + fieldname: "party_name", + label: __("Party Name"), + fieldtype: "Dynamic Link", + get_options: function () { + let party_type = frappe.query_report.get_filter_value("party_type"); + if (!party_type) { frappe.throw(__("Please select Party Type first")); } return party_type; - } - } - ] -} + }, + }, + ], +}; diff --git a/erpnext/selling/report/available_stock_for_packing_items/available_stock_for_packing_items.js b/erpnext/selling/report/available_stock_for_packing_items/available_stock_for_packing_items.js index 1e83acdeb187..a9ee0cbf0677 100644 --- a/erpnext/selling/report/available_stock_for_packing_items/available_stock_for_packing_items.js +++ b/erpnext/selling/report/available_stock_for_packing_items/available_stock_for_packing_items.js @@ -2,7 +2,5 @@ // For license information, please see license.txt frappe.query_reports["Available Stock for Packing Items"] = { - "filters": [ - - ] -} + filters: [], +}; diff --git a/erpnext/selling/report/customer_acquisition_and_loyalty/customer_acquisition_and_loyalty.js b/erpnext/selling/report/customer_acquisition_and_loyalty/customer_acquisition_and_loyalty.js index 1b931e12de3f..04891301d7bb 100644 --- a/erpnext/selling/report/customer_acquisition_and_loyalty/customer_acquisition_and_loyalty.js +++ b/erpnext/selling/report/customer_acquisition_and_loyalty/customer_acquisition_and_loyalty.js @@ -2,43 +2,43 @@ // License: GNU General Public License v3. See license.txt frappe.query_reports["Customer Acquisition and Loyalty"] = { - "filters": [ + filters: [ { - "fieldname": "view_type", - "label": __("View Type"), - "fieldtype": "Select", - "options": ["Monthly", "Territory Wise"], - "default": "Monthly", - "reqd": 1 + fieldname: "view_type", + label: __("View Type"), + fieldtype: "Select", + options: ["Monthly", "Territory Wise"], + default: "Monthly", + reqd: 1, }, { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_user_default("Company"), - "reqd": 1 + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), + reqd: 1, }, { - "fieldname":"from_date", - "label": __("From Date"), - "fieldtype": "Date", - "default": frappe.defaults.get_user_default("year_start_date"), - "reqd": 1 + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + default: frappe.defaults.get_user_default("year_start_date"), + reqd: 1, }, { - "fieldname":"to_date", - "label": __("To Date"), - "fieldtype": "Date", - "default": frappe.defaults.get_user_default("year_end_date"), - "reqd": 1 - } + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + default: frappe.defaults.get_user_default("year_end_date"), + reqd: 1, + }, ], - 'formatter': function(value, row, column, data, default_formatter) { + formatter: function (value, row, column, data, default_formatter) { value = default_formatter(value, row, column, data); if (data && data.bold) { value = value.bold(); } return value; - } -} + }, +}; diff --git a/erpnext/selling/report/customer_credit_balance/customer_credit_balance.js b/erpnext/selling/report/customer_credit_balance/customer_credit_balance.js index 3a99eb0891db..9902abedfa33 100644 --- a/erpnext/selling/report/customer_credit_balance/customer_credit_balance.js +++ b/erpnext/selling/report/customer_credit_balance/customer_credit_balance.js @@ -2,20 +2,20 @@ // For license information, please see license.txt frappe.query_reports["Customer Credit Balance"] = { - "filters": [ + filters: [ { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "reqd": 1, - "default": frappe.defaults.get_user_default("Company") + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + reqd: 1, + default: frappe.defaults.get_user_default("Company"), }, { - "fieldname":"customer", - "label": __("Customer"), - "fieldtype": "Link", - "options": "Customer" - } - ] -} + fieldname: "customer", + label: __("Customer"), + fieldtype: "Link", + options: "Customer", + }, + ], +}; diff --git a/erpnext/selling/report/customer_wise_item_price/customer_wise_item_price.js b/erpnext/selling/report/customer_wise_item_price/customer_wise_item_price.js index d333c8be65e8..6d937a8eede7 100644 --- a/erpnext/selling/report/customer_wise_item_price/customer_wise_item_price.js +++ b/erpnext/selling/report/customer_wise_item_price/customer_wise_item_price.js @@ -3,25 +3,25 @@ /* eslint-disable */ frappe.query_reports["Customer-wise Item Price"] = { - "filters": [ + filters: [ { - "label": __("Customer"), - "fieldname": "customer", - "fieldtype": "Link", - "options": "Customer", - "reqd": 1 + label: __("Customer"), + fieldname: "customer", + fieldtype: "Link", + options: "Customer", + reqd: 1, }, { - "label": __("Item"), - "fieldname": "item", - "fieldtype": "Link", - "options": "Item", - "get_query": () => { + label: __("Item"), + fieldname: "item", + fieldtype: "Link", + options: "Item", + get_query: () => { return { query: "erpnext.controllers.queries.item_query", - filters: { 'is_sales_item': 1 } - } - } - } - ] -} + filters: { is_sales_item: 1 }, + }; + }, + }, + ], +}; diff --git a/erpnext/selling/report/inactive_customers/inactive_customers.js b/erpnext/selling/report/inactive_customers/inactive_customers.js index 804d17e2b0ba..a191d564fee1 100644 --- a/erpnext/selling/report/inactive_customers/inactive_customers.js +++ b/erpnext/selling/report/inactive_customers/inactive_customers.js @@ -2,19 +2,19 @@ // For license information, please see license.txt frappe.query_reports["Inactive Customers"] = { - "filters": [ + filters: [ { - "fieldname":"days_since_last_order", - "label": __("Days Since Last Order"), - "fieldtype": "Int", - "default": 60 + fieldname: "days_since_last_order", + label: __("Days Since Last Order"), + fieldtype: "Int", + default: 60, }, { - "fieldname":"doctype", - "label": __("Doctype"), - "fieldtype": "Select", - "default": "Sales Order", - "options": "Sales Order\nSales Invoice" - } - ] -} + fieldname: "doctype", + label: __("Doctype"), + fieldtype: "Select", + default: "Sales Order", + options: "Sales Order\nSales Invoice", + }, + ], +}; diff --git a/erpnext/selling/report/item_wise_sales_history/item_wise_sales_history.js b/erpnext/selling/report/item_wise_sales_history/item_wise_sales_history.js index 073be7897915..1db05643b4b0 100644 --- a/erpnext/selling/report/item_wise_sales_history/item_wise_sales_history.js +++ b/erpnext/selling/report/item_wise_sales_history/item_wise_sales_history.js @@ -3,55 +3,55 @@ /* eslint-disable */ frappe.query_reports["Item-wise Sales History"] = { - "filters": [ + filters: [ { - fieldname:"company", + fieldname: "company", label: __("Company"), fieldtype: "Link", options: "Company", default: frappe.defaults.get_user_default("Company"), - reqd: 1 + reqd: 1, }, { - fieldname:"from_date", + fieldname: "from_date", reqd: 1, label: __("From Date"), fieldtype: "Date", default: frappe.datetime.add_months(frappe.datetime.get_today(), -1), }, { - fieldname:"to_date", + fieldname: "to_date", reqd: 1, default: frappe.datetime.get_today(), label: __("To Date"), fieldtype: "Date", }, { - fieldname:"item_group", + fieldname: "item_group", label: __("Item Group"), fieldtype: "Link", - options: "Item Group" + options: "Item Group", }, { - fieldname:"item_code", + fieldname: "item_code", label: __("Item"), fieldtype: "Link", options: "Item", get_query: () => { return { - query: "erpnext.controllers.queries.item_query" - } - } + query: "erpnext.controllers.queries.item_query", + }; + }, }, { - fieldname:"customer", + fieldname: "customer", label: __("Customer"), fieldtype: "Link", - options: "Customer" - } + options: "Customer", + }, ], - "formatter": function (value, row, column, data, default_formatter) { + formatter: function (value, row, column, data, default_formatter) { value = default_formatter(value, row, column, data); let format_fields = ["delivered_quantity", "billed_amount"]; @@ -59,5 +59,5 @@ frappe.query_reports["Item-wise Sales History"] = { value = "" + value + ""; } return value; - } + }, }; diff --git a/erpnext/selling/report/payment_terms_status_for_sales_order/payment_terms_status_for_sales_order.js b/erpnext/selling/report/payment_terms_status_for_sales_order/payment_terms_status_for_sales_order.js index 990d736baa4e..32c84b2538b0 100644 --- a/erpnext/selling/report/payment_terms_status_for_sales_order/payment_terms_status_for_sales_order.js +++ b/erpnext/selling/report/payment_terms_status_for_sales_order/payment_terms_status_for_sales_order.js @@ -5,140 +5,135 @@ function get_filters() { let filters = [ { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_user_default("Company"), - "reqd": 1 + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), + reqd: 1, }, { - "fieldname":"period_start_date", - "label": __("Start Date"), - "fieldtype": "Date", - "reqd": 1, - "default": frappe.datetime.add_months(frappe.datetime.get_today(), -1) + fieldname: "period_start_date", + label: __("Start Date"), + fieldtype: "Date", + reqd: 1, + default: frappe.datetime.add_months(frappe.datetime.get_today(), -1), }, { - "fieldname":"period_end_date", - "label": __("End Date"), - "fieldtype": "Date", - "reqd": 1, - "default": frappe.datetime.get_today() + fieldname: "period_end_date", + label: __("End Date"), + fieldtype: "Date", + reqd: 1, + default: frappe.datetime.get_today(), }, { - "fieldname":"customer_group", - "label": __("Customer Group"), - "fieldtype": "Link", - "width": 100, - "options": "Customer Group", + fieldname: "customer_group", + label: __("Customer Group"), + fieldtype: "Link", + width: 100, + options: "Customer Group", }, { - "fieldname":"customer", - "label": __("Customer"), - "fieldtype": "Link", - "width": 100, - "options": "Customer", - "get_query": () => { - var customer_group = frappe.query_report.get_filter_value('customer_group'); - return{ - "query": "erpnext.selling.report.payment_terms_status_for_sales_order.payment_terms_status_for_sales_order.get_customers_or_items", - "filters": [ - ['Customer', 'disabled', '=', '0'], - ['Customer Group','name', '=', customer_group] - ] - } - } + fieldname: "customer", + label: __("Customer"), + fieldtype: "Link", + width: 100, + options: "Customer", + get_query: () => { + var customer_group = frappe.query_report.get_filter_value("customer_group"); + return { + query: "erpnext.selling.report.payment_terms_status_for_sales_order.payment_terms_status_for_sales_order.get_customers_or_items", + filters: [ + ["Customer", "disabled", "=", "0"], + ["Customer Group", "name", "=", customer_group], + ], + }; + }, }, { - "fieldname":"item_group", - "label": __("Item Group"), - "fieldtype": "Link", - "width": 100, - "options": "Item Group", - + fieldname: "item_group", + label: __("Item Group"), + fieldtype: "Link", + width: 100, + options: "Item Group", }, { - "fieldname":"item", - "label": __("Item"), - "fieldtype": "Link", - "width": 100, - "options": "Item", - "get_query": () => { - var item_group = frappe.query_report.get_filter_value('item_group'); - return{ - "query": "erpnext.selling.report.payment_terms_status_for_sales_order.payment_terms_status_for_sales_order.get_customers_or_items", - "filters": [ - ['Item', 'disabled', '=', '0'], - ['Item Group','name', '=', item_group] - ] - } - } + fieldname: "item", + label: __("Item"), + fieldtype: "Link", + width: 100, + options: "Item", + get_query: () => { + var item_group = frappe.query_report.get_filter_value("item_group"); + return { + query: "erpnext.selling.report.payment_terms_status_for_sales_order.payment_terms_status_for_sales_order.get_customers_or_items", + filters: [ + ["Item", "disabled", "=", "0"], + ["Item Group", "name", "=", item_group], + ], + }; + }, }, { - "fieldname":"from_due_date", - "label": __("From Due Date"), - "fieldtype": "Date", + fieldname: "from_due_date", + label: __("From Due Date"), + fieldtype: "Date", }, { - "fieldname":"to_due_date", - "label": __("To Due Date"), - "fieldtype": "Date", + fieldname: "to_due_date", + label: __("To Due Date"), + fieldtype: "Date", }, { - "fieldname":"status", - "label": __("Status"), - "fieldtype": "MultiSelectList", - "width": 100, - get_data: function(txt) { - let status = ["Overdue", "Unpaid", "Completed", "Partly Paid"] - let options = [] - for (let option of status){ + fieldname: "status", + label: __("Status"), + fieldtype: "MultiSelectList", + width: 100, + get_data: function (txt) { + let status = ["Overdue", "Unpaid", "Completed", "Partly Paid"]; + let options = []; + for (let option of status) { options.push({ - "value": option, - "label": __(option), - "description": "" - }) + value: option, + label: __(option), + description: "", + }); } - return options - } + return options; + }, }, { - "fieldname":"only_immediate_upcoming_term", - "label": __("Show only the Immediate Upcoming Term"), - "fieldtype": "Check", + fieldname: "only_immediate_upcoming_term", + label: __("Show only the Immediate Upcoming Term"), + fieldtype: "Check", }, - ] + ]; return filters; } frappe.query_reports["Payment Terms Status for Sales Order"] = { - "filters": get_filters(), - "formatter": function(value, row, column, data, default_formatter){ - if(column.fieldname == 'invoices' && value) { - invoices = value.split(','); + filters: get_filters(), + formatter: function (value, row, column, data, default_formatter) { + if (column.fieldname == "invoices" && value) { + invoices = value.split(","); const invoice_formatter = (prev_value, curr_value) => { - if(prev_value != "") { + if (prev_value != "") { return prev_value + ", " + default_formatter(curr_value, row, column, data); - } - else { + } else { return default_formatter(curr_value, row, column, data); } - } - return invoices.reduce(invoice_formatter, "") - } - else if (column.fieldname == 'paid_amount' && value){ + }; + return invoices.reduce(invoice_formatter, ""); + } else if (column.fieldname == "paid_amount" && value) { formatted_value = default_formatter(value, row, column, data); - if(value > 0) { - formatted_value = "" + formatted_value + "" + if (value > 0) { + formatted_value = "" + formatted_value + ""; } return formatted_value; - } - else if (column.fieldname == 'status' && value == 'Completed'){ + } else if (column.fieldname == "status" && value == "Completed") { return "" + default_formatter(value, row, column, data) + ""; } return default_formatter(value, row, column, data); }, - }; diff --git a/erpnext/selling/report/pending_so_items_for_purchase_request/pending_so_items_for_purchase_request.js b/erpnext/selling/report/pending_so_items_for_purchase_request/pending_so_items_for_purchase_request.js index 37634efb6cdd..484fdc508b0e 100644 --- a/erpnext/selling/report/pending_so_items_for_purchase_request/pending_so_items_for_purchase_request.js +++ b/erpnext/selling/report/pending_so_items_for_purchase_request/pending_so_items_for_purchase_request.js @@ -2,5 +2,4 @@ // For license information, please see license.txt /* eslint-disable */ -frappe.query_reports["Pending SO Items For Purchase Request"] = { -} +frappe.query_reports["Pending SO Items For Purchase Request"] = {}; diff --git a/erpnext/selling/report/quotation_trends/quotation_trends.js b/erpnext/selling/report/quotation_trends/quotation_trends.js index 97a19315ec3f..8ffeda47b64e 100644 --- a/erpnext/selling/report/quotation_trends/quotation_trends.js +++ b/erpnext/selling/report/quotation_trends/quotation_trends.js @@ -1,8 +1,8 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -frappe.require("assets/erpnext/js/sales_trends_filters.js", function() { +frappe.require("assets/erpnext/js/sales_trends_filters.js", function () { frappe.query_reports["Quotation Trends"] = { - filters: erpnext.get_sales_trends_filters() - } + filters: erpnext.get_sales_trends_filters(), + }; }); diff --git a/erpnext/selling/report/sales_analytics/sales_analytics.js b/erpnext/selling/report/sales_analytics/sales_analytics.js index 87dd02f99151..9274586c3e3b 100644 --- a/erpnext/selling/report/sales_analytics/sales_analytics.js +++ b/erpnext/selling/report/sales_analytics/sales_analytics.js @@ -3,47 +3,55 @@ /* eslint-disable */ frappe.query_reports["Sales Analytics"] = { - "filters": [ + filters: [ { fieldname: "tree_type", label: __("Tree Type"), fieldtype: "Select", - options: ["Customer Group", "Customer", "Item Group", "Item", "Territory", "Order Type", "Project"], + options: [ + "Customer Group", + "Customer", + "Item Group", + "Item", + "Territory", + "Order Type", + "Project", + ], default: "Customer", - reqd: 1 + reqd: 1, }, { fieldname: "doc_type", label: __("based_on"), fieldtype: "Select", - options: ["Sales Order","Delivery Note","Sales Invoice"], + options: ["Sales Order", "Delivery Note", "Sales Invoice"], default: "Sales Invoice", - reqd: 1 + reqd: 1, }, { fieldname: "value_quantity", label: __("Value Or Qty"), fieldtype: "Select", options: [ - { "value": "Value", "label": __("Value") }, - { "value": "Quantity", "label": __("Quantity") }, + { value: "Value", label: __("Value") }, + { value: "Quantity", label: __("Quantity") }, ], default: "Value", - reqd: 1 + reqd: 1, }, { fieldname: "from_date", label: __("From Date"), fieldtype: "Date", default: frappe.defaults.get_user_default("year_start_date"), - reqd: 1 + reqd: 1, }, { - fieldname:"to_date", + fieldname: "to_date", label: __("To Date"), fieldtype: "Date", default: frappe.defaults.get_user_default("year_end_date"), - reqd: 1 + reqd: 1, }, { fieldname: "company", @@ -51,21 +59,21 @@ frappe.query_reports["Sales Analytics"] = { fieldtype: "Link", options: "Company", default: frappe.defaults.get_user_default("Company"), - reqd: 1 + reqd: 1, }, { fieldname: "range", label: __("Range"), fieldtype: "Select", options: [ - { "value": "Weekly", "label": __("Weekly") }, - { "value": "Monthly", "label": __("Monthly") }, - { "value": "Quarterly", "label": __("Quarterly") }, - { "value": "Yearly", "label": __("Yearly") } + { value: "Weekly", label: __("Weekly") }, + { value: "Monthly", label: __("Monthly") }, + { value: "Quarterly", label: __("Quarterly") }, + { value: "Yearly", label: __("Yearly") }, ], default: "Monthly", - reqd: 1 - } + reqd: 1, + }, ], get_datatable_options(options) { return Object.assign(options, { @@ -73,32 +81,26 @@ frappe.query_reports["Sales Analytics"] = { events: { onCheckRow: function (data) { if (!data) return; - const data_doctype = $( - data[2].html - )[0].attributes.getNamedItem("data-doctype").value; + const data_doctype = $(data[2].html)[0].attributes.getNamedItem("data-doctype").value; const tree_type = frappe.query_report.filters[0].value; if (data_doctype != tree_type) return; const row_name = data[2].content; const raw_data = frappe.query_report.chart.data; const new_datasets = raw_data.datasets; - const element_found = new_datasets.some( - (element, index, array) => { - if (element.name == row_name) { - array.splice(index, 1); - return true; - } - return false; + const element_found = new_datasets.some((element, index, array) => { + if (element.name == row_name) { + array.splice(index, 1); + return true; } - ); + return false; + }); const slice_at = { Customer: 4, Item: 5 }[tree_type] || 3; if (!element_found) { new_datasets.push({ name: row_name, - values: data - .slice(slice_at, data.length - 1) - .map(column => column.content), + values: data.slice(slice_at, data.length - 1).map((column) => column.content), }); } @@ -106,7 +108,9 @@ frappe.query_reports["Sales Analytics"] = { labels: raw_data.labels, datasets: new_datasets, }; - const new_options = Object.assign({}, frappe.query_report.chart_options, {data: new_data}); + const new_options = Object.assign({}, frappe.query_report.chart_options, { + data: new_data, + }); frappe.query_report.render_chart(new_options); frappe.query_report.raw_chart_data = new_data; diff --git a/erpnext/selling/report/sales_order_analysis/sales_order_analysis.js b/erpnext/selling/report/sales_order_analysis/sales_order_analysis.js index 91748bc7be2a..25089c4b8705 100644 --- a/erpnext/selling/report/sales_order_analysis/sales_order_analysis.js +++ b/erpnext/selling/report/sales_order_analysis/sales_order_analysis.js @@ -3,74 +3,74 @@ /* eslint-disable */ frappe.query_reports["Sales Order Analysis"] = { - "filters": [ + filters: [ { - "fieldname": "company", - "label": __("Company"), - "fieldtype": "Link", - "width": "80", - "options": "Company", - "reqd": 1, - "default": frappe.defaults.get_default("company") + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + width: "80", + options: "Company", + reqd: 1, + default: frappe.defaults.get_default("company"), }, { - "fieldname":"from_date", - "label": __("From Date"), - "fieldtype": "Date", - "width": "80", - "reqd": 1, - "default": frappe.datetime.add_months(frappe.datetime.get_today(), -1), + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + width: "80", + reqd: 1, + default: frappe.datetime.add_months(frappe.datetime.get_today(), -1), }, { - "fieldname":"to_date", - "label": __("To Date"), - "fieldtype": "Date", - "width": "80", - "reqd": 1, - "default": frappe.datetime.get_today() + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + width: "80", + reqd: 1, + default: frappe.datetime.get_today(), }, { - "fieldname": "sales_order", - "label": __("Sales Order"), - "fieldtype": "MultiSelectList", - "width": "80", - "options": "Sales Order", - "get_data": function(txt) { + fieldname: "sales_order", + label: __("Sales Order"), + fieldtype: "MultiSelectList", + width: "80", + options: "Sales Order", + get_data: function (txt) { return frappe.db.get_link_options("Sales Order", txt); }, - "get_query": () =>{ + get_query: () => { return { - filters: { "docstatus": 1 } - } - } + filters: { docstatus: 1 }, + }; + }, }, { - "fieldname": "status", - "label": __("Status"), - "fieldtype": "MultiSelectList", - "width": "80", - get_data: function(txt) { - let status = ["To Bill", "To Deliver", "To Deliver and Bill", "Completed"] - let options = [] - for (let option of status){ + fieldname: "status", + label: __("Status"), + fieldtype: "MultiSelectList", + width: "80", + get_data: function (txt) { + let status = ["To Bill", "To Deliver", "To Deliver and Bill", "Completed"]; + let options = []; + for (let option of status) { options.push({ - "value": option, - "label": __(option), - "description": "" - }) + value: option, + label: __(option), + description: "", + }); } - return options - } + return options; + }, }, { - "fieldname": "group_by_so", - "label": __("Group by Sales Order"), - "fieldtype": "Check", - "default": 0 - } + fieldname: "group_by_so", + label: __("Group by Sales Order"), + fieldtype: "Check", + default: 0, + }, ], - "formatter": function (value, row, column, data, default_formatter) { + formatter: function (value, row, column, data, default_formatter) { value = default_formatter(value, row, column, data); let format_fields = ["delivered_qty", "billed_amount"]; @@ -82,5 +82,5 @@ frappe.query_reports["Sales Order Analysis"] = { value = "" + value + ""; } return value; - } + }, }; diff --git a/erpnext/selling/report/sales_order_trends/sales_order_trends.js b/erpnext/selling/report/sales_order_trends/sales_order_trends.js index b22ea8fa2caa..fe38804ed45d 100644 --- a/erpnext/selling/report/sales_order_trends/sales_order_trends.js +++ b/erpnext/selling/report/sales_order_trends/sales_order_trends.js @@ -1,8 +1,8 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -frappe.require("assets/erpnext/js/sales_trends_filters.js", function() { +frappe.require("assets/erpnext/js/sales_trends_filters.js", function () { frappe.query_reports["Sales Order Trends"] = { - filters: erpnext.get_sales_trends_filters() - } + filters: erpnext.get_sales_trends_filters(), + }; }); diff --git a/erpnext/selling/report/sales_partner_commission_summary/sales_partner_commission_summary.js b/erpnext/selling/report/sales_partner_commission_summary/sales_partner_commission_summary.js index 63d930c1452d..2a67fa35ddf7 100644 --- a/erpnext/selling/report/sales_partner_commission_summary/sales_partner_commission_summary.js +++ b/erpnext/selling/report/sales_partner_commission_summary/sales_partner_commission_summary.js @@ -3,20 +3,19 @@ /* eslint-disable */ frappe.query_reports["Sales Partner Commission Summary"] = { - "filters": [ - + filters: [ { fieldname: "sales_partner", label: __("Sales Partner"), fieldtype: "Link", - options: "Sales Partner" + options: "Sales Partner", }, { fieldname: "doctype", label: __("Document Type"), fieldtype: "Select", options: "Sales Order\nDelivery Note\nSales Invoice", - default: "Sales Order" + default: "Sales Order", }, { fieldname: "from_date", @@ -25,30 +24,29 @@ frappe.query_reports["Sales Partner Commission Summary"] = { default: frappe.datetime.add_months(frappe.datetime.get_today(), -1), }, { - fieldname:"to_date", + fieldname: "to_date", label: __("To Date"), fieldtype: "Date", - default: frappe.datetime.get_today() + default: frappe.datetime.get_today(), }, { - fieldname:"company", + fieldname: "company", label: __("Company"), fieldtype: "Link", options: "Company", - default: frappe.defaults.get_user_default("Company") + default: frappe.defaults.get_user_default("Company"), }, { - fieldname:"customer", + fieldname: "customer", label: __("Customer"), fieldtype: "Link", options: "Customer", }, { - fieldname:"territory", + fieldname: "territory", label: __("Territory"), fieldtype: "Link", options: "Territory", }, - - ] -} + ], +}; diff --git a/erpnext/selling/report/sales_partner_target_variance_based_on_item_group/sales_partner_target_variance_based_on_item_group.js b/erpnext/selling/report/sales_partner_target_variance_based_on_item_group/sales_partner_target_variance_based_on_item_group.js index adae47b87daf..f8c950763e1f 100644 --- a/erpnext/selling/report/sales_partner_target_variance_based_on_item_group/sales_partner_target_variance_based_on_item_group.js +++ b/erpnext/selling/report/sales_partner_target_variance_based_on_item_group/sales_partner_target_variance_based_on_item_group.js @@ -3,61 +3,59 @@ /* eslint-disable */ frappe.query_reports["Sales Partner Target Variance based on Item Group"] = { - "filters": [ + filters: [ { - fieldname:"company", + fieldname: "company", label: __("Company"), fieldtype: "Link", options: "Company", - default: frappe.defaults.get_user_default("Company") + default: frappe.defaults.get_user_default("Company"), }, { fieldname: "fiscal_year", label: __("Fiscal Year"), fieldtype: "Link", options: "Fiscal Year", - default: frappe.sys_defaults.fiscal_year + default: frappe.sys_defaults.fiscal_year, }, { fieldname: "doctype", label: __("Document Type"), fieldtype: "Select", options: "Sales Order\nDelivery Note\nSales Invoice", - default: "Sales Order" + default: "Sales Order", }, { fieldname: "period", label: __("Period"), fieldtype: "Select", options: [ - { "value": "Monthly", "label": __("Monthly") }, - { "value": "Quarterly", "label": __("Quarterly") }, - { "value": "Half-Yearly", "label": __("Half-Yearly") }, - { "value": "Yearly", "label": __("Yearly") } + { value: "Monthly", label: __("Monthly") }, + { value: "Quarterly", label: __("Quarterly") }, + { value: "Half-Yearly", label: __("Half-Yearly") }, + { value: "Yearly", label: __("Yearly") }, ], - default: "Monthly" + default: "Monthly", }, { fieldname: "target_on", label: __("Target On"), fieldtype: "Select", options: "Quantity\nAmount", - default: "Quantity" + default: "Quantity", }, ], - "formatter": function (value, row, column, data, default_formatter) { + formatter: function (value, row, column, data, default_formatter) { value = default_formatter(value, row, column, data); - if (column.fieldname.includes('variance')) { - + if (column.fieldname.includes("variance")) { if (data[column.fieldname] < 0) { value = "" + value + ""; - } - else if (data[column.fieldname] > 0) { + } else if (data[column.fieldname] > 0) { value = "" + value + ""; } } return value; - } -} + }, +}; diff --git a/erpnext/selling/report/sales_partner_transaction_summary/sales_partner_transaction_summary.js b/erpnext/selling/report/sales_partner_transaction_summary/sales_partner_transaction_summary.js index e404233953e1..6bd8077ddd6c 100644 --- a/erpnext/selling/report/sales_partner_transaction_summary/sales_partner_transaction_summary.js +++ b/erpnext/selling/report/sales_partner_transaction_summary/sales_partner_transaction_summary.js @@ -3,19 +3,19 @@ /* eslint-disable */ frappe.query_reports["Sales Partner Transaction Summary"] = { - "filters": [ + filters: [ { fieldname: "sales_partner", label: __("Sales Partner"), fieldtype: "Link", - options: "Sales Partner" + options: "Sales Partner", }, { fieldname: "doctype", label: __("Document Type"), fieldtype: "Select", options: "Sales Order\nDelivery Note\nSales Invoice", - default: "Sales Order" + default: "Sales Order", }, { fieldname: "from_date", @@ -24,48 +24,48 @@ frappe.query_reports["Sales Partner Transaction Summary"] = { default: frappe.datetime.add_months(frappe.datetime.get_today(), -1), }, { - fieldname:"to_date", + fieldname: "to_date", label: __("To Date"), fieldtype: "Date", - default: frappe.datetime.get_today() + default: frappe.datetime.get_today(), }, { - fieldname:"company", + fieldname: "company", label: __("Company"), fieldtype: "Link", options: "Company", default: frappe.defaults.get_user_default("Company"), - reqd: 1 + reqd: 1, }, { - fieldname:"item_group", + fieldname: "item_group", label: __("Item Group"), fieldtype: "Link", options: "Item Group", }, { - fieldname:"brand", + fieldname: "brand", label: __("Brand"), fieldtype: "Link", options: "Brand", }, { - fieldname:"customer", + fieldname: "customer", label: __("Customer"), fieldtype: "Link", options: "Customer", }, { - fieldname:"territory", + fieldname: "territory", label: __("Territory"), fieldtype: "Link", options: "Territory", }, { - fieldname:"show_return_entries", + fieldname: "show_return_entries", label: __("Show Return Entries"), fieldtype: "Check", default: 0, }, - ] -} + ], +}; diff --git a/erpnext/selling/report/sales_person_commission_summary/sales_person_commission_summary.js b/erpnext/selling/report/sales_person_commission_summary/sales_person_commission_summary.js index ba6ee784b91c..ebbf9cf2dd27 100644 --- a/erpnext/selling/report/sales_person_commission_summary/sales_person_commission_summary.js +++ b/erpnext/selling/report/sales_person_commission_summary/sales_person_commission_summary.js @@ -3,20 +3,19 @@ /* eslint-disable */ frappe.query_reports["Sales Person Commission Summary"] = { - "filters": [ - + filters: [ { fieldname: "sales_person", label: __("Sales Person"), fieldtype: "Link", - options: "Sales Person" + options: "Sales Person", }, { fieldname: "doc_type", label: __("Document Type"), fieldtype: "Select", options: "Sales Order\nDelivery Note\nSales Invoice", - default: "Sales Order" + default: "Sales Order", }, { fieldname: "from_date", @@ -25,30 +24,29 @@ frappe.query_reports["Sales Person Commission Summary"] = { default: frappe.defaults.get_user_default("year_start_date"), }, { - fieldname:"to_date", + fieldname: "to_date", label: __("To Date"), fieldtype: "Date", - default: frappe.datetime.get_today() + default: frappe.datetime.get_today(), }, { - fieldname:"company", + fieldname: "company", label: __("Company"), fieldtype: "Link", options: "Company", - default: frappe.defaults.get_user_default("Company") + default: frappe.defaults.get_user_default("Company"), }, { - fieldname:"customer", + fieldname: "customer", label: __("Customer"), fieldtype: "Link", options: "Customer", }, { - fieldname:"territory", + fieldname: "territory", label: __("Territory"), fieldtype: "Link", options: "Territory", }, - - ] -} + ], +}; diff --git a/erpnext/selling/report/sales_person_target_variance_based_on_item_group/sales_person_target_variance_based_on_item_group.js b/erpnext/selling/report/sales_person_target_variance_based_on_item_group/sales_person_target_variance_based_on_item_group.js index 2b8443627d5a..b3497085fb74 100644 --- a/erpnext/selling/report/sales_person_target_variance_based_on_item_group/sales_person_target_variance_based_on_item_group.js +++ b/erpnext/selling/report/sales_person_target_variance_based_on_item_group/sales_person_target_variance_based_on_item_group.js @@ -3,61 +3,59 @@ /* eslint-disable */ frappe.query_reports["Sales Person Target Variance Based On Item Group"] = { - "filters": [ + filters: [ { - fieldname:"company", + fieldname: "company", label: __("Company"), fieldtype: "Link", options: "Company", - default: frappe.defaults.get_user_default("Company") + default: frappe.defaults.get_user_default("Company"), }, { fieldname: "fiscal_year", label: __("Fiscal Year"), fieldtype: "Link", options: "Fiscal Year", - default: frappe.sys_defaults.fiscal_year + default: frappe.sys_defaults.fiscal_year, }, { fieldname: "doctype", label: __("Document Type"), fieldtype: "Select", options: "Sales Order\nDelivery Note\nSales Invoice", - default: "Sales Order" + default: "Sales Order", }, { fieldname: "period", label: __("Period"), fieldtype: "Select", options: [ - { "value": "Monthly", "label": __("Monthly") }, - { "value": "Quarterly", "label": __("Quarterly") }, - { "value": "Half-Yearly", "label": __("Half-Yearly") }, - { "value": "Yearly", "label": __("Yearly") } + { value: "Monthly", label: __("Monthly") }, + { value: "Quarterly", label: __("Quarterly") }, + { value: "Half-Yearly", label: __("Half-Yearly") }, + { value: "Yearly", label: __("Yearly") }, ], - default: "Monthly" + default: "Monthly", }, { fieldname: "target_on", label: __("Target On"), fieldtype: "Select", options: "Quantity\nAmount", - default: "Quantity" + default: "Quantity", }, ], - "formatter": function (value, row, column, data, default_formatter) { + formatter: function (value, row, column, data, default_formatter) { value = default_formatter(value, row, column, data); - if (column.fieldname.includes('variance')) { - + if (column.fieldname.includes("variance")) { if (data[column.fieldname] < 0) { value = "" + value + ""; - } - else if (data[column.fieldname] > 0) { + } else if (data[column.fieldname] > 0) { value = "" + value + ""; } } return value; - } -} + }, +}; diff --git a/erpnext/selling/report/sales_person_wise_transaction_summary/sales_person_wise_transaction_summary.js b/erpnext/selling/report/sales_person_wise_transaction_summary/sales_person_wise_transaction_summary.js index e269f02d0ce6..a02d07111280 100644 --- a/erpnext/selling/report/sales_person_wise_transaction_summary/sales_person_wise_transaction_summary.js +++ b/erpnext/selling/report/sales_person_wise_transaction_summary/sales_person_wise_transaction_summary.js @@ -2,19 +2,19 @@ // License: GNU General Public License v3. See license.txt frappe.query_reports["Sales Person-wise Transaction Summary"] = { - "filters": [ + filters: [ { fieldname: "sales_person", label: __("Sales Person"), fieldtype: "Link", - options: "Sales Person" + options: "Sales Person", }, { fieldname: "doc_type", label: __("Document Type"), fieldtype: "Select", options: "Sales Order\nDelivery Note\nSales Invoice", - default: "Sales Order" + default: "Sales Order", }, { fieldname: "from_date", @@ -23,48 +23,48 @@ frappe.query_reports["Sales Person-wise Transaction Summary"] = { default: frappe.defaults.get_user_default("year_start_date"), }, { - fieldname:"to_date", + fieldname: "to_date", label: __("To Date"), fieldtype: "Date", - default: frappe.datetime.get_today() + default: frappe.datetime.get_today(), }, { - fieldname:"company", + fieldname: "company", label: __("Company"), fieldtype: "Link", options: "Company", default: frappe.defaults.get_user_default("Company"), - reqd: 1 + reqd: 1, }, { - fieldname:"item_group", + fieldname: "item_group", label: __("Item Group"), fieldtype: "Link", options: "Item Group", }, { - fieldname:"brand", + fieldname: "brand", label: __("Brand"), fieldtype: "Link", options: "Brand", }, { - fieldname:"customer", + fieldname: "customer", label: __("Customer"), fieldtype: "Link", options: "Customer", }, { - fieldname:"territory", + fieldname: "territory", label: __("Territory"), fieldtype: "Link", options: "Territory", }, { - fieldname:"show_return_entries", + fieldname: "show_return_entries", label: __("Show Return Entries"), fieldtype: "Check", default: 0, }, - ] -} + ], +}; diff --git a/erpnext/selling/report/territory_target_variance_based_on_item_group/territory_target_variance_based_on_item_group.js b/erpnext/selling/report/territory_target_variance_based_on_item_group/territory_target_variance_based_on_item_group.js index 9f3d255e6626..988fb86ff6cf 100644 --- a/erpnext/selling/report/territory_target_variance_based_on_item_group/territory_target_variance_based_on_item_group.js +++ b/erpnext/selling/report/territory_target_variance_based_on_item_group/territory_target_variance_based_on_item_group.js @@ -3,61 +3,59 @@ /* eslint-disable */ frappe.query_reports["Territory Target Variance Based On Item Group"] = { - "filters": [ + filters: [ { - fieldname:"company", + fieldname: "company", label: __("Company"), fieldtype: "Link", options: "Company", - default: frappe.defaults.get_user_default("Company") + default: frappe.defaults.get_user_default("Company"), }, { fieldname: "fiscal_year", label: __("Fiscal Year"), fieldtype: "Link", options: "Fiscal Year", - default: frappe.sys_defaults.fiscal_year + default: frappe.sys_defaults.fiscal_year, }, { fieldname: "doctype", label: __("Document Type"), fieldtype: "Select", options: "Sales Order\nDelivery Note\nSales Invoice", - default: "Sales Order" + default: "Sales Order", }, { fieldname: "period", label: __("Period"), fieldtype: "Select", options: [ - { "value": "Monthly", "label": __("Monthly") }, - { "value": "Quarterly", "label": __("Quarterly") }, - { "value": "Half-Yearly", "label": __("Half-Yearly") }, - { "value": "Yearly", "label": __("Yearly") } + { value: "Monthly", label: __("Monthly") }, + { value: "Quarterly", label: __("Quarterly") }, + { value: "Half-Yearly", label: __("Half-Yearly") }, + { value: "Yearly", label: __("Yearly") }, ], - default: "Monthly" + default: "Monthly", }, { fieldname: "target_on", label: __("Target On"), fieldtype: "Select", options: "Quantity\nAmount", - default: "Quantity" + default: "Quantity", }, ], - "formatter": function (value, row, column, data, default_formatter) { + formatter: function (value, row, column, data, default_formatter) { value = default_formatter(value, row, column, data); - if (column.fieldname.includes('variance')) { - + if (column.fieldname.includes("variance")) { if (data[column.fieldname] < 0) { value = "" + value + ""; - } - else if (data[column.fieldname] > 0) { + } else if (data[column.fieldname] > 0) { value = "" + value + ""; } } return value; - } -} + }, +}; diff --git a/erpnext/selling/report/territory_wise_sales/territory_wise_sales.js b/erpnext/selling/report/territory_wise_sales/territory_wise_sales.js index bef800f1040b..c13c74084283 100644 --- a/erpnext/selling/report/territory_wise_sales/territory_wise_sales.js +++ b/erpnext/selling/report/territory_wise_sales/territory_wise_sales.js @@ -2,21 +2,23 @@ // For license information, please see license.txt /* eslint-disable */ - frappe.query_reports["Territory-wise Sales"] = { - "breadcrumb":"Selling", - "filters": [ + breadcrumb: "Selling", + filters: [ { - fieldname:"transaction_date", + fieldname: "transaction_date", label: __("Transaction Date"), fieldtype: "DateRange", - default: [frappe.datetime.add_months(frappe.datetime.get_today(),-1), frappe.datetime.get_today()], + default: [ + frappe.datetime.add_months(frappe.datetime.get_today(), -1), + frappe.datetime.get_today(), + ], }, { fieldname: "company", label: __("Company"), fieldtype: "Link", options: "Company", - } - ] + }, + ], }; diff --git a/erpnext/setup/doctype/authorization_rule/authorization_rule.js b/erpnext/setup/doctype/authorization_rule/authorization_rule.js index 3f6afcae7f51..a98d6965d8f8 100644 --- a/erpnext/setup/doctype/authorization_rule/authorization_rule.js +++ b/erpnext/setup/doctype/authorization_rule/authorization_rule.js @@ -2,14 +2,14 @@ // License: GNU General Public License v3. See license.txt frappe.ui.form.on("Authorization Rule", { - refresh: function(frm) { + refresh: function (frm) { frm.events.set_master_type(frm); }, - set_master_type: function(frm) { - if(frm.doc.based_on==="Customerwise Discount") { + set_master_type: function (frm) { + if (frm.doc.based_on === "Customerwise Discount") { unhide_field("master_name"); frm.set_value("customer_or_item", "Customer"); - } else if(frm.doc.based_on==="Itemwise Discount") { + } else if (frm.doc.based_on === "Itemwise Discount") { unhide_field("master_name"); frm.set_value("customer_or_item", "Item"); } else { @@ -18,77 +18,67 @@ frappe.ui.form.on("Authorization Rule", { hide_field("master_name"); } }, - based_on: function(frm) { + based_on: function (frm) { frm.events.set_master_type(frm); - if (frm.doc.based_on === 'Not Applicable') { + if (frm.doc.based_on === "Not Applicable") { frm.set_value("value", 0); - hide_field('value'); + hide_field("value"); } else { - unhide_field('value'); + unhide_field("value"); } }, - transaction: function(frm) { - unhide_field(['system_role', 'system_user', 'value', 'based_on']); - hide_field(['to_emp', 'to_designation']); - } -}) - + transaction: function (frm) { + unhide_field(["system_role", "system_user", "value", "based_on"]); + hide_field(["to_emp", "to_designation"]); + }, +}); // Settings Module -cur_frm.cscript.refresh = function(doc, cdt, cdn) { - if (doc.based_on == 'Not Applicable') - hide_field('value'); - else - unhide_field('value'); +cur_frm.cscript.refresh = function (doc, cdt, cdn) { + if (doc.based_on == "Not Applicable") hide_field("value"); + else unhide_field("value"); - unhide_field(['system_role', 'system_user', 'value']); - hide_field(['to_emp', 'to_designation']); -} + unhide_field(["system_role", "system_user", "value"]); + hide_field(["to_emp", "to_designation"]); +}; -cur_frm.fields_dict.system_user.get_query = function(doc, cdt, cdn) { - return { query:"frappe.core.doctype.user.user.user_query" } -} +cur_frm.fields_dict.system_user.get_query = function (doc, cdt, cdn) { + return { query: "frappe.core.doctype.user.user.user_query" }; +}; -cur_frm.fields_dict.approving_user.get_query = function(doc, cdt, cdn) { - return { query:"frappe.core.doctype.user.user.user_query" } -} +cur_frm.fields_dict.approving_user.get_query = function (doc, cdt, cdn) { + return { query: "frappe.core.doctype.user.user.user_query" }; +}; -cur_frm.fields_dict['approving_role'].get_query = cur_frm.fields_dict['system_role'].get_query; +cur_frm.fields_dict["approving_role"].get_query = cur_frm.fields_dict["system_role"].get_query; // System Role Trigger // ----------------------- -cur_frm.fields_dict['system_role'].get_query = function(doc) { +cur_frm.fields_dict["system_role"].get_query = function (doc) { return { - filters:[ - ['Role', 'name', 'not in', 'Administrator, Guest, All'] - ] - } -} - + filters: [["Role", "name", "not in", "Administrator, Guest, All"]], + }; +}; // Master Name Trigger // -------------------- -cur_frm.fields_dict['master_name'].get_query = function(doc) { - if (doc.based_on == 'Customerwise Discount') +cur_frm.fields_dict["master_name"].get_query = function (doc) { + if (doc.based_on == "Customerwise Discount") return { doctype: "Customer", - filters:[ - ['Customer', 'docstatus', '!=', 2] - ] - } - else if (doc.based_on == 'Itemwise Discount') + filters: [["Customer", "docstatus", "!=", 2]], + }; + else if (doc.based_on == "Itemwise Discount") return { doctype: "Item", - query: "erpnext.controllers.queries.item_query" - } + query: "erpnext.controllers.queries.item_query", + }; else return { - filters: [ - ['Item', 'name', '=', 'cheating done to avoid null'] - ] - } -} + filters: [["Item", "name", "=", "cheating done to avoid null"]], + }; +}; -cur_frm.fields_dict.to_emp.get_query = function(doc, cdt, cdn) { - return { query: "erpnext.controllers.queries.employee_query" } -} +cur_frm.fields_dict.to_emp.get_query = function (doc, cdt, cdn) { + return { query: "erpnext.controllers.queries.employee_query" }; +}; diff --git a/erpnext/setup/doctype/branch/branch.js b/erpnext/setup/doctype/branch/branch.js index c8a0afced8d7..6e17c7819313 100644 --- a/erpnext/setup/doctype/branch/branch.js +++ b/erpnext/setup/doctype/branch/branch.js @@ -1,8 +1,6 @@ // Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Branch', { - refresh: function(frm) { - - } +frappe.ui.form.on("Branch", { + refresh: function (frm) {}, }); diff --git a/erpnext/setup/doctype/brand/brand.js b/erpnext/setup/doctype/brand/brand.js index 0abb71a3629b..5d16d734e0fe 100644 --- a/erpnext/setup/doctype/brand/brand.js +++ b/erpnext/setup/doctype/brand/brand.js @@ -1,71 +1,99 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -frappe.ui.form.on('Brand', { +frappe.ui.form.on("Brand", { setup: (frm) => { - frm.fields_dict["brand_defaults"].grid.get_field("default_warehouse").get_query = function(doc, cdt, cdn) { + frm.fields_dict["brand_defaults"].grid.get_field("default_warehouse").get_query = function ( + doc, + cdt, + cdn + ) { const row = locals[cdt][cdn]; return { - filters: { company: row.company } - } - } + filters: { company: row.company }, + }; + }; - frm.fields_dict["brand_defaults"].grid.get_field("default_discount_account").get_query = function(doc, cdt, cdn) { + frm.fields_dict["brand_defaults"].grid.get_field("default_discount_account").get_query = function ( + doc, + cdt, + cdn + ) { const row = locals[cdt][cdn]; return { filters: { - 'report_type': 'Profit and Loss', - 'company': row.company, - "is_group": 0 - } + report_type: "Profit and Loss", + company: row.company, + is_group: 0, + }, }; - } + }; - frm.fields_dict["brand_defaults"].grid.get_field("buying_cost_center").get_query = function(doc, cdt, cdn) { + frm.fields_dict["brand_defaults"].grid.get_field("buying_cost_center").get_query = function ( + doc, + cdt, + cdn + ) { const row = locals[cdt][cdn]; return { filters: { - "is_group": 0, - "company": row.company - } - } - } + is_group: 0, + company: row.company, + }, + }; + }; - frm.fields_dict["brand_defaults"].grid.get_field("expense_account").get_query = function(doc, cdt, cdn) { + frm.fields_dict["brand_defaults"].grid.get_field("expense_account").get_query = function ( + doc, + cdt, + cdn + ) { const row = locals[cdt][cdn]; return { query: "erpnext.controllers.queries.get_expense_account", - filters: { company: row.company } - } - } + filters: { company: row.company }, + }; + }; - frm.fields_dict["brand_defaults"].grid.get_field("default_provisional_account").get_query = function(doc, cdt, cdn) { + frm.fields_dict["brand_defaults"].grid.get_field("default_provisional_account").get_query = function ( + doc, + cdt, + cdn + ) { const row = locals[cdt][cdn]; return { filters: { - "company": row.company, - "root_type": ["in", ["Liability", "Asset"]], - "is_group": 0 - } + company: row.company, + root_type: ["in", ["Liability", "Asset"]], + is_group: 0, + }, }; - } + }; - frm.fields_dict["brand_defaults"].grid.get_field("selling_cost_center").get_query = function(doc, cdt, cdn) { + frm.fields_dict["brand_defaults"].grid.get_field("selling_cost_center").get_query = function ( + doc, + cdt, + cdn + ) { const row = locals[cdt][cdn]; return { filters: { - "is_group": 0, - "company": row.company - } - } - } + is_group: 0, + company: row.company, + }, + }; + }; - frm.fields_dict["brand_defaults"].grid.get_field("income_account").get_query = function(doc, cdt, cdn) { + frm.fields_dict["brand_defaults"].grid.get_field("income_account").get_query = function ( + doc, + cdt, + cdn + ) { const row = locals[cdt][cdn]; return { query: "erpnext.controllers.queries.get_income_account", - filters: { company: row.company } - } - } - } -}); \ No newline at end of file + filters: { company: row.company }, + }; + }; + }, +}); diff --git a/erpnext/setup/doctype/company/company.js b/erpnext/setup/doctype/company/company.js index 589b3fe8b98e..23a55487adce 100644 --- a/erpnext/setup/doctype/company/company.js +++ b/erpnext/setup/doctype/company/company.js @@ -4,121 +4,148 @@ frappe.provide("erpnext.company"); frappe.ui.form.on("Company", { - onload: function(frm) { + onload: function (frm) { if (frm.doc.__islocal && frm.doc.parent_company) { - frappe.db.get_value('Company', frm.doc.parent_company, 'is_group', (r) => { + frappe.db.get_value("Company", frm.doc.parent_company, "is_group", (r) => { if (!r.is_group) { - frm.set_value('parent_company', ''); + frm.set_value("parent_company", ""); } }); } - frm.call('check_if_transactions_exist').then(r => { - frm.toggle_enable("default_currency", (!r.message)); + frm.call("check_if_transactions_exist").then((r) => { + frm.toggle_enable("default_currency", !r.message); }); }, - setup: function(frm) { + setup: function (frm) { frm.__rename_queue = "long"; erpnext.company.setup_queries(frm); - frm.set_query("parent_company", function() { + frm.set_query("parent_company", function () { return { - filters: {"is_group": 1} - } + filters: { is_group: 1 }, + }; }); - frm.set_query("default_selling_terms", function() { + frm.set_query("default_selling_terms", function () { return { filters: { selling: 1 } }; }); - frm.set_query("default_buying_terms", function() { + frm.set_query("default_buying_terms", function () { return { filters: { buying: 1 } }; }); - frm.set_query("default_in_transit_warehouse", function() { + frm.set_query("default_in_transit_warehouse", function () { return { - filters:{ - 'warehouse_type' : 'Transit', - 'is_group': 0, - 'company': frm.doc.company_name - } + filters: { + warehouse_type: "Transit", + is_group: 0, + company: frm.doc.company_name, + }, }; }); }, - company_name: function(frm) { - if(frm.doc.__islocal) { + company_name: function (frm) { + if (frm.doc.__islocal) { // add missing " " arg in split method let parts = frm.doc.company_name.split(" "); let abbr = $.map(parts, function (p) { - return p? p.substr(0, 1) : null; + return p ? p.substr(0, 1) : null; }).join(""); frm.set_value("abbr", abbr); } }, - parent_company: function(frm) { + parent_company: function (frm) { var bool = frm.doc.parent_company ? true : false; - frm.set_value('create_chart_of_accounts_based_on', bool ? "Existing Company" : ""); - frm.set_value('existing_company', bool ? frm.doc.parent_company : ""); + frm.set_value("create_chart_of_accounts_based_on", bool ? "Existing Company" : ""); + frm.set_value("existing_company", bool ? frm.doc.parent_company : ""); disbale_coa_fields(frm, bool); }, - date_of_commencement: function(frm) { - if(frm.doc.date_of_commencement { + .then((r) => { frappe.model.set_value(cdt, cdn, "address", r.name); }) - .catch(err => { + .catch((err) => { console.log(err); }); - } + }, }); diff --git a/erpnext/setup/doctype/email_digest/email_digest.js b/erpnext/setup/doctype/email_digest/email_digest.js index c2c2710b0255..c0a887e4b116 100644 --- a/erpnext/setup/doctype/email_digest/email_digest.js +++ b/erpnext/setup/doctype/email_digest/email_digest.js @@ -2,30 +2,30 @@ // License: GNU General Public License v3. See license.txt frappe.ui.form.on("Email Digest", { - refresh: function(frm) { + refresh: function (frm) { if (!frm.is_new()) { - frm.add_custom_button(__('View Now'), function() { + frm.add_custom_button(__("View Now"), function () { frappe.call({ - method: 'erpnext.setup.doctype.email_digest.email_digest.get_digest_msg', + method: "erpnext.setup.doctype.email_digest.email_digest.get_digest_msg", args: { - name: frm.doc.name + name: frm.doc.name, }, - callback: function(r) { + callback: function (r) { let d = new frappe.ui.Dialog({ - title: __('Email Digest: {0}', [frm.doc.name]), - width: 800 + title: __("Email Digest: {0}", [frm.doc.name]), + width: 800, }); $(d.body).html(r.message); d.show(); - } + }, }); }); - frm.add_custom_button(__('Send Now'), function() { - return frm.call('send', null, () => { - frappe.show_alert({ message: __("Message Sent"), indicator: 'green'}); + frm.add_custom_button(__("Send Now"), function () { + return frm.call("send", null, () => { + frappe.show_alert({ message: __("Message Sent"), indicator: "green" }); }); }); } - } + }, }); diff --git a/erpnext/setup/doctype/employee/employee.js b/erpnext/setup/doctype/employee/employee.js index efc3fd1d33d8..d165d429f449 100755 --- a/erpnext/setup/doctype/employee/employee.js +++ b/erpnext/setup/doctype/employee/employee.js @@ -4,14 +4,15 @@ frappe.provide("erpnext.setup"); erpnext.setup.EmployeeController = class EmployeeController extends frappe.ui.form.Controller { setup() { - this.frm.fields_dict.user_id.get_query = function(doc, cdt, cdn) { + this.frm.fields_dict.user_id.get_query = function (doc, cdt, cdn) { return { query: "frappe.core.doctype.user.user.user_query", - filters: {ignore_user_type: 1} - } - } - this.frm.fields_dict.reports_to.get_query = function(doc, cdt, cdn) { - return { query: "erpnext.controllers.queries.employee_query"} } + filters: { ignore_user_type: 1 }, + }; + }; + this.frm.fields_dict.reports_to.get_query = function (doc, cdt, cdn) { + return { query: "erpnext.controllers.queries.employee_query" }; + }; } refresh() { @@ -20,58 +21,59 @@ erpnext.setup.EmployeeController = class EmployeeController extends frappe.ui.fo salutation() { if (this.frm.doc.salutation) { - this.frm.set_value("gender", { - "Mr": "Male", - "Ms": "Female" - }[this.frm.doc.salutation]); + this.frm.set_value( + "gender", + { + Mr: "Male", + Ms: "Female", + }[this.frm.doc.salutation] + ); } } - }; frappe.ui.form.on("Employee", { onload: function (frm) { - frm.set_query("department", function() { + frm.set_query("department", function () { return { - "filters": { - "company": frm.doc.company, - } + filters: { + company: frm.doc.company, + }, }; }); }, - prefered_contact_email: function(frm) { + prefered_contact_email: function (frm) { frm.events.update_contact(frm); }, - personal_email: function(frm) { + personal_email: function (frm) { frm.events.update_contact(frm); }, - company_email: function(frm) { + company_email: function (frm) { frm.events.update_contact(frm); }, - user_id: function(frm) { + user_id: function (frm) { frm.events.update_contact(frm); }, - update_contact: function(frm) { - var prefered_email_fieldname = frappe.model.scrub(frm.doc.prefered_contact_email) || 'user_id'; - frm.set_value("prefered_email", - frm.fields_dict[prefered_email_fieldname].value); + update_contact: function (frm) { + var prefered_email_fieldname = frappe.model.scrub(frm.doc.prefered_contact_email) || "user_id"; + frm.set_value("prefered_email", frm.fields_dict[prefered_email_fieldname].value); }, - status: function(frm) { + status: function (frm) { return frm.call({ method: "deactivate_sales_person", args: { employee: frm.doc.employee, - status: frm.doc.status - } + status: frm.doc.status, + }, }); }, - create_user: function(frm) { + create_user: function (frm) { if (!frm.doc.prefered_email) { frappe.throw(__("Please enter Preferred Contact Email")); } @@ -79,46 +81,53 @@ frappe.ui.form.on("Employee", { method: "erpnext.setup.doctype.employee.employee.create_user", args: { employee: frm.doc.name, - email: frm.doc.prefered_email + email: frm.doc.prefered_email, }, freeze: true, freeze_message: __("Creating User..."), callback: function (r) { frm.reload_doc(); - } + }, }); - } + }, }); cur_frm.cscript = new erpnext.setup.EmployeeController({ - frm: cur_frm + frm: cur_frm, }); - -frappe.tour['Employee'] = [ +frappe.tour["Employee"] = [ { fieldname: "first_name", title: "First Name", - description: __("Enter First and Last name of Employee, based on Which Full Name will be updated. IN transactions, it will be Full Name which will be fetched.") + description: __( + "Enter First and Last name of Employee, based on Which Full Name will be updated. IN transactions, it will be Full Name which will be fetched." + ), }, { fieldname: "company", title: "Company", - description: __("Select a Company this Employee belongs to.") + description: __("Select a Company this Employee belongs to."), }, { fieldname: "date_of_birth", title: "Date of Birth", - description: __("Select Date of Birth. This will validate Employees age and prevent hiring of under-age staff.") + description: __( + "Select Date of Birth. This will validate Employees age and prevent hiring of under-age staff." + ), }, { fieldname: "date_of_joining", title: "Date of Joining", - description: __("Select Date of joining. It will have impact on the first salary calculation, Leave allocation on pro-rata bases.") + description: __( + "Select Date of joining. It will have impact on the first salary calculation, Leave allocation on pro-rata bases." + ), }, { fieldname: "reports_to", title: "Reports To", - description: __("Here, you can select a senior of this Employee. Based on this, Organization Chart will be populated.") + description: __( + "Here, you can select a senior of this Employee. Based on this, Organization Chart will be populated." + ), }, ]; diff --git a/erpnext/setup/doctype/employee/employee_list.js b/erpnext/setup/doctype/employee/employee_list.js index d37e1496ca3c..0c97b6269546 100644 --- a/erpnext/setup/doctype/employee/employee_list.js +++ b/erpnext/setup/doctype/employee/employee_list.js @@ -1,9 +1,9 @@ -frappe.listview_settings['Employee'] = { - add_fields: ["status", "branch", "department", "designation","image"], - filters: [["status","=", "Active"]], - get_indicator: function(doc) { +frappe.listview_settings["Employee"] = { + add_fields: ["status", "branch", "department", "designation", "image"], + filters: [["status", "=", "Active"]], + get_indicator: function (doc) { var indicator = [__(doc.status), frappe.utils.guess_colour(doc.status), "status,=," + doc.status]; - indicator[1] = {"Active": "green", "Inactive": "red", "Left": "gray", "Suspended": "orange"}[doc.status]; + indicator[1] = { Active: "green", Inactive: "red", Left: "gray", Suspended: "orange" }[doc.status]; return indicator; - } + }, }; diff --git a/erpnext/setup/doctype/employee/employee_tree.js b/erpnext/setup/doctype/employee/employee_tree.js index 8f52cff8c2c2..26a89719d7ff 100644 --- a/erpnext/setup/doctype/employee/employee_tree.js +++ b/erpnext/setup/doctype/employee/employee_tree.js @@ -1,13 +1,13 @@ -frappe.treeview_settings['Employee'] = { +frappe.treeview_settings["Employee"] = { get_tree_nodes: "erpnext.setup.doctype.employee.employee.get_children", filters: [ { fieldname: "company", - fieldtype:"Select", - options: ['All Companies'].concat(erpnext.utils.get_tree_options("company")), + fieldtype: "Select", + options: ["All Companies"].concat(erpnext.utils.get_tree_options("company")), label: __("Company"), - default: erpnext.utils.get_tree_default("company") - } + default: erpnext.utils.get_tree_default("company"), + }, ], breadcrumb: "Hr", disable_add_node: true, @@ -15,22 +15,22 @@ frappe.treeview_settings['Employee'] = { toolbar: [ { toggle_btn: true }, { - label:__("Edit"), - condition: function(node) { + label: __("Edit"), + condition: function (node) { return !node.is_root; }, - click: function(node) { + click: function (node) { frappe.set_route("Form", "Employee", node.data.value); - } - } + }, + }, ], menu_items: [ { label: __("New Employee"), - action: function() { + action: function () { frappe.new_doc("Employee", true); }, - condition: 'frappe.boot.user.can_create.indexOf("Employee") !== -1' - } + condition: 'frappe.boot.user.can_create.indexOf("Employee") !== -1', + }, ], }; diff --git a/erpnext/setup/doctype/employee_group/employee_group.js b/erpnext/setup/doctype/employee_group/employee_group.js index 3db57181f8ad..0ffa877ee7ea 100644 --- a/erpnext/setup/doctype/employee_group/employee_group.js +++ b/erpnext/setup/doctype/employee_group/employee_group.js @@ -1,6 +1,4 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Employee Group', { - -}); +frappe.ui.form.on("Employee Group", {}); diff --git a/erpnext/setup/doctype/global_defaults/global_defaults.js b/erpnext/setup/doctype/global_defaults/global_defaults.js index 942dd5989ead..20ac6dafde50 100644 --- a/erpnext/setup/doctype/global_defaults/global_defaults.js +++ b/erpnext/setup/doctype/global_defaults/global_defaults.js @@ -1,14 +1,14 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -frappe.ui.form.on('Global Defaults', { - onload: function(frm) { - frm.trigger('get_distance_uoms'); +frappe.ui.form.on("Global Defaults", { + onload: function (frm) { + frm.trigger("get_distance_uoms"); }, - validate: function(frm) { - frm.call('get_defaults', null, r => { + validate: function (frm) { + frm.call("get_defaults", null, (r) => { frappe.sys_defaults = r.message; - }) + }); }, get_distance_uoms: function (frm) { let units = []; @@ -17,16 +17,16 @@ frappe.ui.form.on('Global Defaults', { method: "frappe.client.get_list", args: { doctype: "UOM Conversion Factor", - filters: { "category": __("Length") }, + filters: { category: __("Length") }, fields: ["to_uom"], - limit_page_length: 500 + limit_page_length: 500, }, callback: function (r) { - r.message.forEach(row => units.push(row.to_uom)); - } + r.message.forEach((row) => units.push(row.to_uom)); + }, }); frm.set_query("default_distance_unit", function () { - return { filters: { "name": ["IN", units] } }; + return { filters: { name: ["IN", units] } }; }); - } + }, }); diff --git a/erpnext/setup/doctype/holiday_list/holiday_list.js b/erpnext/setup/doctype/holiday_list/holiday_list.js index 90d9f1b6f509..1f95a73c2424 100644 --- a/erpnext/setup/doctype/holiday_list/holiday_list.js +++ b/erpnext/setup/doctype/holiday_list/holiday_list.js @@ -2,12 +2,12 @@ // For license information, please see license.txt frappe.ui.form.on("Holiday List", { - refresh: function(frm) { + refresh: function (frm) { if (frm.doc.holidays) { frm.set_value("total_holidays", frm.doc.holidays.length); } - frm.call("get_supported_countries").then(r => { + frm.call("get_supported_countries").then((r) => { frm.subdivisions_by_country = r.message.subdivisions_by_country; frm.fields_dict.country.set_data( r.message.countries.sort((a, b) => a.label.localeCompare(b.label)) @@ -18,20 +18,20 @@ frappe.ui.form.on("Holiday List", { } }); }, - from_date: function(frm) { + from_date: function (frm) { if (frm.doc.from_date && !frm.doc.to_date) { var a_year_from_start = frappe.datetime.add_months(frm.doc.from_date, 12); frm.set_value("to_date", frappe.datetime.add_days(a_year_from_start, -1)); } }, - country: function(frm) { + country: function (frm) { frm.set_value("subdivision", ""); if (frm.doc.country) { frm.trigger("set_subdivisions"); } }, - set_subdivisions: function(frm) { + set_subdivisions: function (frm) { const subdivisions = [...frm.subdivisions_by_country[frm.doc.country]]; if (subdivisions && subdivisions.length > 0) { frm.fields_dict.subdivision.set_data(subdivisions); @@ -67,11 +67,15 @@ frappe.tour["Holiday List"] = [ { fieldname: "get_weekly_off_dates", title: "Add Holidays", - description: __("Click on Add to Holidays. This will populate the holidays table with all the dates that fall on the selected weekly off. Repeat the process for populating the dates for all your weekly holidays"), + description: __( + "Click on Add to Holidays. This will populate the holidays table with all the dates that fall on the selected weekly off. Repeat the process for populating the dates for all your weekly holidays" + ), }, { fieldname: "holidays", title: "Holidays", - description: __("Here, your weekly offs are pre-populated based on the previous selections. You can add more rows to also add public and national holidays individually.") + description: __( + "Here, your weekly offs are pre-populated based on the previous selections. You can add more rows to also add public and national holidays individually." + ), }, ]; diff --git a/erpnext/setup/doctype/holiday_list/holiday_list_calendar.js b/erpnext/setup/doctype/holiday_list/holiday_list_calendar.js index bb6d83154678..ff830881c92c 100644 --- a/erpnext/setup/doctype/holiday_list/holiday_list_calendar.js +++ b/erpnext/setup/doctype/holiday_list/holiday_list_calendar.js @@ -3,20 +3,20 @@ frappe.views.calendar["Holiday List"] = { field_map: { - "start": "holiday_date", - "end": "holiday_date", - "id": "name", - "title": "description", - "allDay": "allDay" + start: "holiday_date", + end: "holiday_date", + id: "name", + title: "description", + allDay: "allDay", }, order_by: `from_date`, get_events_method: "erpnext.setup.doctype.holiday_list.holiday_list.get_events", filters: [ { - 'fieldtype': 'Link', - 'fieldname': 'holiday_list', - 'options': 'Holiday List', - 'label': __('Holiday List') - } - ] -} + fieldtype: "Link", + fieldname: "holiday_list", + options: "Holiday List", + label: __("Holiday List"), + }, + ], +}; diff --git a/erpnext/setup/doctype/item_group/item_group.js b/erpnext/setup/doctype/item_group/item_group.js index 4b04ac1d5ef2..ec5ba2a77e0b 100644 --- a/erpnext/setup/doctype/item_group/item_group.js +++ b/erpnext/setup/doctype/item_group/item_group.js @@ -2,99 +2,116 @@ // License: GNU General Public License v3. See license.txt frappe.ui.form.on("Item Group", { - onload: function(frm) { + onload: function (frm) { frm.list_route = "Tree/Item Group"; //get query select item group - frm.fields_dict['parent_item_group'].get_query = function(doc,cdt,cdn) { - return{ - filters:[ - ['Item Group', 'is_group', '=', 1], - ['Item Group', 'name', '!=', doc.item_group_name] - ] - } - } - frm.fields_dict['item_group_defaults'].grid.get_field("default_discount_account").get_query = function(doc, cdt, cdn) { - const row = locals[cdt][cdn]; + frm.fields_dict["parent_item_group"].get_query = function (doc, cdt, cdn) { return { - filters: { - 'report_type': 'Profit and Loss', - 'company': row.company, - "is_group": 0 - } + filters: [ + ["Item Group", "is_group", "=", 1], + ["Item Group", "name", "!=", doc.item_group_name], + ], }; - } - frm.fields_dict["item_group_defaults"].grid.get_field("expense_account").get_query = function(doc, cdt, cdn) { + }; + frm.fields_dict["item_group_defaults"].grid.get_field("default_discount_account").get_query = + function (doc, cdt, cdn) { + const row = locals[cdt][cdn]; + return { + filters: { + report_type: "Profit and Loss", + company: row.company, + is_group: 0, + }, + }; + }; + frm.fields_dict["item_group_defaults"].grid.get_field("expense_account").get_query = function ( + doc, + cdt, + cdn + ) { const row = locals[cdt][cdn]; return { query: "erpnext.controllers.queries.get_expense_account", - filters: { company: row.company } - } - } - frm.fields_dict["item_group_defaults"].grid.get_field("income_account").get_query = function(doc, cdt, cdn) { + filters: { company: row.company }, + }; + }; + frm.fields_dict["item_group_defaults"].grid.get_field("income_account").get_query = function ( + doc, + cdt, + cdn + ) { const row = locals[cdt][cdn]; return { query: "erpnext.controllers.queries.get_income_account", - filters: { company: row.company } - } - } + filters: { company: row.company }, + }; + }; - frm.fields_dict["item_group_defaults"].grid.get_field("buying_cost_center").get_query = function(doc, cdt, cdn) { + frm.fields_dict["item_group_defaults"].grid.get_field("buying_cost_center").get_query = function ( + doc, + cdt, + cdn + ) { const row = locals[cdt][cdn]; return { filters: { - "is_group": 0, - "company": row.company - } - } - } + is_group: 0, + company: row.company, + }, + }; + }; - frm.fields_dict["item_group_defaults"].grid.get_field("selling_cost_center").get_query = function(doc, cdt, cdn) { + frm.fields_dict["item_group_defaults"].grid.get_field("selling_cost_center").get_query = function ( + doc, + cdt, + cdn + ) { const row = locals[cdt][cdn]; return { filters: { - "is_group": 0, - "company": row.company - } - } - } + is_group: 0, + company: row.company, + }, + }; + }; }, - refresh: function(frm) { + refresh: function (frm) { frm.trigger("set_root_readonly"); - frm.add_custom_button(__("Item Group Tree"), function() { + frm.add_custom_button(__("Item Group Tree"), function () { frappe.set_route("Tree", "Item Group"); }); - if(!frm.is_new()) { - frm.add_custom_button(__("Items"), function() { - frappe.set_route("List", "Item", {"item_group": frm.doc.name}); + if (!frm.is_new()) { + frm.add_custom_button(__("Items"), function () { + frappe.set_route("List", "Item", { item_group: frm.doc.name }); }); } - frappe.model.with_doctype('Website Item', () => { - const web_item_meta = frappe.get_meta('Website Item'); + frappe.model.with_doctype("Website Item", () => { + const web_item_meta = frappe.get_meta("Website Item"); - const valid_fields = web_item_meta.fields.filter(df => - ['Link', 'Table MultiSelect'].includes(df.fieldtype) && !df.hidden - ).map(df => - ({ label: df.label, value: df.fieldname }) - ); + const valid_fields = web_item_meta.fields + .filter((df) => ["Link", "Table MultiSelect"].includes(df.fieldtype) && !df.hidden) + .map((df) => ({ label: df.label, value: df.fieldname })); frm.get_field("filter_fields").grid.update_docfield_property( - 'fieldname', 'options', valid_fields + "fieldname", + "options", + valid_fields ); }); }, - set_root_readonly: function(frm) { + set_root_readonly: function (frm) { // read-only for root item group frm.set_intro(""); - if(!frm.doc.parent_item_group && !frm.doc.__islocal) { + if (!frm.doc.parent_item_group && !frm.doc.__islocal) { frm.set_read_only(); frm.set_intro(__("This is a root item group and cannot be edited."), true); } }, - page_name: frappe.utils.warn_page_name_change + page_name: frappe.utils.warn_page_name_change, }); diff --git a/erpnext/setup/doctype/item_group/item_group_tree.js b/erpnext/setup/doctype/item_group/item_group_tree.js index b2628f4f4f83..a7c2b6360cf0 100644 --- a/erpnext/setup/doctype/item_group/item_group_tree.js +++ b/erpnext/setup/doctype/item_group/item_group_tree.js @@ -1,3 +1,3 @@ frappe.treeview_settings["Item Group"] = { - ignore_fields:["parent_item_group"] -} + ignore_fields: ["parent_item_group"], +}; diff --git a/erpnext/setup/doctype/party_type/party_type.js b/erpnext/setup/doctype/party_type/party_type.js index 7a96dc55ee98..9bbfd7d8832c 100644 --- a/erpnext/setup/doctype/party_type/party_type.js +++ b/erpnext/setup/doctype/party_type/party_type.js @@ -1,15 +1,15 @@ // Copyright (c) 2016, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Party Type', { - setup: function(frm) { - frm.fields_dict["party_type"].get_query = function(frm) { +frappe.ui.form.on("Party Type", { + setup: function (frm) { + frm.fields_dict["party_type"].get_query = function (frm) { return { filters: { - "istable": 0, - "is_submittable": 0 - } - } - } - } + istable: 0, + is_submittable: 0, + }, + }; + }; + }, }); diff --git a/erpnext/setup/doctype/print_heading/print_heading.js b/erpnext/setup/doctype/print_heading/print_heading.js index 3680906057fa..273e30fd1973 100644 --- a/erpnext/setup/doctype/print_heading/print_heading.js +++ b/erpnext/setup/doctype/print_heading/print_heading.js @@ -1,13 +1,7 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt - - //--------- ONLOAD ------------- -cur_frm.cscript.onload = function(doc, cdt, cdn) { - -} - -cur_frm.cscript.refresh = function(doc, cdt, cdn) { +cur_frm.cscript.onload = function (doc, cdt, cdn) {}; -} +cur_frm.cscript.refresh = function (doc, cdt, cdn) {}; diff --git a/erpnext/setup/doctype/quotation_lost_reason/quotation_lost_reason.js b/erpnext/setup/doctype/quotation_lost_reason/quotation_lost_reason.js index 3680906057fa..273e30fd1973 100644 --- a/erpnext/setup/doctype/quotation_lost_reason/quotation_lost_reason.js +++ b/erpnext/setup/doctype/quotation_lost_reason/quotation_lost_reason.js @@ -1,13 +1,7 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt - - //--------- ONLOAD ------------- -cur_frm.cscript.onload = function(doc, cdt, cdn) { - -} - -cur_frm.cscript.refresh = function(doc, cdt, cdn) { +cur_frm.cscript.onload = function (doc, cdt, cdn) {}; -} +cur_frm.cscript.refresh = function (doc, cdt, cdn) {}; diff --git a/erpnext/setup/doctype/sales_partner/sales_partner.js b/erpnext/setup/doctype/sales_partner/sales_partner.js index 5656d43e852f..cb957941dc8e 100644 --- a/erpnext/setup/doctype/sales_partner/sales_partner.js +++ b/erpnext/setup/doctype/sales_partner/sales_partner.js @@ -1,34 +1,33 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -frappe.ui.form.on('Sales Partner', { - refresh: function(frm) { - frappe.dynamic_link = {doc: frm.doc, fieldname: 'name', doctype: 'Sales Partner'} +frappe.ui.form.on("Sales Partner", { + refresh: function (frm) { + frappe.dynamic_link = { doc: frm.doc, fieldname: "name", doctype: "Sales Partner" }; - if(frm.doc.__islocal){ - hide_field(['address_html', 'contact_html', 'address_contacts']); + if (frm.doc.__islocal) { + hide_field(["address_html", "contact_html", "address_contacts"]); frappe.contacts.clear_address_and_contact(frm); - } - else{ - unhide_field(['address_html', 'contact_html', 'address_contacts']); + } else { + unhide_field(["address_html", "contact_html", "address_contacts"]); frappe.contacts.render_address_and_contact(frm); } }, - setup: function(frm) { - frm.fields_dict["targets"].grid.get_field("distribution_id").get_query = function(doc, cdt, cdn){ + setup: function (frm) { + frm.fields_dict["targets"].grid.get_field("distribution_id").get_query = function (doc, cdt, cdn) { var row = locals[cdt][cdn]; return { filters: { - 'fiscal_year': row.fiscal_year - } - } + fiscal_year: row.fiscal_year, + }, + }; }; }, - referral_code:function(frm){ + referral_code: function (frm) { if (frm.doc.referral_code) { - frm.doc.referral_code=frm.doc.referral_code.toUpperCase(); - frm.refresh_field('referral_code'); + frm.doc.referral_code = frm.doc.referral_code.toUpperCase(); + frm.refresh_field("referral_code"); } - } + }, }); diff --git a/erpnext/setup/doctype/sales_person/sales_person.js b/erpnext/setup/doctype/sales_person/sales_person.js index d86a8f3d9849..89f794e09551 100644 --- a/erpnext/setup/doctype/sales_person/sales_person.js +++ b/erpnext/setup/doctype/sales_person/sales_person.js @@ -1,59 +1,69 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -frappe.ui.form.on('Sales Person', { - refresh: function(frm) { - if(frm.doc.__onload && frm.doc.__onload.dashboard_info) { +frappe.ui.form.on("Sales Person", { + refresh: function (frm) { + if (frm.doc.__onload && frm.doc.__onload.dashboard_info) { let info = frm.doc.__onload.dashboard_info; - frm.dashboard.add_indicator(__('Total Contribution Amount Against Orders: {0}', - [format_currency(info.allocated_amount_against_order, info.currency)]), 'blue'); + frm.dashboard.add_indicator( + __("Total Contribution Amount Against Orders: {0}", [ + format_currency(info.allocated_amount_against_order, info.currency), + ]), + "blue" + ); - frm.dashboard.add_indicator(__('Total Contribution Amount Against Invoices: {0}', - [format_currency(info.allocated_amount_against_invoice, info.currency)]), 'blue'); + frm.dashboard.add_indicator( + __("Total Contribution Amount Against Invoices: {0}", [ + format_currency(info.allocated_amount_against_invoice, info.currency), + ]), + "blue" + ); } }, - setup: function(frm) { - frm.fields_dict["targets"].grid.get_field("distribution_id").get_query = function(doc, cdt, cdn){ + setup: function (frm) { + frm.fields_dict["targets"].grid.get_field("distribution_id").get_query = function (doc, cdt, cdn) { var row = locals[cdt][cdn]; return { filters: { - 'fiscal_year': row.fiscal_year - } - } + fiscal_year: row.fiscal_year, + }, + }; }; frm.make_methods = { - 'Sales Order': () => frappe.new_doc("Sales Order") - .then(() => frm.add_child("sales_team", {"sales_person": frm.doc.name})) - } - } + "Sales Order": () => + frappe + .new_doc("Sales Order") + .then(() => frm.add_child("sales_team", { sales_person: frm.doc.name })), + }; + }, }); -cur_frm.cscript.refresh = function(doc, cdt, cdn) { +cur_frm.cscript.refresh = function (doc, cdt, cdn) { cur_frm.cscript.set_root_readonly(doc); -} +}; -cur_frm.cscript.set_root_readonly = function(doc) { +cur_frm.cscript.set_root_readonly = function (doc) { // read-only for root - if(!doc.parent_sales_person && !doc.__islocal) { + if (!doc.parent_sales_person && !doc.__islocal) { cur_frm.set_read_only(); cur_frm.set_intro(__("This is a root sales person and cannot be edited.")); } else { cur_frm.set_intro(null); } -} +}; //get query select sales person -cur_frm.fields_dict['parent_sales_person'].get_query = function(doc, cdt, cdn) { - return{ +cur_frm.fields_dict["parent_sales_person"].get_query = function (doc, cdt, cdn) { + return { filters: [ - ['Sales Person', 'is_group', '=', 1], - ['Sales Person', 'name', '!=', doc.sales_person_name] - ] - } -} + ["Sales Person", "is_group", "=", 1], + ["Sales Person", "name", "!=", doc.sales_person_name], + ], + }; +}; -cur_frm.fields_dict.employee.get_query = function(doc, cdt, cdn) { - return { query: "erpnext.controllers.queries.employee_query" } -} +cur_frm.fields_dict.employee.get_query = function (doc, cdt, cdn) { + return { query: "erpnext.controllers.queries.employee_query" }; +}; diff --git a/erpnext/setup/doctype/sales_person/sales_person_tree.js b/erpnext/setup/doctype/sales_person/sales_person_tree.js index 00056fde8699..0fcd592aea35 100644 --- a/erpnext/setup/doctype/sales_person/sales_person_tree.js +++ b/erpnext/setup/doctype/sales_person/sales_person_tree.js @@ -1,12 +1,18 @@ - frappe.treeview_settings["Sales Person"] = { fields: [ - {fieldtype:'Data', fieldname: 'sales_person_name', - label:__('New Sales Person Name'), reqd:true}, - {fieldtype:'Link', fieldname:'employee', - label:__('Employee'), options:'Employee', - description: __("Please enter Employee Id of this sales person")}, - {fieldtype:'Check', fieldname:'is_group', label:__('Group Node'), - description: __("Further nodes can be only created under 'Group' type nodes")} + { fieldtype: "Data", fieldname: "sales_person_name", label: __("New Sales Person Name"), reqd: true }, + { + fieldtype: "Link", + fieldname: "employee", + label: __("Employee"), + options: "Employee", + description: __("Please enter Employee Id of this sales person"), + }, + { + fieldtype: "Check", + fieldname: "is_group", + label: __("Group Node"), + description: __("Further nodes can be only created under 'Group' type nodes"), + }, ], -} +}; diff --git a/erpnext/setup/doctype/supplier_group/supplier_group.js b/erpnext/setup/doctype/supplier_group/supplier_group.js index e75030d44140..cd58d23889d0 100644 --- a/erpnext/setup/doctype/supplier_group/supplier_group.js +++ b/erpnext/setup/doctype/supplier_group/supplier_group.js @@ -1,14 +1,14 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -cur_frm.cscript.refresh = function(doc) { +cur_frm.cscript.refresh = function (doc) { cur_frm.set_intro(doc.__islocal ? "" : __("There is nothing to edit.")); cur_frm.cscript.set_root_readonly(doc); }; -cur_frm.cscript.set_root_readonly = function(doc) { +cur_frm.cscript.set_root_readonly = function (doc) { // read-only for root customer group - if(!doc.parent_supplier_group && !doc.__islocal) { + if (!doc.parent_supplier_group && !doc.__islocal) { cur_frm.set_read_only(); cur_frm.set_intro(__("This is a root supplier group and cannot be edited.")); } else { @@ -17,22 +17,22 @@ cur_frm.cscript.set_root_readonly = function(doc) { }; // get query select Customer Group -cur_frm.fields_dict['parent_supplier_group'].get_query = function() { +cur_frm.fields_dict["parent_supplier_group"].get_query = function () { return { filters: { - 'is_group': 1, - 'name': ['!=', cur_frm.doc.supplier_group_name] - } + is_group: 1, + name: ["!=", cur_frm.doc.supplier_group_name], + }, }; }; -cur_frm.fields_dict['accounts'].grid.get_field('account').get_query = function(doc, cdt, cdn) { - var d = locals[cdt][cdn]; +cur_frm.fields_dict["accounts"].grid.get_field("account").get_query = function (doc, cdt, cdn) { + var d = locals[cdt][cdn]; return { filters: { - 'account_type': 'Payable', - 'company': d.company, - "is_group": 0 - } + account_type: "Payable", + company: d.company, + is_group: 0, + }, }; }; diff --git a/erpnext/setup/doctype/supplier_group/supplier_group_tree.js b/erpnext/setup/doctype/supplier_group/supplier_group_tree.js index 728793eb25f0..9210dc1f0029 100644 --- a/erpnext/setup/doctype/supplier_group/supplier_group_tree.js +++ b/erpnext/setup/doctype/supplier_group/supplier_group_tree.js @@ -1,4 +1,4 @@ frappe.treeview_settings["Supplier Group"] = { breadcrumbs: "Buying", - ignore_fields:["parent_supplier_group"] + ignore_fields: ["parent_supplier_group"], }; diff --git a/erpnext/setup/doctype/territory/territory.js b/erpnext/setup/doctype/territory/territory.js index 3caf814c90b8..744c7fe01e29 100644 --- a/erpnext/setup/doctype/territory/territory.js +++ b/erpnext/setup/doctype/territory/territory.js @@ -2,38 +2,38 @@ // License: GNU General Public License v3. See license.txt frappe.ui.form.on("Territory", { - setup: function(frm) { - frm.fields_dict["targets"].grid.get_field("distribution_id").get_query = function(doc, cdt, cdn){ + setup: function (frm) { + frm.fields_dict["targets"].grid.get_field("distribution_id").get_query = function (doc, cdt, cdn) { var row = locals[cdt][cdn]; return { filters: { - 'fiscal_year': row.fiscal_year - } - } + fiscal_year: row.fiscal_year, + }, + }; }; - } + }, }); -cur_frm.cscript.refresh = function(doc, cdt, cdn) { +cur_frm.cscript.refresh = function (doc, cdt, cdn) { cur_frm.cscript.set_root_readonly(doc); -} +}; -cur_frm.cscript.set_root_readonly = function(doc) { +cur_frm.cscript.set_root_readonly = function (doc) { // read-only for root territory - if(!doc.parent_territory && !doc.__islocal) { + if (!doc.parent_territory && !doc.__islocal) { cur_frm.set_read_only(); cur_frm.set_intro(__("This is a root territory and cannot be edited.")); } else { cur_frm.set_intro(null); } -} +}; //get query select territory -cur_frm.fields_dict['parent_territory'].get_query = function(doc,cdt,cdn) { - return{ - filters:[ - ['Territory', 'is_group', '=', 1], - ['Territory', 'name', '!=', doc.territory_name] - ] - } -} +cur_frm.fields_dict["parent_territory"].get_query = function (doc, cdt, cdn) { + return { + filters: [ + ["Territory", "is_group", "=", 1], + ["Territory", "name", "!=", doc.territory_name], + ], + }; +}; diff --git a/erpnext/setup/doctype/territory/territory_tree.js b/erpnext/setup/doctype/territory/territory_tree.js index dadeeef09e9b..4892b8c45fc5 100644 --- a/erpnext/setup/doctype/territory/territory_tree.js +++ b/erpnext/setup/doctype/territory/territory_tree.js @@ -1,3 +1,3 @@ frappe.treeview_settings["Territory"] = { - ignore_fields:["parent_territory"] -} + ignore_fields: ["parent_territory"], +}; diff --git a/erpnext/setup/doctype/transaction_deletion_record/transaction_deletion_record.js b/erpnext/setup/doctype/transaction_deletion_record/transaction_deletion_record.js index a7b0709b3da2..527c753d6a97 100644 --- a/erpnext/setup/doctype/transaction_deletion_record/transaction_deletion_record.js +++ b/erpnext/setup/doctype/transaction_deletion_record/transaction_deletion_record.js @@ -1,39 +1,38 @@ // Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Transaction Deletion Record', { - onload: function(frm) { +frappe.ui.form.on("Transaction Deletion Record", { + onload: function (frm) { if (frm.doc.docstatus == 0) { let doctypes_to_be_ignored_array; frappe.call({ - method: 'erpnext.setup.doctype.transaction_deletion_record.transaction_deletion_record.get_doctypes_to_be_ignored', - callback: function(r) { + method: "erpnext.setup.doctype.transaction_deletion_record.transaction_deletion_record.get_doctypes_to_be_ignored", + callback: function (r) { doctypes_to_be_ignored_array = r.message; populate_doctypes_to_be_ignored(doctypes_to_be_ignored_array, frm); - frm.fields_dict['doctypes_to_be_ignored'].grid.set_column_disp('no_of_docs', false); - frm.refresh_field('doctypes_to_be_ignored'); - } + frm.fields_dict["doctypes_to_be_ignored"].grid.set_column_disp("no_of_docs", false); + frm.refresh_field("doctypes_to_be_ignored"); + }, }); } - frm.get_field('doctypes_to_be_ignored').grid.cannot_add_rows = true; - frm.fields_dict['doctypes_to_be_ignored'].grid.set_column_disp('no_of_docs', false); - frm.refresh_field('doctypes_to_be_ignored'); + frm.get_field("doctypes_to_be_ignored").grid.cannot_add_rows = true; + frm.fields_dict["doctypes_to_be_ignored"].grid.set_column_disp("no_of_docs", false); + frm.refresh_field("doctypes_to_be_ignored"); }, - refresh: function(frm) { - frm.fields_dict['doctypes_to_be_ignored'].grid.set_column_disp('no_of_docs', false); - frm.refresh_field('doctypes_to_be_ignored'); - } - + refresh: function (frm) { + frm.fields_dict["doctypes_to_be_ignored"].grid.set_column_disp("no_of_docs", false); + frm.refresh_field("doctypes_to_be_ignored"); + }, }); function populate_doctypes_to_be_ignored(doctypes_to_be_ignored_array, frm) { if (frm.doc.doctypes_to_be_ignored.length === 0) { var i; for (i = 0; i < doctypes_to_be_ignored_array.length; i++) { - frm.add_child('doctypes_to_be_ignored', { - doctype_name: doctypes_to_be_ignored_array[i] + frm.add_child("doctypes_to_be_ignored", { + doctype_name: doctypes_to_be_ignored_array[i], }); } } diff --git a/erpnext/setup/doctype/transaction_deletion_record/transaction_deletion_record_list.js b/erpnext/setup/doctype/transaction_deletion_record/transaction_deletion_record_list.js index c238f18abad7..08a35df2c174 100644 --- a/erpnext/setup/doctype/transaction_deletion_record/transaction_deletion_record_list.js +++ b/erpnext/setup/doctype/transaction_deletion_record/transaction_deletion_record_list.js @@ -1,12 +1,12 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -frappe.listview_settings['Transaction Deletion Record'] = { - get_indicator: function(doc) { +frappe.listview_settings["Transaction Deletion Record"] = { + get_indicator: function (doc) { if (doc.docstatus == 0) { return [__("Draft"), "red"]; } else { return [__("Completed"), "green"]; } - } + }, }; diff --git a/erpnext/setup/doctype/uom/uom.js b/erpnext/setup/doctype/uom/uom.js index 3680906057fa..273e30fd1973 100644 --- a/erpnext/setup/doctype/uom/uom.js +++ b/erpnext/setup/doctype/uom/uom.js @@ -1,13 +1,7 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt - - //--------- ONLOAD ------------- -cur_frm.cscript.onload = function(doc, cdt, cdn) { - -} - -cur_frm.cscript.refresh = function(doc, cdt, cdn) { +cur_frm.cscript.onload = function (doc, cdt, cdn) {}; -} +cur_frm.cscript.refresh = function (doc, cdt, cdn) {}; diff --git a/erpnext/setup/doctype/uom_conversion_factor/uom_conversion_factor.js b/erpnext/setup/doctype/uom_conversion_factor/uom_conversion_factor.js index e734d83500fd..e975729dca75 100644 --- a/erpnext/setup/doctype/uom_conversion_factor/uom_conversion_factor.js +++ b/erpnext/setup/doctype/uom_conversion_factor/uom_conversion_factor.js @@ -1,8 +1,6 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('UOM Conversion Factor', { - refresh: function() { - - } +frappe.ui.form.on("UOM Conversion Factor", { + refresh: function () {}, }); diff --git a/erpnext/setup/doctype/vehicle/vehicle.js b/erpnext/setup/doctype/vehicle/vehicle.js index f12c4346852d..9d598a9883b2 100644 --- a/erpnext/setup/doctype/vehicle/vehicle.js +++ b/erpnext/setup/doctype/vehicle/vehicle.js @@ -1,8 +1,6 @@ // Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Vehicle', { - refresh: function(frm) { - - } +frappe.ui.form.on("Vehicle", { + refresh: function (frm) {}, }); diff --git a/erpnext/setup/page/welcome_to_erpnext/welcome_to_erpnext.js b/erpnext/setup/page/welcome_to_erpnext/welcome_to_erpnext.js index f072b8d8c574..0b4d82351063 100644 --- a/erpnext/setup/page/welcome_to_erpnext/welcome_to_erpnext.js +++ b/erpnext/setup/page/welcome_to_erpnext/welcome_to_erpnext.js @@ -1,20 +1,27 @@ -frappe.pages['welcome-to-erpnext'].on_page_load = function(wrapper) { +frappe.pages["welcome-to-erpnext"].on_page_load = function (wrapper) { var parent = $('
              ').appendTo(wrapper); parent.html(frappe.render_template("welcome_to_erpnext", {})); - parent.find(".video-placeholder").on("click", function() { + parent.find(".video-placeholder").on("click", function () { window.erpnext_welcome_video_started = true; parent.find(".video-placeholder").addClass("hidden"); - parent.find(".embed-responsive").append('') + parent + .find(".embed-responsive") + .append( + '' + ); }); // pause video on page change - $(document).on("page-change", function() { + $(document).on("page-change", function () { if (window.erpnext_welcome_video_started && parent) { - parent.find(".video-playlist").each(function() { - this.contentWindow.postMessage('{"event":"command","func":"' + 'pauseVideo' + '","args":""}', '*'); + parent.find(".video-playlist").each(function () { + this.contentWindow.postMessage( + '{"event":"command","func":"' + "pauseVideo" + '","args":""}', + "*" + ); }); } }); -} +}; diff --git a/erpnext/stock/dashboard/item_dashboard.js b/erpnext/stock/dashboard/item_dashboard.js index bef438f9fd72..29db6e3c01da 100644 --- a/erpnext/stock/dashboard/item_dashboard.js +++ b/erpnext/stock/dashboard/item_dashboard.js @@ -1,4 +1,4 @@ -frappe.provide('erpnext.stock'); +frappe.provide("erpnext.stock"); erpnext.stock.ItemDashboard = class ItemDashboard { constructor(opts) { @@ -9,46 +9,51 @@ erpnext.stock.ItemDashboard = class ItemDashboard { var me = this; this.start = 0; if (!this.sort_by) { - this.sort_by = 'projected_qty'; - this.sort_order = 'asc'; + this.sort_by = "projected_qty"; + this.sort_order = "asc"; } - this.content = $(frappe.render_template('item_dashboard')).appendTo(this.parent); - this.result = this.content.find('.result'); + this.content = $(frappe.render_template("item_dashboard")).appendTo(this.parent); + this.result = this.content.find(".result"); - this.content.on('click', '.btn-move', function () { + this.content.on("click", ".btn-move", function () { handle_move_add($(this), "Move"); }); - this.content.on('click', '.btn-add', function () { + this.content.on("click", ".btn-add", function () { handle_move_add($(this), "Add"); }); - this.content.on('click', '.btn-edit', function () { - let item = unescape($(this).attr('data-item')); - let warehouse = unescape($(this).attr('data-warehouse')); - let company = unescape($(this).attr('data-company')); - frappe.db.get_value('Putaway Rule', { - 'item_code': item, - 'warehouse': warehouse, - 'company': company - }, 'name', (r) => { - frappe.set_route("Form", "Putaway Rule", r.name); - }); + this.content.on("click", ".btn-edit", function () { + let item = unescape($(this).attr("data-item")); + let warehouse = unescape($(this).attr("data-warehouse")); + let company = unescape($(this).attr("data-company")); + frappe.db.get_value( + "Putaway Rule", + { + item_code: item, + warehouse: warehouse, + company: company, + }, + "name", + (r) => { + frappe.set_route("Form", "Putaway Rule", r.name); + } + ); }); function handle_move_add(element, action) { - let item = unescape(element.attr('data-item')); - let warehouse = unescape(element.attr('data-warehouse')); - let actual_qty = unescape(element.attr('data-actual_qty')); - let disable_quick_entry = Number(unescape(element.attr('data-disable_quick_entry'))); + let item = unescape(element.attr("data-item")); + let warehouse = unescape(element.attr("data-warehouse")); + let actual_qty = unescape(element.attr("data-actual_qty")); + let disable_quick_entry = Number(unescape(element.attr("data-disable_quick_entry"))); let entry_type = action === "Move" ? "Material Transfer" : "Material Receipt"; if (disable_quick_entry) { open_stock_entry(item, warehouse, entry_type); } else { if (action === "Add") { - let rate = unescape($(this).attr('data-rate')); + let rate = unescape($(this).attr("data-rate")); erpnext.stock.move_item(item, null, warehouse, actual_qty, rate, function () { me.refresh(); }); @@ -61,35 +66,33 @@ erpnext.stock.ItemDashboard = class ItemDashboard { } function open_stock_entry(item, warehouse, entry_type) { - frappe.model.with_doctype('Stock Entry', function () { - var doc = frappe.model.get_new_doc('Stock Entry'); + frappe.model.with_doctype("Stock Entry", function () { + var doc = frappe.model.get_new_doc("Stock Entry"); if (entry_type) { doc.stock_entry_type = entry_type; } - var row = frappe.model.add_child(doc, 'items'); + var row = frappe.model.add_child(doc, "items"); row.item_code = item; if (entry_type === "Material Transfer") { row.s_warehouse = warehouse; - } - else { + } else { row.t_warehouse = warehouse; } - frappe.set_route('Form', doc.doctype, doc.name); + frappe.set_route("Form", doc.doctype, doc.name); }); } // more - this.content.find('.btn-more').on('click', function () { + this.content.find(".btn-more").on("click", function () { me.start += me.page_length; me.refresh(); }); - } refresh() { - if(this.before_refresh) { + if (this.before_refresh) { this.before_refresh(); } @@ -101,7 +104,7 @@ erpnext.stock.ItemDashboard = class ItemDashboard { company: this.company, start: this.start, sort_by: this.sort_by, - sort_order: this.sort_order + sort_order: this.sort_order, }; var me = this; @@ -110,11 +113,11 @@ erpnext.stock.ItemDashboard = class ItemDashboard { args: args, callback: function (r) { me.render(r.message); - } + }, }); } render(data) { - if (this.start===0) { + if (this.start === 0) { this.max_count = 0; this.result.empty(); } @@ -129,22 +132,22 @@ erpnext.stock.ItemDashboard = class ItemDashboard { this.max_count = this.max_count; // show more button - if (data && data.length === (this.page_length + 1)) { - this.content.find('.more').removeClass('hidden'); + if (data && data.length === this.page_length + 1) { + this.content.find(".more").removeClass("hidden"); // remove the last element data.splice(-1); } else { - this.content.find('.more').addClass('hidden'); + this.content.find(".more").addClass("hidden"); } // If not any stock in any warehouses provide a message to end user if (context.data.length > 0) { - this.content.find('.result').css('text-align', 'unset'); + this.content.find(".result").css("text-align", "unset"); $(frappe.render_template(this.template, context)).appendTo(this.result); } else { var message = __("No Stock Available Currently"); - this.content.find('.result').css('text-align', 'center'); + this.content.find(".result").css("text-align", "center"); $(`
              ${message}
              `).appendTo(this.result); @@ -152,19 +155,23 @@ erpnext.stock.ItemDashboard = class ItemDashboard { } get_item_dashboard_data(data, max_count, show_item) { - if(!max_count) max_count = 0; - if(!data) data = []; + if (!max_count) max_count = 0; + if (!data) data = []; data.forEach(function (d) { - d.actual_or_pending = d.projected_qty + d.reserved_qty + d.reserved_qty_for_production + d.reserved_qty_for_sub_contract; + d.actual_or_pending = + d.projected_qty + + d.reserved_qty + + d.reserved_qty_for_production + + d.reserved_qty_for_sub_contract; d.pending_qty = 0; - d.total_reserved = d.reserved_qty + d.reserved_qty_for_production + d.reserved_qty_for_sub_contract; + d.total_reserved = + d.reserved_qty + d.reserved_qty_for_production + d.reserved_qty_for_sub_contract; if (d.actual_or_pending > d.actual_qty) { d.pending_qty = d.actual_or_pending - d.actual_qty; } - max_count = Math.max(d.actual_or_pending, d.actual_qty, - d.total_reserved, max_count); + max_count = Math.max(d.actual_or_pending, d.actual_qty, d.total_reserved, max_count); }); let can_write = 0; @@ -176,7 +183,7 @@ erpnext.stock.ItemDashboard = class ItemDashboard { data: data, max_count: max_count, can_write: can_write, - show_item: show_item || false + show_item: show_item || false, }; } @@ -201,73 +208,74 @@ erpnext.stock.ItemDashboard = class ItemDashboard { erpnext.stock.move_item = function (item, source, target, actual_qty, rate, callback) { var dialog = new frappe.ui.Dialog({ - title: target ? __('Add Item') : __('Move Item'), - fields: [{ - fieldname: 'item_code', - label: __('Item'), - fieldtype: 'Link', - options: 'Item', - read_only: 1 - }, - { - fieldname: 'source', - label: __('Source Warehouse'), - fieldtype: 'Link', - options: 'Warehouse', - read_only: 1 - }, - { - fieldname: 'target', - label: __('Target Warehouse'), - fieldtype: 'Link', - options: 'Warehouse', - reqd: 1, - get_query() { - return { - filters: { - is_group: 0 - } - } - } - }, - { - fieldname: 'qty', - label: __('Quantity'), - reqd: 1, - fieldtype: 'Float', - description: __('Available {0}', [actual_qty]) - }, - { - fieldname: 'rate', - label: __('Rate'), - fieldtype: 'Currency', - hidden: 1 - }, + title: target ? __("Add Item") : __("Move Item"), + fields: [ + { + fieldname: "item_code", + label: __("Item"), + fieldtype: "Link", + options: "Item", + read_only: 1, + }, + { + fieldname: "source", + label: __("Source Warehouse"), + fieldtype: "Link", + options: "Warehouse", + read_only: 1, + }, + { + fieldname: "target", + label: __("Target Warehouse"), + fieldtype: "Link", + options: "Warehouse", + reqd: 1, + get_query() { + return { + filters: { + is_group: 0, + }, + }; + }, + }, + { + fieldname: "qty", + label: __("Quantity"), + reqd: 1, + fieldtype: "Float", + description: __("Available {0}", [actual_qty]), + }, + { + fieldname: "rate", + label: __("Rate"), + fieldtype: "Currency", + hidden: 1, + }, ], }); dialog.show(); - dialog.get_field('item_code').set_input(item); + dialog.get_field("item_code").set_input(item); if (source) { - dialog.get_field('source').set_input(source); + dialog.get_field("source").set_input(source); } else { - dialog.get_field('source').df.hidden = 1; - dialog.get_field('source').refresh(); + dialog.get_field("source").df.hidden = 1; + dialog.get_field("source").refresh(); } if (rate) { - dialog.get_field('rate').set_value(rate); - dialog.get_field('rate').df.hidden = 0; - dialog.get_field('rate').refresh(); + dialog.get_field("rate").set_value(rate); + dialog.get_field("rate").df.hidden = 0; + dialog.get_field("rate").refresh(); } if (target) { - dialog.get_field('target').df.read_only = 1; - dialog.get_field('target').value = target; - dialog.get_field('target').refresh(); + dialog.get_field("target").df.read_only = 1; + dialog.get_field("target").value = target; + dialog.get_field("target").refresh(); } - dialog.set_primary_action(__('Create Stock Entry'), function () { + dialog.set_primary_action(__("Create Stock Entry"), function () { if (source && (dialog.get_value("qty") == 0 || dialog.get_value("qty") > actual_qty)) { frappe.msgprint(__("Quantity must be greater than zero, and less or equal to {0}", [actual_qty])); return; @@ -278,20 +286,20 @@ erpnext.stock.move_item = function (item, source, target, actual_qty, rate, call return; } - frappe.model.with_doctype('Stock Entry', function () { - let doc = frappe.model.get_new_doc('Stock Entry'); - doc.from_warehouse = dialog.get_value('source'); - doc.to_warehouse = dialog.get_value('target'); + frappe.model.with_doctype("Stock Entry", function () { + let doc = frappe.model.get_new_doc("Stock Entry"); + doc.from_warehouse = dialog.get_value("source"); + doc.to_warehouse = dialog.get_value("target"); doc.stock_entry_type = doc.from_warehouse ? "Material Transfer" : "Material Receipt"; - let row = frappe.model.add_child(doc, 'items'); - row.item_code = dialog.get_value('item_code'); - row.s_warehouse = dialog.get_value('source'); - row.t_warehouse = dialog.get_value('target'); - row.qty = dialog.get_value('qty'); + let row = frappe.model.add_child(doc, "items"); + row.item_code = dialog.get_value("item_code"); + row.s_warehouse = dialog.get_value("source"); + row.t_warehouse = dialog.get_value("target"); + row.qty = dialog.get_value("qty"); row.conversion_factor = 1; - row.transfer_qty = dialog.get_value('qty'); - row.basic_rate = dialog.get_value('rate'); - frappe.set_route('Form', doc.doctype, doc.name); + row.transfer_qty = dialog.get_value("qty"); + row.basic_rate = dialog.get_value("rate"); + frappe.set_route("Form", doc.doctype, doc.name); }); }); }; diff --git a/erpnext/stock/dashboard_chart_source/warehouse_wise_stock_value/warehouse_wise_stock_value.js b/erpnext/stock/dashboard_chart_source/warehouse_wise_stock_value/warehouse_wise_stock_value.js index 2b9d46e4ab0d..a550174d6563 100644 --- a/erpnext/stock/dashboard_chart_source/warehouse_wise_stock_value/warehouse_wise_stock_value.js +++ b/erpnext/stock/dashboard_chart_source/warehouse_wise_stock_value/warehouse_wise_stock_value.js @@ -1,4 +1,4 @@ -frappe.provide('frappe.dashboards.chart_sources'); +frappe.provide("frappe.dashboards.chart_sources"); frappe.dashboards.chart_sources["Warehouse wise Stock Value"] = { method: "erpnext.stock.dashboard_chart_source.warehouse_wise_stock_value.warehouse_wise_stock_value.get", @@ -8,7 +8,7 @@ frappe.dashboards.chart_sources["Warehouse wise Stock Value"] = { label: __("Company"), fieldtype: "Link", options: "Company", - default: frappe.defaults.get_user_default("Company") - } - ] + default: frappe.defaults.get_user_default("Company"), + }, + ], }; diff --git a/erpnext/stock/doctype/batch/batch.js b/erpnext/stock/doctype/batch/batch.js index 38d3d1cc3764..fc160fa3b650 100644 --- a/erpnext/stock/doctype/batch/batch.js +++ b/erpnext/stock/doctype/batch/batch.js @@ -1,62 +1,72 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -frappe.ui.form.on('Batch', { +frappe.ui.form.on("Batch", { setup: (frm) => { - frm.fields_dict['item'].get_query = function(doc, cdt, cdn) { + frm.fields_dict["item"].get_query = function (doc, cdt, cdn) { return { query: "erpnext.controllers.queries.item_query", - filters:{ - 'is_stock_item': 1, - 'has_batch_no': 1 - } - } - } + filters: { + is_stock_item: 1, + has_batch_no: 1, + }, + }; + }; }, refresh: (frm) => { - if(!frm.is_new()) { + if (!frm.is_new()) { frm.add_custom_button(__("View Ledger"), () => { frappe.route_options = { - batch_no: frm.doc.name + batch_no: frm.doc.name, }; frappe.set_route("query-report", "Stock Ledger"); }); - frm.trigger('make_dashboard'); + frm.trigger("make_dashboard"); } }, item: (frm) => { // frappe.db.get_value('Item', {name: frm.doc.item}, 'has_expiry_date', (r) => { // frm.toggle_reqd('expiry_date', r.has_expiry_date); // }); - frappe.db.get_value('Item', {name: frm.doc.item}, ['shelf_life_in_days', 'has_expiry_date'], (r) => { - if (r.has_expiry_date && r.shelf_life_in_days) { - // Calculate expiry date based on shelf_life_in_days - frm.set_value('expiry_date', frappe.datetime.add_days(frm.doc.manufacturing_date, r.shelf_life_in_days)); - }else if(r.has_expiry_date){ - frm.toggle_reqd('expiry_date', r.has_expiry_date); + frappe.db.get_value( + "Item", + { name: frm.doc.item }, + ["shelf_life_in_days", "has_expiry_date"], + (r) => { + if (r.has_expiry_date && r.shelf_life_in_days) { + // Calculate expiry date based on shelf_life_in_days + frm.set_value( + "expiry_date", + frappe.datetime.add_days(frm.doc.manufacturing_date, r.shelf_life_in_days) + ); + } else if (r.has_expiry_date) { + frm.toggle_reqd("expiry_date", r.has_expiry_date); + } } - }) + ); }, make_dashboard: (frm) => { - if(!frm.is_new()) { + if (!frm.is_new()) { frappe.call({ - method: 'erpnext.stock.doctype.batch.batch.get_batch_qty', - args: {batch_no: frm.doc.name}, + method: "erpnext.stock.doctype.batch.batch.get_batch_qty", + args: { batch_no: frm.doc.name }, callback: (r) => { - if(!r.message) { + if (!r.message) { return; } - const section = frm.dashboard.add_section('', __("Stock Levels")); + const section = frm.dashboard.add_section("", __("Stock Levels")); // sort by qty - r.message.sort(function(a, b) { a.qty > b.qty ? 1 : -1 }); + r.message.sort(function (a, b) { + a.qty > b.qty ? 1 : -1; + }); - const rows = $('
              ').appendTo(section); + const rows = $("
              ").appendTo(section); // show - (r.message || []).forEach(function(d) { - if(d.qty > 0) { + (r.message || []).forEach(function (d) { + if (d.qty > 0) { $(`
              ${d.warehouse}
              ${d.qty}
              @@ -64,98 +74,110 @@ frappe.ui.form.on('Batch', { + ${__("Move")} + ${__("Split")}
              `).appendTo(rows); } }); // move - ask for target warehouse and make stock entry - rows.find('.btn-move').on('click', function() { + rows.find(".btn-move").on("click", function () { const $btn = $(this); const fields = [ { - fieldname: 'to_warehouse', - label: __('To Warehouse'), - fieldtype: 'Link', - options: 'Warehouse' - } + fieldname: "to_warehouse", + label: __("To Warehouse"), + fieldtype: "Link", + options: "Warehouse", + }, ]; frappe.prompt( fields, (data) => { frappe.call({ - method: 'erpnext.stock.doctype.stock_entry.stock_entry_utils.make_stock_entry', + method: "erpnext.stock.doctype.stock_entry.stock_entry_utils.make_stock_entry", args: { item_code: frm.doc.item, batch_no: frm.doc.name, - qty: $btn.attr('data-qty'), - from_warehouse: $btn.attr('data-warehouse'), + qty: $btn.attr("data-qty"), + from_warehouse: $btn.attr("data-warehouse"), to_warehouse: data.to_warehouse, source_document: frm.doc.reference_name, - reference_doctype: frm.doc.reference_doctype + reference_doctype: frm.doc.reference_doctype, }, callback: (r) => { - frappe.show_alert(__('Stock Entry {0} created', - ['' + r.message.name+ ''])); + frappe.show_alert( + __("Stock Entry {0} created", [ + '' + + r.message.name + + "", + ]) + ); frm.refresh(); }, }); }, - __('Select Target Warehouse'), - __('Move') + __("Select Target Warehouse"), + __("Move") ); }); // split - ask for new qty and batch ID (optional) // and make stock entry via batch.batch_split - rows.find('.btn-split').on('click', function() { + rows.find(".btn-split").on("click", function () { const $btn = $(this); - frappe.prompt([{ - fieldname: 'qty', - label: __('New Batch Qty'), - fieldtype: 'Float', - 'default': $btn.attr('data-qty') - }, - { - fieldname: 'new_batch_id', - label: __('New Batch ID (Optional)'), - fieldtype: 'Data', - }], - (data) => { - frappe.xcall( - 'erpnext.stock.doctype.batch.batch.split_batch', + frappe.prompt( + [ + { + fieldname: "qty", + label: __("New Batch Qty"), + fieldtype: "Float", + default: $btn.attr("data-qty"), + }, { - item_code: frm.doc.item, - batch_no: frm.doc.name, - qty: data.qty, - warehouse: $btn.attr('data-warehouse'), - new_batch_id: data.new_batch_id - } - ).then(() => frm.reload_doc()); - }, - __('Split Batch'), - __('Split') + fieldname: "new_batch_id", + label: __("New Batch ID (Optional)"), + fieldtype: "Data", + }, + ], + (data) => { + frappe + .xcall("erpnext.stock.doctype.batch.batch.split_batch", { + item_code: frm.doc.item, + batch_no: frm.doc.name, + qty: data.qty, + warehouse: $btn.attr("data-warehouse"), + new_batch_id: data.new_batch_id, + }) + .then(() => frm.reload_doc()); + }, + __("Split Batch"), + __("Split") ); - }) + }); frm.dashboard.show(); - } + }, }); } - } -}) + }, +}); -frappe.ui.form.on('Batch', 'manufacturing_date', function (frm){ - frappe.db.get_value('Item', {name: frm.doc.item}, ['shelf_life_in_days', 'has_expiry_date'], (r) => { +frappe.ui.form.on("Batch", "manufacturing_date", function (frm) { + frappe.db.get_value("Item", { name: frm.doc.item }, ["shelf_life_in_days", "has_expiry_date"], (r) => { if (r.has_expiry_date && r.shelf_life_in_days) { // Calculate expiry date based on shelf_life_in_days - frm.set_value('expiry_date', frappe.datetime.add_days(frm.doc.manufacturing_date, r.shelf_life_in_days)); + frm.set_value( + "expiry_date", + frappe.datetime.add_days(frm.doc.manufacturing_date, r.shelf_life_in_days) + ); } - }) -}) + }); +}); diff --git a/erpnext/stock/doctype/batch/batch_list.js b/erpnext/stock/doctype/batch/batch_list.js index 0de9fd01503a..2060d6e87632 100644 --- a/erpnext/stock/doctype/batch/batch_list.js +++ b/erpnext/stock/doctype/batch/batch_list.js @@ -1,14 +1,21 @@ -frappe.listview_settings['Batch'] = { +frappe.listview_settings["Batch"] = { add_fields: ["item", "expiry_date", "batch_qty", "disabled"], get_indicator: (doc) => { if (doc.disabled) { return [__("Disabled"), "gray", "disabled,=,1"]; } else if (!doc.batch_qty) { return [__("Empty"), "gray", "batch_qty,=,0|disabled,=,0"]; - } else if (doc.expiry_date && frappe.datetime.get_diff(doc.expiry_date, frappe.datetime.nowdate()) <= 0) { - return [__("Expired"), "red", "expiry_date,not in,|expiry_date,<=,Today|batch_qty,>,0|disabled,=,0"] + } else if ( + doc.expiry_date && + frappe.datetime.get_diff(doc.expiry_date, frappe.datetime.nowdate()) <= 0 + ) { + return [ + __("Expired"), + "red", + "expiry_date,not in,|expiry_date,<=,Today|batch_qty,>,0|disabled,=,0", + ]; } else { return [__("Active"), "green", "batch_qty,>,0|disabled,=,0"]; - }; - } + } + }, }; diff --git a/erpnext/stock/doctype/bin/bin.js b/erpnext/stock/doctype/bin/bin.js index 40411b68b484..02ff8b623960 100644 --- a/erpnext/stock/doctype/bin/bin.js +++ b/erpnext/stock/doctype/bin/bin.js @@ -1,8 +1,6 @@ // Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Bin', { - refresh: function(frm) { - - } +frappe.ui.form.on("Bin", { + refresh: function (frm) {}, }); diff --git a/erpnext/stock/doctype/closing_stock_balance/closing_stock_balance.js b/erpnext/stock/doctype/closing_stock_balance/closing_stock_balance.js index 5c807a80a040..0f0221fa5623 100644 --- a/erpnext/stock/doctype/closing_stock_balance/closing_stock_balance.js +++ b/erpnext/stock/doctype/closing_stock_balance/closing_stock_balance.js @@ -16,9 +16,9 @@ frappe.ui.form.on("Closing Stock Balance", { freeze: true, callback: () => { frm.reload_doc(); - } - }) - }) + }, + }); + }); } }, @@ -31,9 +31,9 @@ frappe.ui.form.on("Closing Stock Balance", { freeze: true, callback: () => { frm.reload_doc(); - } - }) - }) + }, + }); + }); } - } + }, }); diff --git a/erpnext/stock/doctype/customs_tariff_number/customs_tariff_number.js b/erpnext/stock/doctype/customs_tariff_number/customs_tariff_number.js index a39414c8363c..bb60ee7e3685 100644 --- a/erpnext/stock/doctype/customs_tariff_number/customs_tariff_number.js +++ b/erpnext/stock/doctype/customs_tariff_number/customs_tariff_number.js @@ -1,8 +1,6 @@ // Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Customs Tariff Number', { - refresh: function(frm) { - - } +frappe.ui.form.on("Customs Tariff Number", { + refresh: function (frm) {}, }); diff --git a/erpnext/stock/doctype/delivery_note/delivery_note_list.js b/erpnext/stock/doctype/delivery_note/delivery_note_list.js index 6ff3ed3e8e5a..c6b98c4134c6 100644 --- a/erpnext/stock/doctype/delivery_note/delivery_note_list.js +++ b/erpnext/stock/doctype/delivery_note/delivery_note_list.js @@ -1,8 +1,18 @@ -frappe.listview_settings['Delivery Note'] = { - add_fields: ["customer", "customer_name", "base_grand_total", "per_installed", "per_billed", - "transporter_name", "grand_total", "is_return", "status", "currency"], - get_indicator: function(doc) { - if(cint(doc.is_return)==1) { +frappe.listview_settings["Delivery Note"] = { + add_fields: [ + "customer", + "customer_name", + "base_grand_total", + "per_installed", + "per_billed", + "transporter_name", + "grand_total", + "is_return", + "status", + "currency", + ], + get_indicator: function (doc) { + if (cint(doc.is_return) == 1) { return [__("Return"), "gray", "is_return,=,Yes"]; } else if (doc.status === "Closed") { return [__("Closed"), "green", "status,=,Closed"]; @@ -24,46 +34,45 @@ frappe.listview_settings['Delivery Note'] = { if (!doc.docstatus) { frappe.throw(__("Cannot create a Delivery Trip from Draft documents.")); } - }; + } - frappe.new_doc("Delivery Trip") - .then(() => { - // Empty out the child table before inserting new ones - cur_frm.set_value("delivery_stops", []); + frappe.new_doc("Delivery Trip").then(() => { + // Empty out the child table before inserting new ones + cur_frm.set_value("delivery_stops", []); - // We don't want to use `map_current_doc` since it brings up - // the dialog to select more items. We just want the mapper - // function to be called. - frappe.call({ - type: "POST", - method: "frappe.model.mapper.map_docs", - args: { - "method": "erpnext.stock.doctype.delivery_note.delivery_note.make_delivery_trip", - "source_names": docnames, - "target_doc": cur_frm.doc - }, - callback: function (r) { - if (!r.exc) { - frappe.model.sync(r.message); - cur_frm.dirty(); - cur_frm.refresh(); - } + // We don't want to use `map_current_doc` since it brings up + // the dialog to select more items. We just want the mapper + // function to be called. + frappe.call({ + type: "POST", + method: "frappe.model.mapper.map_docs", + args: { + method: "erpnext.stock.doctype.delivery_note.delivery_note.make_delivery_trip", + source_names: docnames, + target_doc: cur_frm.doc, + }, + callback: function (r) { + if (!r.exc) { + frappe.model.sync(r.message); + cur_frm.dirty(); + cur_frm.refresh(); } - }); - }) - }; + }, + }); + }); + } }; // doclist.page.add_actions_menu_item(__('Create Delivery Trip'), action, false); - doclist.page.add_action_item(__('Create Delivery Trip'), action); + doclist.page.add_action_item(__("Create Delivery Trip"), action); - doclist.page.add_action_item(__("Sales Invoice"), ()=>{ + doclist.page.add_action_item(__("Sales Invoice"), () => { erpnext.bulk_transaction_processing.create(doclist, "Delivery Note", "Sales Invoice"); }); - doclist.page.add_action_item(__("Packaging Slip From Delivery Note"), ()=>{ + doclist.page.add_action_item(__("Packaging Slip From Delivery Note"), () => { erpnext.bulk_transaction_processing.create(doclist, "Delivery Note", "Packing Slip"); }); - } + }, }; diff --git a/erpnext/stock/doctype/delivery_settings/delivery_settings.js b/erpnext/stock/doctype/delivery_settings/delivery_settings.js index 03aa1922ff53..4328158e6d90 100644 --- a/erpnext/stock/doctype/delivery_settings/delivery_settings.js +++ b/erpnext/stock/doctype/delivery_settings/delivery_settings.js @@ -1,8 +1,6 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Delivery Settings', { - refresh: function(frm) { - - } +frappe.ui.form.on("Delivery Settings", { + refresh: function (frm) {}, }); diff --git a/erpnext/stock/doctype/delivery_trip/delivery_trip.js b/erpnext/stock/doctype/delivery_trip/delivery_trip.js index 4ba5b32ca62c..4f8649c0bfa2 100755 --- a/erpnext/stock/doctype/delivery_trip/delivery_trip.js +++ b/erpnext/stock/doctype/delivery_trip/delivery_trip.js @@ -1,15 +1,15 @@ // Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Delivery Trip', { +frappe.ui.form.on("Delivery Trip", { setup: function (frm) { - frm.set_indicator_formatter('customer', (stop) => (stop.visited) ? "green" : "orange"); + frm.set_indicator_formatter("customer", (stop) => (stop.visited ? "green" : "orange")); frm.set_query("driver", function () { return { filters: { - "status": "Active" - } + status: "Active", + }, }; }); @@ -17,58 +17,71 @@ frappe.ui.form.on('Delivery Trip', { var row = locals[cdt][cdn]; if (row.customer) { return { - query: 'frappe.contacts.doctype.address.address.address_query', + query: "frappe.contacts.doctype.address.address.address_query", filters: { link_doctype: "Customer", - link_name: row.customer - } + link_name: row.customer, + }, }; } - }) + }); frm.set_query("contact", "delivery_stops", function (doc, cdt, cdn) { var row = locals[cdt][cdn]; if (row.customer) { return { - query: 'frappe.contacts.doctype.contact.contact.contact_query', + query: "frappe.contacts.doctype.contact.contact.contact_query", filters: { link_doctype: "Customer", - link_name: row.customer - } + link_name: row.customer, + }, }; } - }) + }); }, refresh: function (frm) { if (frm.doc.docstatus == 1 && frm.doc.delivery_stops.length > 0) { frm.add_custom_button(__("Notify Customers via Email"), function () { - frm.trigger('notify_customers'); + frm.trigger("notify_customers"); }); } if (frm.doc.docstatus === 0) { - frm.add_custom_button(__('Delivery Note'), () => { - erpnext.utils.map_current_doc({ - method: "erpnext.stock.doctype.delivery_note.delivery_note.make_delivery_trip", - source_doctype: "Delivery Note", - target: frm, - date_field: "posting_date", - setters: { - company: frm.doc.company, - }, - get_query_filters: { - docstatus: 1, - company: frm.doc.company, - } - }) - }, __("Get stops from")); - } - frm.add_custom_button(__("Delivery Notes"), function () { - frappe.set_route("List", "Delivery Note", - {'name': ["in", frm.doc.delivery_stops.map((stop) => {return stop.delivery_note;})]} + frm.add_custom_button( + __("Delivery Note"), + () => { + erpnext.utils.map_current_doc({ + method: "erpnext.stock.doctype.delivery_note.delivery_note.make_delivery_trip", + source_doctype: "Delivery Note", + target: frm, + date_field: "posting_date", + setters: { + company: frm.doc.company, + }, + get_query_filters: { + docstatus: 1, + company: frm.doc.company, + }, + }); + }, + __("Get stops from") ); - }, __("View")); + } + frm.add_custom_button( + __("Delivery Notes"), + function () { + frappe.set_route("List", "Delivery Note", { + name: [ + "in", + frm.doc.delivery_stops.map((stop) => { + return stop.delivery_note; + }), + ], + }); + }, + __("View") + ); }, calculate_arrival_time: function (frm) { @@ -77,13 +90,17 @@ frappe.ui.form.on('Delivery Trip', { } frappe.show_alert({ message: "Calculating Arrival Times", - indicator: 'orange' - }); - frm.call("process_route", { - optimize: false, - }, () => { - frm.reload_doc(); + indicator: "orange", }); + frm.call( + "process_route", + { + optimize: false, + }, + () => { + frm.reload_doc(); + } + ); }, driver: function (frm) { @@ -91,13 +108,13 @@ frappe.ui.form.on('Delivery Trip', { frappe.call({ method: "erpnext.stock.doctype.delivery_trip.delivery_trip.get_driver_email", args: { - driver: frm.doc.driver + driver: frm.doc.driver, }, callback: (data) => { frm.set_value("driver_email", data.message.email); - } + }, }); - }; + } }, optimize_route: function (frm) { @@ -106,23 +123,27 @@ frappe.ui.form.on('Delivery Trip', { } frappe.show_alert({ message: "Optimizing Route", - indicator: 'orange' - }); - frm.call("process_route", { - optimize: true, - }, () => { - frm.reload_doc(); + indicator: "orange", }); + frm.call( + "process_route", + { + optimize: true, + }, + () => { + frm.reload_doc(); + } + ); }, notify_customers: function (frm) { $.each(frm.doc.delivery_stops || [], function (i, delivery_stop) { if (!delivery_stop.delivery_note) { frappe.msgprint({ - "message": __("No Delivery Note selected for Customer {}", [delivery_stop.customer]), - "title": __("Warning"), - "indicator": "orange", - "alert": 1 + message: __("No Delivery Note selected for Customer {}", [delivery_stop.customer]), + title: __("Warning"), + indicator: "orange", + alert: 1, }); } }); @@ -135,48 +156,45 @@ frappe.ui.form.on('Delivery Trip', { frappe.call({ method: "erpnext.stock.doctype.delivery_trip.delivery_trip.notify_customers", args: { - "delivery_trip": frm.doc.name + delivery_trip: frm.doc.name, }, callback: function (r) { if (!r.exc) { frm.doc.email_notification_sent = true; - frm.refresh_field('email_notification_sent'); + frm.refresh_field("email_notification_sent"); } - } + }, }); }); } }); - } + }, }); -frappe.ui.form.on('Delivery Stop', { +frappe.ui.form.on("Delivery Stop", { customer: function (frm, cdt, cdn) { var row = locals[cdt][cdn]; if (row.customer) { frappe.call({ method: "erpnext.stock.doctype.delivery_trip.delivery_trip.get_contact_and_address", - args: { "name": row.customer }, + args: { name: row.customer }, callback: function (r) { if (r.message) { if (r.message["shipping_address"]) { frappe.model.set_value(cdt, cdn, "address", r.message["shipping_address"].parent); - } - else { - frappe.model.set_value(cdt, cdn, "address", ''); + } else { + frappe.model.set_value(cdt, cdn, "address", ""); } if (r.message["contact_person"]) { frappe.model.set_value(cdt, cdn, "contact", r.message["contact_person"].parent); + } else { + frappe.model.set_value(cdt, cdn, "contact", ""); } - else { - frappe.model.set_value(cdt, cdn, "contact", ''); - } - } - else { - frappe.model.set_value(cdt, cdn, "address", ''); - frappe.model.set_value(cdt, cdn, "contact", ''); + } else { + frappe.model.set_value(cdt, cdn, "address", ""); + frappe.model.set_value(cdt, cdn, "contact", ""); } - } + }, }); } }, @@ -186,12 +204,12 @@ frappe.ui.form.on('Delivery Stop', { if (row.address) { frappe.call({ method: "frappe.contacts.doctype.address.address.get_address_display", - args: { "address_dict": row.address }, + args: { address_dict: row.address }, callback: function (r) { if (r.message) { frappe.model.set_value(cdt, cdn, "customer_address", r.message); } - } + }, }); } else { frappe.model.set_value(cdt, cdn, "customer_address", ""); @@ -203,15 +221,15 @@ frappe.ui.form.on('Delivery Stop', { if (row.contact) { frappe.call({ method: "erpnext.stock.doctype.delivery_trip.delivery_trip.get_contact_display", - args: { "contact": row.contact }, + args: { contact: row.contact }, callback: function (r) { if (r.message) { frappe.model.set_value(cdt, cdn, "customer_contact", r.message); } - } + }, }); } else { frappe.model.set_value(cdt, cdn, "customer_contact", ""); } - } + }, }); diff --git a/erpnext/stock/doctype/delivery_trip/delivery_trip_list.js b/erpnext/stock/doctype/delivery_trip/delivery_trip_list.js index 1d198b733fbb..230107caadbb 100644 --- a/erpnext/stock/doctype/delivery_trip/delivery_trip_list.js +++ b/erpnext/stock/doctype/delivery_trip/delivery_trip_list.js @@ -1,4 +1,4 @@ -frappe.listview_settings['Delivery Trip'] = { +frappe.listview_settings["Delivery Trip"] = { add_fields: ["status"], get_indicator: function (doc) { if (in_list(["Cancelled", "Draft"], doc.status)) { @@ -8,5 +8,5 @@ frappe.listview_settings['Delivery Trip'] = { } else if (doc.status === "Completed") { return [__(doc.status), "green", "status,=," + doc.status]; } - } + }, }; diff --git a/erpnext/stock/doctype/inventory_dimension/inventory_dimension.js b/erpnext/stock/doctype/inventory_dimension/inventory_dimension.js index 35d1c02719cc..c819d17b1e7e 100644 --- a/erpnext/stock/doctype/inventory_dimension/inventory_dimension.js +++ b/erpnext/stock/doctype/inventory_dimension/inventory_dimension.js @@ -1,43 +1,59 @@ // Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Inventory Dimension', { +frappe.ui.form.on("Inventory Dimension", { setup(frm) { - frm.trigger('set_query_on_fields'); + frm.trigger("set_query_on_fields"); }, set_query_on_fields(frm) { - frm.set_query('reference_document', () => { + frm.set_query("reference_document", () => { let invalid_doctypes = frappe.model.core_doctypes_list; - invalid_doctypes.push('Batch', 'Serial No', 'Warehouse', 'Item', 'Inventory Dimension', - 'Accounting Dimension', 'Accounting Dimension Filter'); + invalid_doctypes.push( + "Batch", + "Serial No", + "Warehouse", + "Item", + "Inventory Dimension", + "Accounting Dimension", + "Accounting Dimension Filter" + ); return { filters: { - 'istable': 0, - 'issingle': 0, - 'name': ['not in', invalid_doctypes] - } + istable: 0, + issingle: 0, + name: ["not in", invalid_doctypes], + }, }; }); - frm.set_query('document_type', () => { + frm.set_query("document_type", () => { return { - query: 'erpnext.stock.doctype.inventory_dimension.inventory_dimension.get_inventory_documents', + query: "erpnext.stock.doctype.inventory_dimension.inventory_dimension.get_inventory_documents", }; }); }, onload(frm) { - frm.trigger('render_traget_field'); + frm.trigger("render_traget_field"); frm.trigger("set_parent_fields"); }, refresh(frm) { - if (frm.doc.__onload && frm.doc.__onload.has_stock_ledger - && frm.doc.__onload.has_stock_ledger.length) { - let allow_to_edit_fields = ['disabled', 'fetch_from_parent', - 'type_of_transaction', 'condition', 'mandatory_depends_on', 'validate_negative_stock']; + if ( + frm.doc.__onload && + frm.doc.__onload.has_stock_ledger && + frm.doc.__onload.has_stock_ledger.length + ) { + let allow_to_edit_fields = [ + "disabled", + "fetch_from_parent", + "type_of_transaction", + "condition", + "mandatory_depends_on", + "validate_negative_stock", + ]; frm.fields.forEach((field) => { if (!in_list(allow_to_edit_fields, field.df.fieldname)) { @@ -47,8 +63,8 @@ frappe.ui.form.on('Inventory Dimension', { } if (!frm.is_new()) { - frm.add_custom_button(__('Delete Dimension'), () => { - frm.trigger('delete_dimension'); + frm.add_custom_button(__("Delete Dimension"), () => { + frm.trigger("delete_dimension"); }); } }, @@ -62,39 +78,38 @@ frappe.ui.form.on('Inventory Dimension', { frm.set_df_property("fetch_from_parent", "options", frm.doc.reference_document); } else if (frm.doc.document_type && frm.doc.istable) { frappe.call({ - method: 'erpnext.stock.doctype.inventory_dimension.inventory_dimension.get_parent_fields', + method: "erpnext.stock.doctype.inventory_dimension.inventory_dimension.get_parent_fields", args: { child_doctype: frm.doc.document_type, - dimension_name: frm.doc.reference_document + dimension_name: frm.doc.reference_document, }, callback: (r) => { if (r.message && r.message.length) { - frm.set_df_property("fetch_from_parent", "options", - [""].concat(r.message)); + frm.set_df_property("fetch_from_parent", "options", [""].concat(r.message)); } else { frm.set_df_property("fetch_from_parent", "hidden", 1); } - } + }, }); } }, delete_dimension(frm) { - let msg = (` + let msg = ` Custom fields related to this dimension will be deleted on deletion of dimension.
              Do you want to delete {0} dimension? - `); + `; frappe.confirm(__(msg, [frm.doc.name.bold()]), () => { frappe.call({ - method: 'erpnext.stock.doctype.inventory_dimension.inventory_dimension.delete_dimension', + method: "erpnext.stock.doctype.inventory_dimension.inventory_dimension.delete_dimension", args: { - dimension: frm.doc.name + dimension: frm.doc.name, + }, + callback: function () { + frappe.set_route("List", "Inventory Dimension"); }, - callback: function() { - frappe.set_route('List', 'Inventory Dimension'); - } }); }); - } + }, }); diff --git a/erpnext/stock/doctype/item/item.js b/erpnext/stock/doctype/item/item.js index 1b71017bd4d2..29d41fe76251 100644 --- a/erpnext/stock/doctype/item/item.js +++ b/erpnext/stock/doctype/item/item.js @@ -3,48 +3,47 @@ frappe.provide("erpnext.item"); -const SALES_DOCTYPES = ['Quotation', 'Sales Order', 'Delivery Note', 'Sales Invoice']; -const PURCHASE_DOCTYPES = ['Purchase Order', 'Purchase Receipt', 'Purchase Invoice']; +const SALES_DOCTYPES = ["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"]; +const PURCHASE_DOCTYPES = ["Purchase Order", "Purchase Receipt", "Purchase Invoice"]; frappe.ui.form.on("Item", { - setup: function(frm) { - frm.add_fetch('attribute', 'numeric_values', 'numeric_values'); - frm.add_fetch('attribute', 'from_range', 'from_range'); - frm.add_fetch('attribute', 'to_range', 'to_range'); - frm.add_fetch('attribute', 'increment', 'increment'); - frm.add_fetch('tax_type', 'tax_rate', 'tax_rate'); + setup: function (frm) { + frm.add_fetch("attribute", "numeric_values", "numeric_values"); + frm.add_fetch("attribute", "from_range", "from_range"); + frm.add_fetch("attribute", "to_range", "to_range"); + frm.add_fetch("attribute", "increment", "increment"); + frm.add_fetch("tax_type", "tax_rate", "tax_rate"); frm.make_methods = { - 'Sales Order': () => { + "Sales Order": () => { open_form(frm, "Sales Order", "Sales Order Item", "items"); }, - 'Delivery Note': () => { + "Delivery Note": () => { open_form(frm, "Delivery Note", "Delivery Note Item", "items"); }, - 'Sales Invoice': () => { + "Sales Invoice": () => { open_form(frm, "Sales Invoice", "Sales Invoice Item", "items"); }, - 'Purchase Order': () => { + "Purchase Order": () => { open_form(frm, "Purchase Order", "Purchase Order Item", "items"); }, - 'Purchase Receipt': () => { + "Purchase Receipt": () => { open_form(frm, "Purchase Receipt", "Purchase Receipt Item", "items"); }, - 'Purchase Invoice': () => { + "Purchase Invoice": () => { open_form(frm, "Purchase Invoice", "Purchase Invoice Item", "items"); }, - 'Material Request': () => { + "Material Request": () => { open_form(frm, "Material Request", "Material Request Item", "items"); }, - 'Stock Entry': () => { + "Stock Entry": () => { open_form(frm, "Stock Entry", "Stock Entry Detail", "items"); }, }; - }, - onload: function(frm) { + onload: function (frm) { erpnext.item.setup_queries(frm); - if (frm.doc.variant_of){ + if (frm.doc.variant_of) { frm.fields_dict["attributes"].grid.set_column_disp("attribute_value", true); } @@ -53,106 +52,161 @@ frappe.ui.form.on("Item", { } }, - refresh: function(frm) { + refresh: function (frm) { if (frm.doc.is_stock_item) { - frm.add_custom_button(__("Stock Balance"), function() { - frappe.route_options = { - "item_code": frm.doc.name - } - frappe.set_route("query-report", "Stock Balance"); - }, __("View")); - frm.add_custom_button(__("Stock Ledger"), function() { - frappe.route_options = { - "item_code": frm.doc.name - } - frappe.set_route("query-report", "Stock Ledger"); - }, __("View")); - frm.add_custom_button(__("Stock Projected Qty"), function() { - frappe.route_options = { - "item_code": frm.doc.name - } - frappe.set_route("query-report", "Stock Projected Qty"); - }, __("View")); + frm.add_custom_button( + __("Stock Balance"), + function () { + frappe.route_options = { + item_code: frm.doc.name, + }; + frappe.set_route("query-report", "Stock Balance"); + }, + __("View") + ); + frm.add_custom_button( + __("Stock Ledger"), + function () { + frappe.route_options = { + item_code: frm.doc.name, + }; + frappe.set_route("query-report", "Stock Ledger"); + }, + __("View") + ); + frm.add_custom_button( + __("Stock Projected Qty"), + function () { + frappe.route_options = { + item_code: frm.doc.name, + }; + frappe.set_route("query-report", "Stock Projected Qty"); + }, + __("View") + ); } - if (frm.doc.is_fixed_asset) { - frm.trigger('is_fixed_asset'); - frm.trigger('auto_create_assets'); + frm.trigger("is_fixed_asset"); + frm.trigger("auto_create_assets"); } // clear intro frm.set_intro(); if (frm.doc.has_variants) { - frm.set_intro(__("This Item is a Template and cannot be used in transactions. Item attributes will be copied over into the variants unless 'No Copy' is set"), true); - - frm.add_custom_button(__("Show Variants"), function() { - frappe.set_route("List", "Item", {"variant_of": frm.doc.name}); - }, __("View")); - - frm.add_custom_button(__("Item Variant Settings"), function() { - frappe.set_route("Form", "Item Variant Settings"); - }, __("View")); - - frm.add_custom_button(__("Variant Details Report"), function() { - frappe.set_route("query-report", "Item Variant Details", {"item": frm.doc.name}); - }, __("View")); - - if(frm.doc.variant_based_on==="Item Attribute") { - frm.add_custom_button(__("Single Variant"), function() { - erpnext.item.show_single_variant_dialog(frm); - }, __('Create')); - frm.add_custom_button(__("Multiple Variants"), function() { - erpnext.item.show_multiple_variants_dialog(frm); - }, __('Create')); + frm.set_intro( + __( + "This Item is a Template and cannot be used in transactions. Item attributes will be copied over into the variants unless 'No Copy' is set" + ), + true + ); + + frm.add_custom_button( + __("Show Variants"), + function () { + frappe.set_route("List", "Item", { variant_of: frm.doc.name }); + }, + __("View") + ); + + frm.add_custom_button( + __("Item Variant Settings"), + function () { + frappe.set_route("Form", "Item Variant Settings"); + }, + __("View") + ); + + frm.add_custom_button( + __("Variant Details Report"), + function () { + frappe.set_route("query-report", "Item Variant Details", { item: frm.doc.name }); + }, + __("View") + ); + + if (frm.doc.variant_based_on === "Item Attribute") { + frm.add_custom_button( + __("Single Variant"), + function () { + erpnext.item.show_single_variant_dialog(frm); + }, + __("Create") + ); + frm.add_custom_button( + __("Multiple Variants"), + function () { + erpnext.item.show_multiple_variants_dialog(frm); + }, + __("Create") + ); } else { - frm.add_custom_button(__("Variant"), function() { - erpnext.item.show_modal_for_manufacturers(frm); - }, __('Create')); + frm.add_custom_button( + __("Variant"), + function () { + erpnext.item.show_modal_for_manufacturers(frm); + }, + __("Create") + ); } // frm.page.set_inner_btn_group_as_primary(__('Create')); } if (frm.doc.variant_of) { - frm.set_intro(__('This Item is a Variant of {0} (Template).', - [`${frm.doc.variant_of}`]), true); + frm.set_intro( + __("This Item is a Variant of {0} (Template).", [ + `${frm.doc.variant_of}`, + ]), + true + ); } - if (frappe.defaults.get_default("item_naming_by")!="Naming Series" || frm.doc.variant_of) { + if (frappe.defaults.get_default("item_naming_by") != "Naming Series" || frm.doc.variant_of) { frm.toggle_display("naming_series", false); } else { erpnext.toggle_naming_series(); } if (!frm.doc.published_in_website) { - frm.add_custom_button(__("Publish in Website"), function() { - frappe.call({ - method: "erpnext.e_commerce.doctype.website_item.website_item.make_website_item", - args: {doc: frm.doc}, - freeze: true, - freeze_message: __("Publishing Item ..."), - callback: function(result) { - frappe.msgprint({ - message: __("Website Item {0} has been created.", - [repl('%(item)s', { - item_encoded: encodeURIComponent(result.message[0]), - item: result.message[1] - })] - ), - title: __("Published"), - indicator: "green" - }); - } - }); - }, __('Actions')); + frm.add_custom_button( + __("Publish in Website"), + function () { + frappe.call({ + method: "erpnext.e_commerce.doctype.website_item.website_item.make_website_item", + args: { doc: frm.doc }, + freeze: true, + freeze_message: __("Publishing Item ..."), + callback: function (result) { + frappe.msgprint({ + message: __("Website Item {0} has been created.", [ + repl( + '%(item)s', + { + item_encoded: encodeURIComponent(result.message[0]), + item: result.message[1], + } + ), + ]), + title: __("Published"), + indicator: "green", + }); + }, + }); + }, + __("Actions") + ); } else { - frm.add_custom_button(__("Website Item"), function() { - frappe.db.get_value("Website Item", {item_code: frm.doc.name}, "name", (d) => { - if (!d.name) frappe.throw(__("Website Item not found")); - frappe.set_route("Form", "Website Item", d.name); - }); - }, __("View")); + frm.add_custom_button( + __("Website Item"), + function () { + frappe.db.get_value("Website Item", { item_code: frm.doc.name }, "name", (d) => { + if (!d.name) frappe.throw(__("Website Item not found")); + frappe.set_route("Form", "Website Item", d.name); + }); + }, + __("View") + ); } erpnext.item.edit_prices_button(frm); @@ -162,341 +216,374 @@ frappe.ui.form.on("Item", { erpnext.item.make_dashboard(frm); } - frm.add_custom_button(__('Duplicate'), function() { + frm.add_custom_button(__("Duplicate"), function () { var new_item = frappe.model.copy_doc(frm.doc); // Duplicate item could have different name, causing "copy paste" error. - if (new_item.item_name===new_item.item_code) { + if (new_item.item_name === new_item.item_code) { new_item.item_name = null; } - if (new_item.item_code===new_item.description || new_item.item_code===new_item.description) { + if (new_item.item_code === new_item.description || new_item.item_code === new_item.description) { new_item.description = null; } - frappe.set_route('Form', 'Item', new_item.name); + frappe.set_route("Form", "Item", new_item.name); }); - const stock_exists = (frm.doc.__onload - && frm.doc.__onload.stock_exists) ? 1 : 0; + const stock_exists = frm.doc.__onload && frm.doc.__onload.stock_exists ? 1 : 0; - ['is_stock_item', 'has_serial_no', 'has_batch_no', 'has_variants'].forEach((fieldname) => { - frm.set_df_property(fieldname, 'read_only', stock_exists); + ["is_stock_item", "has_serial_no", "has_batch_no", "has_variants"].forEach((fieldname) => { + frm.set_df_property(fieldname, "read_only", stock_exists); }); - frm.toggle_reqd('customer', frm.doc.is_customer_provided_item ? 1:0); + frm.toggle_reqd("customer", frm.doc.is_customer_provided_item ? 1 : 0); }, - validate: function(frm){ + validate: function (frm) { erpnext.item.weight_to_validate(frm); }, - image: function() { + image: function () { refresh_field("image_view"); }, - is_customer_provided_item: function(frm) { - frm.toggle_reqd('customer', frm.doc.is_customer_provided_item ? 1:0); + is_customer_provided_item: function (frm) { + frm.toggle_reqd("customer", frm.doc.is_customer_provided_item ? 1 : 0); }, - is_fixed_asset: function(frm) { + is_fixed_asset: function (frm) { // set serial no to false & toggles its visibility - frm.set_value('has_serial_no', 0); - frm.set_value('has_batch_no', 0); - frm.toggle_enable(['has_serial_no', 'serial_no_series'], !frm.doc.is_fixed_asset); + frm.set_value("has_serial_no", 0); + frm.set_value("has_batch_no", 0); + frm.toggle_enable(["has_serial_no", "serial_no_series"], !frm.doc.is_fixed_asset); frappe.call({ method: "erpnext.stock.doctype.item.item.get_asset_naming_series", - callback: function(r) { + callback: function (r) { frm.set_value("is_stock_item", frm.doc.is_fixed_asset ? 0 : 1); frm.events.set_asset_naming_series(frm, r.message); - } + }, }); - frm.trigger('auto_create_assets'); + frm.trigger("auto_create_assets"); }, - set_asset_naming_series: function(frm, asset_naming_series) { + set_asset_naming_series: function (frm, asset_naming_series) { if ((frm.doc.__onload && frm.doc.__onload.asset_naming_series) || asset_naming_series) { - let naming_series = (frm.doc.__onload && frm.doc.__onload.asset_naming_series) || asset_naming_series; + let naming_series = + (frm.doc.__onload && frm.doc.__onload.asset_naming_series) || asset_naming_series; frm.set_df_property("asset_naming_series", "options", naming_series); } }, - auto_create_assets: function(frm) { - frm.toggle_reqd(['asset_naming_series'], frm.doc.auto_create_assets); - frm.toggle_display(['asset_naming_series'], frm.doc.auto_create_assets); + auto_create_assets: function (frm) { + frm.toggle_reqd(["asset_naming_series"], frm.doc.auto_create_assets); + frm.toggle_display(["asset_naming_series"], frm.doc.auto_create_assets); }, page_name: frappe.utils.warn_page_name_change, - item_code: function(frm) { - if(!frm.doc.item_name) - frm.set_value("item_name", frm.doc.item_code); + item_code: function (frm) { + if (!frm.doc.item_name) frm.set_value("item_name", frm.doc.item_code); }, - is_stock_item: function(frm) { - if(!frm.doc.is_stock_item) { + is_stock_item: function (frm) { + if (!frm.doc.is_stock_item) { frm.set_value("has_batch_no", 0); frm.set_value("create_new_batch", 0); frm.set_value("has_serial_no", 0); } }, - has_variants: function(frm) { + has_variants: function (frm) { erpnext.item.toggle_attributes(frm); - } + }, }); -frappe.ui.form.on('Item Reorder', { - reorder_levels_add: function(frm, cdt, cdn) { +frappe.ui.form.on("Item Reorder", { + reorder_levels_add: function (frm, cdt, cdn) { var row = frappe.get_doc(cdt, cdn); - var type = frm.doc.default_material_request_type - row.material_request_type = (type == 'Material Transfer')? 'Transfer' : type; - } -}) + var type = frm.doc.default_material_request_type; + row.material_request_type = type == "Material Transfer" ? "Transfer" : type; + }, +}); -frappe.ui.form.on('Item Customer Detail', { - customer_items_add: function(frm, cdt, cdn) { - frappe.model.set_value(cdt, cdn, 'customer_group', ""); +frappe.ui.form.on("Item Customer Detail", { + customer_items_add: function (frm, cdt, cdn) { + frappe.model.set_value(cdt, cdn, "customer_group", ""); }, - customer_name: function(frm, cdt, cdn) { + customer_name: function (frm, cdt, cdn) { set_customer_group(frm, cdt, cdn); }, - customer_group: function(frm, cdt, cdn) { - if(set_customer_group(frm, cdt, cdn)){ + customer_group: function (frm, cdt, cdn) { + if (set_customer_group(frm, cdt, cdn)) { frappe.msgprint(__("Changing Customer Group for the selected Customer is not allowed.")); } - } + }, }); -var set_customer_group = function(frm, cdt, cdn) { +var set_customer_group = function (frm, cdt, cdn) { var row = frappe.get_doc(cdt, cdn); if (!row.customer_name) { return false; } - frappe.model.with_doc("Customer", row.customer_name, function() { + frappe.model.with_doc("Customer", row.customer_name, function () { var customer = frappe.model.get_doc("Customer", row.customer_name); row.customer_group = customer.customer_group; refresh_field("customer_group", cdn, "customer_items"); }); return true; -} +}; $.extend(erpnext.item, { - setup_queries: function(frm) { - frm.fields_dict["item_defaults"].grid.get_field("expense_account").get_query = function(doc, cdt, cdn) { + setup_queries: function (frm) { + frm.fields_dict["item_defaults"].grid.get_field("expense_account").get_query = function ( + doc, + cdt, + cdn + ) { const row = locals[cdt][cdn]; return { query: "erpnext.controllers.queries.get_expense_account", - filters: { company: row.company } - } - } + filters: { company: row.company }, + }; + }; - frm.fields_dict["item_defaults"].grid.get_field("income_account").get_query = function(doc, cdt, cdn) { + frm.fields_dict["item_defaults"].grid.get_field("income_account").get_query = function ( + doc, + cdt, + cdn + ) { const row = locals[cdt][cdn]; return { query: "erpnext.controllers.queries.get_income_account", - filters: { company: row.company } - } - } + filters: { company: row.company }, + }; + }; - frm.fields_dict["item_defaults"].grid.get_field("default_discount_account").get_query = function(doc, cdt, cdn) { + frm.fields_dict["item_defaults"].grid.get_field("default_discount_account").get_query = function ( + doc, + cdt, + cdn + ) { const row = locals[cdt][cdn]; return { filters: { - 'report_type': 'Profit and Loss', - 'company': row.company, - "is_group": 0 - } + report_type: "Profit and Loss", + company: row.company, + is_group: 0, + }, }; }; - frm.fields_dict["item_defaults"].grid.get_field("buying_cost_center").get_query = function(doc, cdt, cdn) { + frm.fields_dict["item_defaults"].grid.get_field("buying_cost_center").get_query = function ( + doc, + cdt, + cdn + ) { const row = locals[cdt][cdn]; return { filters: { - "is_group": 0, - "company": row.company - } - } - } + is_group: 0, + company: row.company, + }, + }; + }; - frm.fields_dict["item_defaults"].grid.get_field("selling_cost_center").get_query = function(doc, cdt, cdn) { + frm.fields_dict["item_defaults"].grid.get_field("selling_cost_center").get_query = function ( + doc, + cdt, + cdn + ) { const row = locals[cdt][cdn]; return { filters: { - "is_group": 0, - "company": row.company - } - } - } - + is_group: 0, + company: row.company, + }, + }; + }; - frm.fields_dict['taxes'].grid.get_field("tax_type").get_query = function(doc, cdt, cdn) { + frm.fields_dict["taxes"].grid.get_field("tax_type").get_query = function (doc, cdt, cdn) { return { filters: [ - ['Account', 'account_type', 'in', - 'Tax, Chargeable, Income Account, Expense Account'], - ['Account', 'docstatus', '!=', 2] - ] - } - } + ["Account", "account_type", "in", "Tax, Chargeable, Income Account, Expense Account"], + ["Account", "docstatus", "!=", 2], + ], + }; + }; - frm.fields_dict['item_group'].get_query = function(doc, cdt, cdn) { + frm.fields_dict["item_group"].get_query = function (doc, cdt, cdn) { return { - filters: [ - ['Item Group', 'docstatus', '!=', 2] - ] - } - } + filters: [["Item Group", "docstatus", "!=", 2]], + }; + }; - frm.fields_dict["item_defaults"].grid.get_field("deferred_revenue_account").get_query = function(doc, cdt, cdn) { + frm.fields_dict["item_defaults"].grid.get_field("deferred_revenue_account").get_query = function ( + doc, + cdt, + cdn + ) { return { filters: { - "company": locals[cdt][cdn].company, - 'root_type': 'Liability', - "is_group": 0 - } - } - } + company: locals[cdt][cdn].company, + root_type: "Liability", + is_group: 0, + }, + }; + }; - frm.fields_dict["item_defaults"].grid.get_field("deferred_expense_account").get_query = function(doc, cdt, cdn) { + frm.fields_dict["item_defaults"].grid.get_field("deferred_expense_account").get_query = function ( + doc, + cdt, + cdn + ) { return { filters: { - "company": locals[cdt][cdn].company, - 'root_type': 'Asset', - "is_group": 0 - } - } - } + company: locals[cdt][cdn].company, + root_type: "Asset", + is_group: 0, + }, + }; + }; - frm.fields_dict.customer_items.grid.get_field("customer_name").get_query = function(doc, cdt, cdn) { - return { query: "erpnext.controllers.queries.customer_query" } - } + frm.fields_dict.customer_items.grid.get_field("customer_name").get_query = function (doc, cdt, cdn) { + return { query: "erpnext.controllers.queries.customer_query" }; + }; - frm.fields_dict.supplier_items.grid.get_field("supplier").get_query = function(doc, cdt, cdn) { - return { query: "erpnext.controllers.queries.supplier_query" } - } + frm.fields_dict.supplier_items.grid.get_field("supplier").get_query = function (doc, cdt, cdn) { + return { query: "erpnext.controllers.queries.supplier_query" }; + }; - frm.fields_dict["item_defaults"].grid.get_field("default_warehouse").get_query = function(doc, cdt, cdn) { + frm.fields_dict["item_defaults"].grid.get_field("default_warehouse").get_query = function ( + doc, + cdt, + cdn + ) { const row = locals[cdt][cdn]; return { filters: { - "is_group": 0, - "company": row.company - } - } - } + is_group: 0, + company: row.company, + }, + }; + }; - frm.fields_dict.reorder_levels.grid.get_field("warehouse_group").get_query = function(doc, cdt, cdn) { + frm.fields_dict.reorder_levels.grid.get_field("warehouse_group").get_query = function ( + doc, + cdt, + cdn + ) { return { - filters: { "is_group": 1 } - } - } + filters: { is_group: 1 }, + }; + }; - frm.fields_dict.reorder_levels.grid.get_field("warehouse").get_query = function(doc, cdt, cdn) { + frm.fields_dict.reorder_levels.grid.get_field("warehouse").get_query = function (doc, cdt, cdn) { var d = locals[cdt][cdn]; var filters = { - "is_group": 0 - } + is_group: 0, + }; if (d.parent_warehouse) { - filters.extend({"parent_warehouse": d.warehouse_group}) + filters.extend({ parent_warehouse: d.warehouse_group }); } return { - filters: filters - } - } + filters: filters, + }; + }; - frm.set_query('default_provisional_account', 'item_defaults', (doc, cdt, cdn) => { + frm.set_query("default_provisional_account", "item_defaults", (doc, cdt, cdn) => { let row = locals[cdt][cdn]; return { filters: { - "company": row.company, - "root_type": ["in", ["Liability", "Asset"]], - "is_group": 0 - } + company: row.company, + root_type: ["in", ["Liability", "Asset"]], + is_group: 0, + }, }; }); - }, - make_dashboard: function(frm) { - if(frm.doc.__islocal) - return; + make_dashboard: function (frm) { + if (frm.doc.__islocal) return; // Show Stock Levels only if is_stock_item if (frm.doc.is_stock_item) { - frappe.require('item-dashboard.bundle.js', function() { - const section = frm.dashboard.add_section('', __("Stock Levels")); + frappe.require("item-dashboard.bundle.js", function () { + const section = frm.dashboard.add_section("", __("Stock Levels")); erpnext.item.item_dashboard = new erpnext.stock.ItemDashboard({ parent: section, item_code: frm.doc.name, page_length: 20, - method: 'erpnext.stock.dashboard.item_dashboard.get_data', - template: 'item_dashboard_list' + method: "erpnext.stock.dashboard.item_dashboard.get_data", + template: "item_dashboard_list", }); erpnext.item.item_dashboard.refresh(); }); } }, - edit_prices_button: function(frm) { - frm.add_custom_button(__("Add / Edit Prices"), function() { - frappe.set_route("List", "Item Price", {"item_code": frm.doc.name}); - }, __("Actions")); + edit_prices_button: function (frm) { + frm.add_custom_button( + __("Add / Edit Prices"), + function () { + frappe.set_route("List", "Item Price", { item_code: frm.doc.name }); + }, + __("Actions") + ); }, - weight_to_validate: function(frm) { + weight_to_validate: function (frm) { if (frm.doc.weight_per_unit && !frm.doc.weight_uom) { frappe.msgprint({ message: __("Please mention 'Weight UOM' along with Weight."), - title: __("Note") + title: __("Note"), }); } }, - show_modal_for_manufacturers: function(frm) { + show_modal_for_manufacturers: function (frm) { var dialog = new frappe.ui.Dialog({ fields: [ { - fieldtype: 'Link', - fieldname: 'manufacturer', - options: 'Manufacturer', - label: 'Manufacturer', + fieldtype: "Link", + fieldname: "manufacturer", + options: "Manufacturer", + label: "Manufacturer", reqd: 1, }, { - fieldtype: 'Data', - label: 'Manufacturer Part Number', - fieldname: 'manufacturer_part_no' + fieldtype: "Data", + label: "Manufacturer Part Number", + fieldname: "manufacturer_part_no", }, - ] + ], }); - dialog.set_primary_action(__('Create'), function() { + dialog.set_primary_action(__("Create"), function () { var data = dialog.get_values(); - if(!data) return; + if (!data) return; // call the server to make the variant data.template = frm.doc.name; frappe.call({ method: "erpnext.controllers.item_variant.get_variant", args: data, - callback: function(r) { + callback: function (r) { var doclist = frappe.model.sync(r.message); dialog.hide(); frappe.set_route("Form", doclist[0].doctype, doclist[0].name); - } + }, }); - }) + }); dialog.show(); }, - show_multiple_variants_dialog: function(frm) { + show_multiple_variants_dialog: function (frm) { var me = this; let promises = []; @@ -505,27 +592,26 @@ $.extend(erpnext.item, { function make_fields_from_attribute_values(attr_dict) { let fields = []; Object.keys(attr_dict).forEach((name, i) => { - if(i % 3 === 0){ - fields.push({fieldtype: 'Section Break'}); + if (i % 3 === 0) { + fields.push({ fieldtype: "Section Break" }); } - fields.push({fieldtype: 'Column Break', label: name}); - attr_dict[name].forEach(value => { + fields.push({ fieldtype: "Column Break", label: name }); + attr_dict[name].forEach((value) => { fields.push({ - fieldtype: 'Check', + fieldtype: "Check", label: value, fieldname: value, default: 0, - onchange: function() { + onchange: function () { let selected_attributes = get_selected_attributes(); let lengths = []; - Object.keys(selected_attributes).map(key => { + Object.keys(selected_attributes).map((key) => { lengths.push(selected_attributes[key].length); }); - if(lengths.includes(0)) { - me.multiple_variant_dialog.get_primary_btn().html(__('Create Variants')); + if (lengths.includes(0)) { + me.multiple_variant_dialog.get_primary_btn().html(__("Create Variants")); me.multiple_variant_dialog.disable_primary_action(); } else { - let no_of_combinations = lengths.reduce((a, b) => a * b, 1); let msg; if (no_of_combinations === 1) { @@ -536,7 +622,7 @@ $.extend(erpnext.item, { me.multiple_variant_dialog.get_primary_btn().html(msg); me.multiple_variant_dialog.enable_primary_action(); } - } + }, }); }); }); @@ -553,38 +639,40 @@ $.extend(erpnext.item, { options: ``, - } - ].concat(fields) + }, + ].concat(fields), }); - me.multiple_variant_dialog.set_primary_action(__('Create Variants'), () => { + me.multiple_variant_dialog.set_primary_action(__("Create Variants"), () => { let selected_attributes = get_selected_attributes(); me.multiple_variant_dialog.hide(); frappe.call({ method: "erpnext.controllers.item_variant.enqueue_multiple_variant_creation", args: { - "item": frm.doc.name, - "args": selected_attributes + item: frm.doc.name, + args: selected_attributes, }, - callback: function(r) { - if (r.message==='queued') { + callback: function (r) { + if (r.message === "queued") { frappe.show_alert({ message: __("Variant creation has been queued."), - indicator: 'orange' + indicator: "orange", }); } else { frappe.show_alert({ message: __("{0} variants created.", [r.message]), - indicator: 'green' + indicator: "green", }); } - } + }, }); }); - $($(me.multiple_variant_dialog.$wrapper.find('.form-column')) - .find('.frappe-control')).css('margin-bottom', '0px'); + $($(me.multiple_variant_dialog.$wrapper.find(".form-column")).find(".frappe-control")).css( + "margin-bottom", + "0px" + ); me.multiple_variant_dialog.disable_primary_action(); me.multiple_variant_dialog.clear(); @@ -593,14 +681,14 @@ $.extend(erpnext.item, { function get_selected_attributes() { let selected_attributes = {}; - me.multiple_variant_dialog.$wrapper.find('.form-column').each((i, col) => { - if(i===0) return; - let attribute_name = $(col).find('.control-label').html().trim(); + me.multiple_variant_dialog.$wrapper.find(".form-column").each((i, col) => { + if (i === 0) return; + let attribute_name = $(col).find(".control-label").html().trim(); selected_attributes[attribute_name] = []; - let checked_opts = $(col).find('.checkbox input'); + let checked_opts = $(col).find(".checkbox input"); checked_opts.each((i, opt) => { - if($(opt).is(':checked')) { - selected_attributes[attribute_name].push($(opt).attr('data-fieldname')); + if ($(opt).is(":checked")) { + selected_attributes[attribute_name].push($(opt).attr("data-fieldname")); } }); }); @@ -608,30 +696,32 @@ $.extend(erpnext.item, { return selected_attributes; } - frm.doc.attributes.forEach(function(d) { - let p = new Promise(resolve => { - if(!d.numeric_values) { - frappe.call({ - method: "frappe.client.get_list", - args: { - doctype: "Item Attribute Value", - filters: [ - ["parent","=", d.attribute] - ], - fields: ["attribute_value"], - limit_page_length: 0, - parent: "Item Attribute", - order_by: "idx" - } - }).then((r) => { - if(r.message) { - attr_val_fields[d.attribute] = r.message.map(function(d) { return d.attribute_value; }); - resolve(); - } - }); + frm.doc.attributes.forEach(function (d) { + let p = new Promise((resolve) => { + if (!d.numeric_values) { + frappe + .call({ + method: "frappe.client.get_list", + args: { + doctype: "Item Attribute Value", + filters: [["parent", "=", d.attribute]], + fields: ["attribute_value"], + limit_page_length: 0, + parent: "Item Attribute", + order_by: "idx", + }, + }) + .then((r) => { + if (r.message) { + attr_val_fields[d.attribute] = r.message.map(function (d) { + return d.attribute_value; + }); + resolve(); + } + }); } else { let values = []; - for(var i = d.from_range; i <= d.to_range; i = flt(i + d.increment, 6)) { + for (var i = d.from_range; i <= d.to_range; i = flt(i + d.increment, 6)) { values.push(i); } attr_val_fields[d.attribute] = values; @@ -640,66 +730,74 @@ $.extend(erpnext.item, { }); promises.push(p); - }, this); Promise.all(promises).then(() => { let fields = make_fields_from_attribute_values(attr_val_fields); make_and_show_dialog(fields); - }) - + }); }, - show_single_variant_dialog: function(frm) { - var fields = [] + show_single_variant_dialog: function (frm) { + var fields = []; - for(var i=0;i< frm.doc.attributes.length;i++){ + for (var i = 0; i < frm.doc.attributes.length; i++) { var fieldtype, desc; var row = frm.doc.attributes[i]; - if (row.numeric_values){ + if (row.numeric_values) { fieldtype = "Float"; - desc = "Min Value: "+ row.from_range +" , Max Value: "+ row.to_range +", in Increments of: "+ row.increment - } - else { + desc = + "Min Value: " + + row.from_range + + " , Max Value: " + + row.to_range + + ", in Increments of: " + + row.increment; + } else { fieldtype = "Data"; - desc = "" + desc = ""; } fields = fields.concat({ - "label": row.attribute, - "fieldname": row.attribute, - "fieldtype": fieldtype, - "reqd": 0, - "description": desc - }) + label: row.attribute, + fieldname: row.attribute, + fieldtype: fieldtype, + reqd: 0, + description: desc, + }); } var d = new frappe.ui.Dialog({ - title: __('Create Variant'), - fields: fields + title: __("Create Variant"), + fields: fields, }); - d.set_primary_action(__('Create'), function() { + d.set_primary_action(__("Create"), function () { var args = d.get_values(); - if(!args) return; + if (!args) return; frappe.call({ method: "erpnext.controllers.item_variant.get_variant", btn: d.get_primary_btn(), args: { - "template": frm.doc.name, - "args": d.get_values() + template: frm.doc.name, + args: d.get_values(), }, - callback: function(r) { + callback: function (r) { // returns variant item if (r.message) { var variant = r.message; - frappe.msgprint_dialog = frappe.msgprint(__("Item Variant {0} already exists with same attributes", - [repl('%(item)s', { - item_encoded: encodeURIComponent(variant), - item: variant - })] - )); + frappe.msgprint_dialog = frappe.msgprint( + __("Item Variant {0} already exists with same attributes", [ + repl( + '%(item)s', + { + item_encoded: encodeURIComponent(variant), + item: variant, + } + ), + ]) + ); frappe.msgprint_dialog.hide_on_page_refresh = true; - frappe.msgprint_dialog.$wrapper.find(".variant-click").on("click", function() { + frappe.msgprint_dialog.$wrapper.find(".variant-click").on("click", function () { d.hide(); }); } else { @@ -707,24 +805,23 @@ $.extend(erpnext.item, { frappe.call({ method: "erpnext.controllers.item_variant.create_variant", args: { - "item": frm.doc.name, - "args": d.get_values() + item: frm.doc.name, + args: d.get_values(), }, - callback: function(r) { + callback: function (r) { var doclist = frappe.model.sync(r.message); frappe.set_route("Form", doclist[0].doctype, doclist[0].name); - } + }, }); } - } + }, }); }); d.show(); - $.each(d.fields_dict, function(i, field) { - - if(field.df.fieldtype !== "Data") { + $.each(d.fields_dict, function (i, field) { + if (field.df.fieldtype !== "Data") { return; } @@ -740,32 +837,34 @@ $.extend(erpnext.item, { input.field = field; field.$input - .on('input', function(e) { + .on("input", function (e) { var term = e.target.value; frappe.call({ method: "erpnext.stock.doctype.item.item.get_item_attribute", args: { parent: i, - attribute_value: term + attribute_value: term, }, - callback: function(r) { + callback: function (r) { if (r.message) { - e.target.awesomplete.list = r.message.map(function(d) { return d.attribute_value; }); + e.target.awesomplete.list = r.message.map(function (d) { + return d.attribute_value; + }); } - } + }, }); }) - .on('focus', function(e) { - $(e.target).val('').trigger('input'); + .on("focus", function (e) { + $(e.target).val("").trigger("input"); }) .on("awesomplete-open", () => { - let modal = field.$input.parents('.modal-dialog')[0]; + let modal = field.$input.parents(".modal-dialog")[0]; if (modal) { $(modal).removeClass("modal-dialog-scrollable"); } }) .on("awesomplete-close", () => { - let modal = field.$input.parents('.modal-dialog')[0]; + let modal = field.$input.parents(".modal-dialog")[0]; if (modal) { $(modal).addClass("modal-dialog-scrollable"); } @@ -773,14 +872,13 @@ $.extend(erpnext.item, { }); }, - toggle_attributes: function(frm) { - if((frm.doc.has_variants || frm.doc.variant_of) - && frm.doc.variant_based_on==='Item Attribute') { + toggle_attributes: function (frm) { + if ((frm.doc.has_variants || frm.doc.variant_of) && frm.doc.variant_based_on === "Item Attribute") { frm.toggle_display("attributes", true); var grid = frm.fields_dict.attributes.grid; - if(frm.doc.variant_of) { + if (frm.doc.variant_of) { // variant // value column is displayed but not editable @@ -804,78 +902,87 @@ $.extend(erpnext.item, { // enable the grid so you can add more attributes grid.toggle_enable("attribute", true); } - } else { // nothing to do with attributes, hide it frm.toggle_display("attributes", false); } frm.layout.refresh_sections(); - } + }, }); frappe.ui.form.on("UOM Conversion Detail", { - uom: function(frm, cdt, cdn) { + uom: function (frm, cdt, cdn) { var row = locals[cdt][cdn]; if (row.uom) { frappe.call({ method: "erpnext.stock.doctype.item.item.get_uom_conv_factor", args: { - "uom": row.uom, - "stock_uom": frm.doc.stock_uom + uom: row.uom, + stock_uom: frm.doc.stock_uom, }, - callback: function(r) { + callback: function (r) { if (!r.exc && r.message) { frappe.model.set_value(cdt, cdn, "conversion_factor", r.message); } - } + }, }); } - } + }, }); -frappe.tour['Item'] = [ +frappe.tour["Item"] = [ { fieldname: "item_code", title: "Item Code", - description: __("Enter an Item Code, the name will be auto-filled the same as Item Code on clicking inside the Item Name field.") + description: __( + "Enter an Item Code, the name will be auto-filled the same as Item Code on clicking inside the Item Name field." + ), }, { fieldname: "item_group", title: "Item Group", - description: __("Select an Item Group.") + description: __("Select an Item Group."), }, { fieldname: "is_stock_item", title: "Maintain Stock", - description: __("If you are maintaining stock of this Item in your Inventory, ERPNext will make a stock ledger entry for each transaction of this item.") + description: __( + "If you are maintaining stock of this Item in your Inventory, ERPNext will make a stock ledger entry for each transaction of this item." + ), }, { fieldname: "include_item_in_manufacturing", title: "Include Item in Manufacturing", - description: __("This is for raw material Items that'll be used to create finished goods. If the Item is an additional service like 'washing' that'll be used in the BOM, keep this unchecked.") + description: __( + "This is for raw material Items that'll be used to create finished goods. If the Item is an additional service like 'washing' that'll be used in the BOM, keep this unchecked." + ), }, { fieldname: "opening_stock", title: "Opening Stock", - description: __("Enter the opening stock units.") + description: __("Enter the opening stock units."), }, { fieldname: "valuation_rate", title: "Valuation Rate", - description: __("There are two options to maintain valuation of stock. FIFO (first in - first out) and Moving Average. To understand this topic in detail please visit Item Valuation, FIFO and Moving Average.") + description: __( + "There are two options to maintain valuation of stock. FIFO (first in - first out) and Moving Average. To understand this topic in detail please visit Item Valuation, FIFO and Moving Average." + ), }, { fieldname: "standard_rate", title: "Standard Selling Rate", - description: __("When creating an Item, entering a value for this field will automatically create an Item Price at the backend.") + description: __( + "When creating an Item, entering a value for this field will automatically create an Item Price at the backend." + ), }, { fieldname: "item_defaults", title: "Item Defaults", - description: __("In this section, you can define Company-wide transaction-related defaults for this Item. Eg. Default Warehouse, Default Price List, Supplier, etc.") - } - - + description: __( + "In this section, you can define Company-wide transaction-related defaults for this Item. Eg. Default Warehouse, Default Price List, Supplier, etc." + ), + }, ]; function open_form(frm, doctype, child_doctype, parentfield) { @@ -902,7 +1009,7 @@ function open_form(frm, doctype, child_doctype, parentfield) { () => { frappe.flags.ignore_company_party_validation = true; frappe.model.trigger("item_code", frm.doc.name, new_child_doc); - } - ]) + }, + ]); }); } diff --git a/erpnext/stock/doctype/item/item_list.js b/erpnext/stock/doctype/item/item_list.js index 22d38e88935c..aef0b2a648b6 100644 --- a/erpnext/stock/doctype/item/item_list.js +++ b/erpnext/stock/doctype/item/item_list.js @@ -1,9 +1,8 @@ -frappe.listview_settings['Item'] = { - add_fields: ["item_name", "stock_uom", "item_group", "image", - "has_variants", "end_of_life", "disabled"], +frappe.listview_settings["Item"] = { + add_fields: ["item_name", "stock_uom", "item_group", "image", "has_variants", "end_of_life", "disabled"], filters: [["disabled", "=", "0"]], - get_indicator: function(doc) { + get_indicator: function (doc) { if (doc.disabled) { return [__("Disabled"), "grey", "disabled,=,Yes"]; } else if (doc.end_of_life && doc.end_of_life < frappe.datetime.get_today()) { @@ -17,24 +16,23 @@ frappe.listview_settings['Item'] = { reports: [ { - name: 'Stock Summary', - report_type: 'Page', - route: 'stock-balance' + name: "Stock Summary", + report_type: "Page", + route: "stock-balance", }, { - name: 'Stock Ledger', - report_type: 'Script Report' + name: "Stock Ledger", + report_type: "Script Report", }, { - name: 'Stock Balance', - report_type: 'Script Report' + name: "Stock Balance", + report_type: "Script Report", }, { - name: 'Stock Projected Qty', - report_type: 'Script Report' - } - - ] + name: "Stock Projected Qty", + report_type: "Script Report", + }, + ], }; frappe.help.youtube_id["Item"] = "qXaEwld4_Ps"; diff --git a/erpnext/stock/doctype/item_alternative/item_alternative.js b/erpnext/stock/doctype/item_alternative/item_alternative.js index ef0a88b9c811..e384e576bd29 100644 --- a/erpnext/stock/doctype/item_alternative/item_alternative.js +++ b/erpnext/stock/doctype/item_alternative/item_alternative.js @@ -1,14 +1,14 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Item Alternative', { - setup: function(frm) { +frappe.ui.form.on("Item Alternative", { + setup: function (frm) { frm.fields_dict.item_code.get_query = () => { return { filters: { - 'allow_alternative_item': 1 - } + allow_alternative_item: 1, + }, }; }; - } + }, }); diff --git a/erpnext/stock/doctype/item_attribute/item_attribute.js b/erpnext/stock/doctype/item_attribute/item_attribute.js index f253e22327f6..22c7978ac3c3 100644 --- a/erpnext/stock/doctype/item_attribute/item_attribute.js +++ b/erpnext/stock/doctype/item_attribute/item_attribute.js @@ -1,6 +1,4 @@ // Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Item Attribute', { - -}); +frappe.ui.form.on("Item Attribute", {}); diff --git a/erpnext/stock/doctype/item_manufacturer/item_manufacturer.js b/erpnext/stock/doctype/item_manufacturer/item_manufacturer.js index a4df923f039f..21803720f1f7 100644 --- a/erpnext/stock/doctype/item_manufacturer/item_manufacturer.js +++ b/erpnext/stock/doctype/item_manufacturer/item_manufacturer.js @@ -1,8 +1,7 @@ // Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Item Manufacturer', { +frappe.ui.form.on("Item Manufacturer", { // refresh: function(frm) { - // } }); diff --git a/erpnext/stock/doctype/item_price/item_price.js b/erpnext/stock/doctype/item_price/item_price.js index 8a4b4eef0ae0..a5599e340a6e 100644 --- a/erpnext/stock/doctype/item_price/item_price.js +++ b/erpnext/stock/doctype/item_price/item_price.js @@ -3,11 +3,11 @@ frappe.ui.form.on("Item Price", { setup(frm) { - frm.set_query("item_code", function() { + frm.set_query("item_code", function () { return { filters: { - "has_variants": 0 - } + has_variants: 0, + }, }; }); }, @@ -23,15 +23,18 @@ frappe.ui.form.on("Item Price", { frm.add_fetch("item_code", "description", "item_description"); frm.add_fetch("item_code", "stock_uom", "uom"); - frm.set_df_property("bulk_import_help", "options", - '' + __("Import in Bulk") + ''); + frm.set_df_property( + "bulk_import_help", + "options", + '' + __("Import in Bulk") + "" + ); - frm.set_query('batch_no', function() { + frm.set_query("batch_no", function () { return { filters: { - 'item': frm.doc.item_code - } + item: frm.doc.item_code, + }, }; }); - } + }, }); diff --git a/erpnext/stock/doctype/item_price/item_price_list.js b/erpnext/stock/doctype/item_price/item_price_list.js index 48158393f67d..94c232e2e654 100644 --- a/erpnext/stock/doctype/item_price/item_price_list.js +++ b/erpnext/stock/doctype/item_price/item_price_list.js @@ -1,3 +1,3 @@ -frappe.listview_settings['Item Price'] = { +frappe.listview_settings["Item Price"] = { hide_name_column: true, }; diff --git a/erpnext/stock/doctype/item_variant_settings/item_variant_settings.js b/erpnext/stock/doctype/item_variant_settings/item_variant_settings.js index 058783c4ae34..4c49ce99510e 100644 --- a/erpnext/stock/doctype/item_variant_settings/item_variant_settings.js +++ b/erpnext/stock/doctype/item_variant_settings/item_variant_settings.js @@ -1,24 +1,39 @@ // Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Item Variant Settings', { - refresh: function(frm) { +frappe.ui.form.on("Item Variant Settings", { + refresh: function (frm) { const allow_fields = []; - const existing_fields = frm.doc.fields.map(row => row.field_name); - const exclude_fields = [...existing_fields, "naming_series", "item_code", "item_name", - "published_in_website", "standard_rate", "opening_stock", "image", - "variant_of", "valuation_rate", "barcodes", "has_variants", "attributes"]; + const existing_fields = frm.doc.fields.map((row) => row.field_name); + const exclude_fields = [ + ...existing_fields, + "naming_series", + "item_code", + "item_name", + "published_in_website", + "standard_rate", + "opening_stock", + "image", + "variant_of", + "valuation_rate", + "barcodes", + "has_variants", + "attributes", + ]; - const exclude_field_types = ['HTML', 'Section Break', 'Column Break', 'Button', 'Read Only']; + const exclude_field_types = ["HTML", "Section Break", "Column Break", "Button", "Read Only"]; - frappe.model.with_doctype('Item', () => { + frappe.model.with_doctype("Item", () => { const field_label_map = {}; - frappe.get_meta('Item').fields.forEach(d => { + frappe.get_meta("Item").fields.forEach((d) => { field_label_map[d.fieldname] = __(d.label) + ` (${d.fieldname})`; - if (!in_list(exclude_field_types, d.fieldtype) - && !d.no_copy && !in_list(exclude_fields, d.fieldname)) { + if ( + !in_list(exclude_field_types, d.fieldtype) && + !d.no_copy && + !in_list(exclude_fields, d.fieldname) + ) { allow_fields.push({ label: field_label_map[d.fieldname], value: d.fieldname, @@ -33,9 +48,7 @@ frappe.ui.form.on('Item Variant Settings', { }); } - frm.fields_dict.fields.grid.update_docfield_property( - 'field_name', 'options', allow_fields - ); + frm.fields_dict.fields.grid.update_docfield_property("field_name", "options", allow_fields); }); - } + }, }); diff --git a/erpnext/stock/doctype/manufacturer/manufacturer.js b/erpnext/stock/doctype/manufacturer/manufacturer.js index bb7e314e14ed..1af6e4cb26dd 100644 --- a/erpnext/stock/doctype/manufacturer/manufacturer.js +++ b/erpnext/stock/doctype/manufacturer/manufacturer.js @@ -1,16 +1,15 @@ // Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Manufacturer', { - refresh: function(frm) { - frappe.dynamic_link = { doc: frm.doc, fieldname: 'name', doctype: 'Manufacturer' }; +frappe.ui.form.on("Manufacturer", { + refresh: function (frm) { + frappe.dynamic_link = { doc: frm.doc, fieldname: "name", doctype: "Manufacturer" }; if (frm.doc.__islocal) { - hide_field(['address_html','contact_html']); + hide_field(["address_html", "contact_html"]); frappe.contacts.clear_address_and_contact(frm); - } - else { - unhide_field(['address_html','contact_html']); + } else { + unhide_field(["address_html", "contact_html"]); frappe.contacts.render_address_and_contact(frm); } - } + }, }); diff --git a/erpnext/stock/doctype/material_request/material_request_list.js b/erpnext/stock/doctype/material_request/material_request_list.js index de7a3d05bf57..ee5c9e7b86c6 100644 --- a/erpnext/stock/doctype/material_request/material_request_list.js +++ b/erpnext/stock/doctype/material_request/material_request_list.js @@ -1,8 +1,8 @@ -frappe.listview_settings['Material Request'] = { +frappe.listview_settings["Material Request"] = { add_fields: ["material_request_type", "status", "per_ordered", "per_received", "transfer_status"], - get_indicator: function(doc) { + get_indicator: function (doc) { var precision = frappe.defaults.get_default("float_precision"); - if (doc.status=="Stopped") { + if (doc.status == "Stopped") { return [__("Stopped"), "red", "status,=,Stopped"]; } else if (doc.transfer_status && doc.docstatus != 2) { if (doc.transfer_status == "Not Started") { @@ -12,12 +12,16 @@ frappe.listview_settings['Material Request'] = { } else if (doc.transfer_status == "Completed") { return [__("Completed"), "green"]; } - } else if (doc.docstatus==1 && flt(doc.per_ordered, precision) == 0) { + } else if (doc.docstatus == 1 && flt(doc.per_ordered, precision) == 0) { return [__("Pending"), "orange", "per_ordered,=,0"]; - } else if (doc.docstatus==1 && flt(doc.per_ordered, precision) < 100) { + } else if (doc.docstatus == 1 && flt(doc.per_ordered, precision) < 100) { return [__("Partially ordered"), "yellow", "per_ordered,<,100"]; - } else if (doc.docstatus==1 && flt(doc.per_ordered, precision) == 100) { - if (doc.material_request_type == "Purchase" && flt(doc.per_received, precision) < 100 && flt(doc.per_received, precision) > 0) { + } else if (doc.docstatus == 1 && flt(doc.per_ordered, precision) == 100) { + if ( + doc.material_request_type == "Purchase" && + flt(doc.per_received, precision) < 100 && + flt(doc.per_received, precision) > 0 + ) { return [__("Partially Received"), "yellow", "per_received,<,100"]; } else if (doc.material_request_type == "Purchase" && flt(doc.per_received, precision) == 100) { return [__("Received"), "green", "per_received,=,100"]; @@ -33,5 +37,5 @@ frappe.listview_settings['Material Request'] = { return [__("Manufactured"), "green", "per_ordered,=,100"]; } } - } + }, }; diff --git a/erpnext/stock/doctype/packing_slip/packing_slip.js b/erpnext/stock/doctype/packing_slip/packing_slip.js index 95e5ea309f81..682631f1b747 100644 --- a/erpnext/stock/doctype/packing_slip/packing_slip.js +++ b/erpnext/stock/doctype/packing_slip/packing_slip.js @@ -1,45 +1,45 @@ // Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Packing Slip', { - setup: (frm) => { - frm.set_query('delivery_note', () => { - return { - filters: { - docstatus: 0, - } - } - }); +frappe.ui.form.on("Packing Slip", { + setup: (frm) => { + frm.set_query("delivery_note", () => { + return { + filters: { + docstatus: 0, + }, + }; + }); - frm.set_query('item_code', 'items', (doc, cdt, cdn) => { - if (!doc.delivery_note) { - frappe.throw(__('Please select a Delivery Note')); - } else { - let d = locals[cdt][cdn]; - return { - query: 'erpnext.stock.doctype.packing_slip.packing_slip.item_details', - filters: { - delivery_note: doc.delivery_note, - } - } - } - }); + frm.set_query("item_code", "items", (doc, cdt, cdn) => { + if (!doc.delivery_note) { + frappe.throw(__("Please select a Delivery Note")); + } else { + let d = locals[cdt][cdn]; + return { + query: "erpnext.stock.doctype.packing_slip.packing_slip.item_details", + filters: { + delivery_note: doc.delivery_note, + }, + }; + } + }); }, refresh: (frm) => { - frm.toggle_display('misc_details', frm.doc.amended_from); + frm.toggle_display("misc_details", frm.doc.amended_from); }, delivery_note: (frm) => { - frm.set_value('items', null); + frm.set_value("items", null); if (frm.doc.delivery_note) { erpnext.utils.map_current_doc({ - method: 'erpnext.stock.doctype.delivery_note.delivery_note.make_packing_slip', + method: "erpnext.stock.doctype.delivery_note.delivery_note.make_packing_slip", source_name: frm.doc.delivery_note, target_doc: frm, freeze: true, - freeze_message: __('Creating Packing Slip ...'), + freeze_message: __("Creating Packing Slip ..."), }); } }, diff --git a/erpnext/stock/doctype/pick_list/pick_list.js b/erpnext/stock/doctype/pick_list/pick_list.js index 8213adb89bf2..38b1ca7f76e4 100644 --- a/erpnext/stock/doctype/pick_list/pick_list.js +++ b/erpnext/stock/doctype/pick_list/pick_list.js @@ -1,61 +1,62 @@ // Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Pick List', { +frappe.ui.form.on("Pick List", { setup: (frm) => { - frm.set_indicator_formatter('item_code', - function(doc) { return (doc.stock_qty === 0) ? "red" : "green"; }); + frm.set_indicator_formatter("item_code", function (doc) { + return doc.stock_qty === 0 ? "red" : "green"; + }); frm.custom_make_buttons = { - 'Delivery Note': 'Delivery Note', - 'Stock Entry': 'Stock Entry', + "Delivery Note": "Delivery Note", + "Stock Entry": "Stock Entry", }; - frm.set_query('parent_warehouse', () => { + frm.set_query("parent_warehouse", () => { return { filters: { - 'is_group': 1, - 'company': frm.doc.company - } + is_group: 1, + company: frm.doc.company, + }, }; }); - frm.set_query('work_order', () => { + frm.set_query("work_order", () => { return { - query: 'erpnext.stock.doctype.pick_list.pick_list.get_pending_work_orders', + query: "erpnext.stock.doctype.pick_list.pick_list.get_pending_work_orders", filters: { - 'company': frm.doc.company - } + company: frm.doc.company, + }, }; }); - frm.set_query('material_request', () => { + frm.set_query("material_request", () => { return { filters: { - 'material_request_type': ['=', frm.doc.purpose] - } + material_request_type: ["=", frm.doc.purpose], + }, }; }); - frm.set_query('item_code', 'locations', () => { - return erpnext.queries.item({ "is_stock_item": 1 }); + frm.set_query("item_code", "locations", () => { + return erpnext.queries.item({ is_stock_item: 1 }); }); - frm.set_query('batch_no', 'locations', (frm, cdt, cdn) => { + frm.set_query("batch_no", "locations", (frm, cdt, cdn) => { const row = locals[cdt][cdn]; return { - query: 'erpnext.controllers.queries.get_batch_no', + query: "erpnext.controllers.queries.get_batch_no", filters: { item_code: row.item_code, - warehouse: row.warehouse + warehouse: row.warehouse, }, }; }); }, - set_item_locations:(frm, save) => { + set_item_locations: (frm, save) => { if (!(frm.doc.locations && frm.doc.locations.length)) { - frappe.msgprint(__('Add items in the Item Locations table')); + frappe.msgprint(__("Add items in the Item Locations table")); } else { frappe.call({ method: "set_item_locations", doc: frm.doc, args: { - "save": save, + save: save, }, freeze: 1, freeze_message: __("Setting Item Locations..."), @@ -67,155 +68,172 @@ frappe.ui.form.on('Pick List', { frm.events.set_item_locations(frm, false); }, refresh: (frm) => { - frm.trigger('add_get_items_button'); + frm.trigger("add_get_items_button"); if (frm.doc.docstatus === 1) { - frappe.xcall('erpnext.stock.doctype.pick_list.pick_list.target_document_exists', { - 'pick_list_name': frm.doc.name, - 'purpose': frm.doc.purpose - }).then(target_document_exists => { - frm.set_df_property("locations", "allow_on_submit", target_document_exists ? 0 : 1); + frappe + .xcall("erpnext.stock.doctype.pick_list.pick_list.target_document_exists", { + pick_list_name: frm.doc.name, + purpose: frm.doc.purpose, + }) + .then((target_document_exists) => { + frm.set_df_property("locations", "allow_on_submit", target_document_exists ? 0 : 1); - if (target_document_exists) return; + if (target_document_exists) return; - frm.add_custom_button(__('Update Current Stock'), () => frm.trigger('update_pick_list_stock')); + frm.add_custom_button(__("Update Current Stock"), () => + frm.trigger("update_pick_list_stock") + ); - if (frm.doc.purpose === 'Delivery') { - frm.add_custom_button(__('Delivery Note'), () => frm.trigger('create_delivery_note'), __('Create')); - } else { - frm.add_custom_button(__('Stock Entry'), () => frm.trigger('create_stock_entry'), __('Create')); - } - }); + if (frm.doc.purpose === "Delivery") { + frm.add_custom_button( + __("Delivery Note"), + () => frm.trigger("create_delivery_note"), + __("Create") + ); + } else { + frm.add_custom_button( + __("Stock Entry"), + () => frm.trigger("create_stock_entry"), + __("Create") + ); + } + }); } }, work_order: (frm) => { - frappe.db.get_value('Work Order', - frm.doc.work_order, - ['qty', 'material_transferred_for_manufacturing'] - ).then(data => { - let qty_data = data.message; - let max = qty_data.qty - qty_data.material_transferred_for_manufacturing; - frappe.prompt({ - fieldtype: 'Float', - label: __('Qty of Finished Goods Item'), - fieldname: 'qty', - description: __('Max: {0}', [max]), - default: max - }, (data) => { - frm.set_value('for_qty', data.qty); - if (data.qty > max) { - frappe.msgprint(__('Quantity must not be more than {0}', [max])); - return; - } - frm.clear_table('locations'); - erpnext.utils.map_current_doc({ - method: 'erpnext.manufacturing.doctype.work_order.work_order.create_pick_list', - target: frm, - source_name: frm.doc.work_order - }); - }, __('Select Quantity'), __('Get Items')); - }); + frappe.db + .get_value("Work Order", frm.doc.work_order, ["qty", "material_transferred_for_manufacturing"]) + .then((data) => { + let qty_data = data.message; + let max = qty_data.qty - qty_data.material_transferred_for_manufacturing; + frappe.prompt( + { + fieldtype: "Float", + label: __("Qty of Finished Goods Item"), + fieldname: "qty", + description: __("Max: {0}", [max]), + default: max, + }, + (data) => { + frm.set_value("for_qty", data.qty); + if (data.qty > max) { + frappe.msgprint(__("Quantity must not be more than {0}", [max])); + return; + } + frm.clear_table("locations"); + erpnext.utils.map_current_doc({ + method: "erpnext.manufacturing.doctype.work_order.work_order.create_pick_list", + target: frm, + source_name: frm.doc.work_order, + }); + }, + __("Select Quantity"), + __("Get Items") + ); + }); }, material_request: (frm) => { erpnext.utils.map_current_doc({ - method: 'erpnext.stock.doctype.material_request.material_request.create_pick_list', + method: "erpnext.stock.doctype.material_request.material_request.create_pick_list", target: frm, - source_name: frm.doc.material_request + source_name: frm.doc.material_request, }); }, purpose: (frm) => { - frm.clear_table('locations'); - frm.trigger('add_get_items_button'); + frm.clear_table("locations"); + frm.trigger("add_get_items_button"); }, create_delivery_note: (frm) => { frappe.model.open_mapped_doc({ - method: 'erpnext.stock.doctype.pick_list.pick_list.create_delivery_note', - frm: frm + method: "erpnext.stock.doctype.pick_list.pick_list.create_delivery_note", + frm: frm, }); - }, create_stock_entry: (frm) => { - frappe.xcall('erpnext.stock.doctype.pick_list.pick_list.create_stock_entry', { - 'pick_list': frm.doc, - }).then(stock_entry => { - frappe.model.sync(stock_entry); - frappe.set_route("Form", 'Stock Entry', stock_entry.name); - }); + frappe + .xcall("erpnext.stock.doctype.pick_list.pick_list.create_stock_entry", { + pick_list: frm.doc, + }) + .then((stock_entry) => { + frappe.model.sync(stock_entry); + frappe.set_route("Form", "Stock Entry", stock_entry.name); + }); }, update_pick_list_stock: (frm) => { frm.events.set_item_locations(frm, true); }, add_get_items_button: (frm) => { let purpose = frm.doc.purpose; - if (purpose != 'Delivery' || frm.doc.docstatus !== 0) return; + if (purpose != "Delivery" || frm.doc.docstatus !== 0) return; let get_query_filters = { docstatus: 1, - per_delivered: ['<', 100], - status: ['!=', ''], - customer: frm.doc.customer + per_delivered: ["<", 100], + status: ["!=", ""], + customer: frm.doc.customer, }; - frm.get_items_btn = frm.add_custom_button(__('Get Items'), () => { + frm.get_items_btn = frm.add_custom_button(__("Get Items"), () => { erpnext.utils.map_current_doc({ - method: 'erpnext.selling.doctype.sales_order.sales_order.create_pick_list', - source_doctype: 'Sales Order', + method: "erpnext.selling.doctype.sales_order.sales_order.create_pick_list", + source_doctype: "Sales Order", target: frm, setters: { company: frm.doc.company, - customer: frm.doc.customer + customer: frm.doc.customer, }, - date_field: 'transaction_date', - get_query_filters: get_query_filters + date_field: "transaction_date", + get_query_filters: get_query_filters, }); }); }, scan_barcode: (frm) => { const opts = { frm, - items_table_name: 'locations', - qty_field: 'picked_qty', - max_qty_field: 'qty', + items_table_name: "locations", + qty_field: "picked_qty", + max_qty_field: "qty", dont_allow_new_row: true, prompt_qty: frm.doc.prompt_qty, - serial_no_field: "not_supported", // doesn't make sense for picklist without a separate field. + serial_no_field: "not_supported", // doesn't make sense for picklist without a separate field. }; const barcode_scanner = new erpnext.utils.BarcodeScanner(opts); barcode_scanner.process_scan(); - } + }, }); -frappe.ui.form.on('Pick List Item', { +frappe.ui.form.on("Pick List Item", { item_code: (frm, cdt, cdn) => { let row = frappe.get_doc(cdt, cdn); if (row.item_code) { - get_item_details(row.item_code).then(data => { - frappe.model.set_value(cdt, cdn, 'uom', data.stock_uom); - frappe.model.set_value(cdt, cdn, 'stock_uom', data.stock_uom); - frappe.model.set_value(cdt, cdn, 'conversion_factor', 1); + get_item_details(row.item_code).then((data) => { + frappe.model.set_value(cdt, cdn, "uom", data.stock_uom); + frappe.model.set_value(cdt, cdn, "stock_uom", data.stock_uom); + frappe.model.set_value(cdt, cdn, "conversion_factor", 1); }); } }, uom: (frm, cdt, cdn) => { let row = frappe.get_doc(cdt, cdn); if (row.uom) { - get_item_details(row.item_code, row.uom).then(data => { - frappe.model.set_value(cdt, cdn, 'conversion_factor', data.conversion_factor); + get_item_details(row.item_code, row.uom).then((data) => { + frappe.model.set_value(cdt, cdn, "conversion_factor", data.conversion_factor); }); } }, qty: (frm, cdt, cdn) => { let row = frappe.get_doc(cdt, cdn); - frappe.model.set_value(cdt, cdn, 'stock_qty', row.qty * row.conversion_factor); + frappe.model.set_value(cdt, cdn, "stock_qty", row.qty * row.conversion_factor); }, conversion_factor: (frm, cdt, cdn) => { let row = frappe.get_doc(cdt, cdn); - frappe.model.set_value(cdt, cdn, 'stock_qty', row.qty * row.conversion_factor); - } + frappe.model.set_value(cdt, cdn, "stock_qty", row.qty * row.conversion_factor); + }, }); -function get_item_details(item_code, uom=null) { +function get_item_details(item_code, uom = null) { if (item_code) { - return frappe.xcall('erpnext.stock.doctype.pick_list.pick_list.get_item_details', { + return frappe.xcall("erpnext.stock.doctype.pick_list.pick_list.get_item_details", { item_code, - uom + uom, }); } } diff --git a/erpnext/stock/doctype/pick_list/pick_list_list.js b/erpnext/stock/doctype/pick_list/pick_list_list.js index ad88b0a682f5..9cdbfe187205 100644 --- a/erpnext/stock/doctype/pick_list/pick_list_list.js +++ b/erpnext/stock/doctype/pick_list/pick_list_list.js @@ -1,14 +1,14 @@ // Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.listview_settings['Pick List'] = { +frappe.listview_settings["Pick List"] = { get_indicator: function (doc) { const status_colors = { - "Draft": "grey", - "Open": "orange", - "Completed": "green", - "Cancelled": "red", + Draft: "grey", + Open: "orange", + Completed: "green", + Cancelled: "red", }; return [__(doc.status), status_colors[doc.status], "status,=," + doc.status]; }, -}; \ No newline at end of file +}; diff --git a/erpnext/stock/doctype/price_list/price_list.js b/erpnext/stock/doctype/price_list/price_list.js index 9291498e8635..85a3a3911872 100644 --- a/erpnext/stock/doctype/price_list/price_list.js +++ b/erpnext/stock/doctype/price_list/price_list.js @@ -2,13 +2,17 @@ // License: GNU General Public License v3. See license.txt frappe.ui.form.on("Price List", { - refresh: function(frm) { + refresh: function (frm) { let me = this; - frm.add_custom_button(__("Add / Edit Prices"), function() { - frappe.route_options = { - "price_list": frm.doc.name - }; - frappe.set_route("Report", "Item Price"); - }, "fa fa-money"); - } + frm.add_custom_button( + __("Add / Edit Prices"), + function () { + frappe.route_options = { + price_list: frm.doc.name, + }; + frappe.set_route("Report", "Item Price"); + }, + "fa fa-money" + ); + }, }); diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt_list.js b/erpnext/stock/doctype/purchase_receipt/purchase_receipt_list.js index 4029f0c127b7..ddc9bb026fbb 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt_list.js +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt_list.js @@ -1,8 +1,17 @@ -frappe.listview_settings['Purchase Receipt'] = { - add_fields: ["supplier", "supplier_name", "base_grand_total", "is_subcontracted", - "transporter_name", "is_return", "status", "per_billed", "currency"], - get_indicator: function(doc) { - if(cint(doc.is_return)==1) { +frappe.listview_settings["Purchase Receipt"] = { + add_fields: [ + "supplier", + "supplier_name", + "base_grand_total", + "is_subcontracted", + "transporter_name", + "is_return", + "status", + "per_billed", + "currency", + ], + get_indicator: function (doc) { + if (cint(doc.is_return) == 1) { return [__("Return"), "gray", "is_return,=,Yes"]; } else if (doc.status === "Closed") { return [__("Closed"), "green", "status,=,Closed"]; @@ -15,11 +24,9 @@ frappe.listview_settings['Purchase Receipt'] = { } }, - onload: function(listview) { - - listview.page.add_action_item(__("Purchase Invoice"), ()=>{ + onload: function (listview) { + listview.page.add_action_item(__("Purchase Invoice"), () => { erpnext.bulk_transaction_processing.create(listview, "Purchase Receipt", "Purchase Invoice"); }); - } - + }, }; diff --git a/erpnext/stock/doctype/putaway_rule/putaway_rule.js b/erpnext/stock/doctype/putaway_rule/putaway_rule.js index e0569206ef94..351be16d7cbb 100644 --- a/erpnext/stock/doctype/putaway_rule/putaway_rule.js +++ b/erpnext/stock/doctype/putaway_rule/putaway_rule.js @@ -1,41 +1,41 @@ // Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Putaway Rule', { - setup: function(frm) { - frm.set_query("warehouse", function() { +frappe.ui.form.on("Putaway Rule", { + setup: function (frm) { + frm.set_query("warehouse", function () { return { - "filters": { - "company": frm.doc.company, - "is_group": 0 - } + filters: { + company: frm.doc.company, + is_group: 0, + }, }; }); }, - uom: function(frm) { + uom: function (frm) { if (frm.doc.item_code && frm.doc.uom) { return frm.call({ method: "erpnext.stock.get_item_details.get_conversion_factor", args: { item_code: frm.doc.item_code, - uom: frm.doc.uom + uom: frm.doc.uom, }, - callback: function(r) { + callback: function (r) { if (!r.exc) { let stock_capacity = flt(frm.doc.capacity) * flt(r.message.conversion_factor); - frm.set_value('conversion_factor', r.message.conversion_factor); - frm.set_value('stock_capacity', stock_capacity); + frm.set_value("conversion_factor", r.message.conversion_factor); + frm.set_value("stock_capacity", stock_capacity); } - } + }, }); } }, - capacity: function(frm) { + capacity: function (frm) { let stock_capacity = flt(frm.doc.capacity) * flt(frm.doc.conversion_factor); - frm.set_value('stock_capacity', stock_capacity); - } + frm.set_value("stock_capacity", stock_capacity); + }, // refresh: function(frm) { diff --git a/erpnext/stock/doctype/putaway_rule/putaway_rule_list.js b/erpnext/stock/doctype/putaway_rule/putaway_rule_list.js index 725e91ee8d93..c5c85908b8fd 100644 --- a/erpnext/stock/doctype/putaway_rule/putaway_rule_list.js +++ b/erpnext/stock/doctype/putaway_rule/putaway_rule_list.js @@ -1,4 +1,4 @@ -frappe.listview_settings['Putaway Rule'] = { +frappe.listview_settings["Putaway Rule"] = { add_fields: ["disable"], get_indicator: (doc) => { if (doc.disable) { @@ -10,9 +10,9 @@ frappe.listview_settings['Putaway Rule'] = { reports: [ { - name: 'Warehouse Capacity Summary', - report_type: 'Page', - route: 'warehouse-capacity-summary' - } - ] + name: "Warehouse Capacity Summary", + report_type: "Page", + route: "warehouse-capacity-summary", + }, + ], }; diff --git a/erpnext/stock/doctype/quality_inspection/quality_inspection.js b/erpnext/stock/doctype/quality_inspection/quality_inspection.js index 05fa2324dd47..fc487514a2c7 100644 --- a/erpnext/stock/doctype/quality_inspection/quality_inspection.js +++ b/erpnext/stock/doctype/quality_inspection/quality_inspection.js @@ -4,88 +4,85 @@ cur_frm.cscript.refresh = cur_frm.cscript.inspection_type; frappe.ui.form.on("Quality Inspection", { - - setup: function(frm) { - frm.set_query("reference_name", function() { + setup: function (frm) { + frm.set_query("reference_name", function () { return { filters: { - "docstatus": ["!=", 2], - } - } + docstatus: ["!=", 2], + }, + }; }); - frm.set_query("batch_no", function() { + frm.set_query("batch_no", function () { return { filters: { - "item": frm.doc.item_code - } + item: frm.doc.item_code, + }, }; }); // Serial No based on item_code - frm.set_query("item_serial_no", function() { + frm.set_query("item_serial_no", function () { let filters = {}; if (frm.doc.item_code) { filters = { - 'item_code': frm.doc.item_code + item_code: frm.doc.item_code, }; } return { filters: filters }; }); // item code based on GRN/DN - frm.set_query("item_code", function(doc) { + frm.set_query("item_code", function (doc) { let doctype = doc.reference_type; if (doc.reference_type !== "Job Card") { - doctype = (doc.reference_type == "Stock Entry") ? - "Stock Entry Detail" : doc.reference_type + " Item"; + doctype = + doc.reference_type == "Stock Entry" ? "Stock Entry Detail" : doc.reference_type + " Item"; } if (doc.reference_type && doc.reference_name) { let filters = { - "from": doctype, - "inspection_type": doc.inspection_type + from: doctype, + inspection_type: doc.inspection_type, }; - if (doc.reference_type == doctype) - filters["reference_name"] = doc.reference_name; - else - filters["parent"] = doc.reference_name; + if (doc.reference_type == doctype) filters["reference_name"] = doc.reference_name; + else filters["parent"] = doc.reference_name; return { query: "erpnext.stock.doctype.quality_inspection.quality_inspection.item_query", - filters: filters + filters: filters, }; } }); }, - refresh: function(frm) { + refresh: function (frm) { // Ignore cancellation of reference doctype on cancel all. frm.ignore_doctypes_on_cancel_all = [frm.doc.reference_type]; }, - item_code: function(frm) { + item_code: function (frm) { if (frm.doc.item_code && !frm.doc.quality_inspection_template) { return frm.call({ method: "get_quality_inspection_template", doc: frm.doc, - callback: function() { - refresh_field(['quality_inspection_template', 'readings']); - } + callback: function () { + refresh_field(["quality_inspection_template", "readings"]); + }, }); } }, - quality_inspection_template: function(frm) { + quality_inspection_template: function (frm) { if (frm.doc.quality_inspection_template) { return frm.call({ method: "get_item_specification_details", doc: frm.doc, - callback: function() { - refresh_field('readings'); - } + callback: function () { + refresh_field("readings"); + }, }); } }, diff --git a/erpnext/stock/doctype/quality_inspection_parameter/quality_inspection_parameter.js b/erpnext/stock/doctype/quality_inspection_parameter/quality_inspection_parameter.js index 47c7e11d2375..ecf84c91506e 100644 --- a/erpnext/stock/doctype/quality_inspection_parameter/quality_inspection_parameter.js +++ b/erpnext/stock/doctype/quality_inspection_parameter/quality_inspection_parameter.js @@ -1,8 +1,7 @@ // Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Quality Inspection Parameter', { +frappe.ui.form.on("Quality Inspection Parameter", { // refresh: function(frm) { - // } }); diff --git a/erpnext/stock/doctype/quality_inspection_parameter_group/quality_inspection_parameter_group.js b/erpnext/stock/doctype/quality_inspection_parameter_group/quality_inspection_parameter_group.js index 8716a298716d..796ab89d2b53 100644 --- a/erpnext/stock/doctype/quality_inspection_parameter_group/quality_inspection_parameter_group.js +++ b/erpnext/stock/doctype/quality_inspection_parameter_group/quality_inspection_parameter_group.js @@ -1,8 +1,7 @@ // Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Quality Inspection Parameter Group', { +frappe.ui.form.on("Quality Inspection Parameter Group", { // refresh: function(frm) { - // } }); diff --git a/erpnext/stock/doctype/quality_inspection_template/quality_inspection_template.js b/erpnext/stock/doctype/quality_inspection_template/quality_inspection_template.js index fa57a3dcc348..053809d5fe07 100644 --- a/erpnext/stock/doctype/quality_inspection_template/quality_inspection_template.js +++ b/erpnext/stock/doctype/quality_inspection_template/quality_inspection_template.js @@ -1,8 +1,6 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Quality Inspection Template', { - refresh: function() { - - } +frappe.ui.form.on("Quality Inspection Template", { + refresh: function () {}, }); diff --git a/erpnext/stock/doctype/quick_stock_balance/quick_stock_balance.js b/erpnext/stock/doctype/quick_stock_balance/quick_stock_balance.js index f261fd99790c..5cfd1f5843a8 100644 --- a/erpnext/stock/doctype/quick_stock_balance/quick_stock_balance.js +++ b/erpnext/stock/doctype/quick_stock_balance/quick_stock_balance.js @@ -1,91 +1,90 @@ // Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Quick Stock Balance', { - +frappe.ui.form.on("Quick Stock Balance", { setup: (frm) => { - frm.set_query('item', () => { + frm.set_query("item", () => { if (!(frm.doc.warehouse && frm.doc.date)) { - frm.trigger('check_warehouse_and_date'); + frm.trigger("check_warehouse_and_date"); } }); }, make_custom_stock_report_button: (frm) => { if (frm.doc.item) { - frm.add_custom_button(__('Stock Balance Report'), () => { - frappe.set_route('query-report', 'Stock Balance', - { 'item_code': frm.doc.item, 'warehouse': frm.doc.warehouse }); + frm.add_custom_button(__("Stock Balance Report"), () => { + frappe.set_route("query-report", "Stock Balance", { + item_code: frm.doc.item, + warehouse: frm.doc.warehouse, + }); }); } }, refresh: (frm) => { frm.disable_save(); - frm.trigger('make_custom_stock_report_button'); + frm.trigger("make_custom_stock_report_button"); }, check_warehouse_and_date: (frm) => { - frappe.msgprint(__('Please enter Warehouse and Date')); - frm.doc.item = ''; + frappe.msgprint(__("Please enter Warehouse and Date")); + frm.doc.item = ""; frm.refresh(); }, warehouse: (frm) => { if (frm.doc.item || frm.doc.item_barcode) { - frm.trigger('get_stock_and_item_details'); + frm.trigger("get_stock_and_item_details"); } }, date: (frm) => { if (frm.doc.item || frm.doc.item_barcode) { - frm.trigger('get_stock_and_item_details'); + frm.trigger("get_stock_and_item_details"); } }, item: (frm) => { - frappe.flags.last_updated_element = 'item'; - frm.trigger('get_stock_and_item_details'); - frm.trigger('make_custom_stock_report_button'); + frappe.flags.last_updated_element = "item"; + frm.trigger("get_stock_and_item_details"); + frm.trigger("make_custom_stock_report_button"); }, item_barcode: (frm) => { - frappe.flags.last_updated_element = 'item_barcode'; - frm.trigger('get_stock_and_item_details'); - frm.trigger('make_custom_stock_report_button'); + frappe.flags.last_updated_element = "item_barcode"; + frm.trigger("get_stock_and_item_details"); + frm.trigger("make_custom_stock_report_button"); }, get_stock_and_item_details: (frm) => { if (!(frm.doc.warehouse && frm.doc.date)) { - frm.trigger('check_warehouse_and_date'); - } - else if (frm.doc.item || frm.doc.item_barcode) { + frm.trigger("check_warehouse_and_date"); + } else if (frm.doc.item || frm.doc.item_barcode) { let filters = { warehouse: frm.doc.warehouse, date: frm.doc.date, }; - if (frappe.flags.last_updated_element === 'item') { - filters = { ...filters, ...{ item: frm.doc.item }}; - } - else { - filters = { ...filters, ...{ barcode: frm.doc.item_barcode }}; + if (frappe.flags.last_updated_element === "item") { + filters = { ...filters, ...{ item: frm.doc.item } }; + } else { + filters = { ...filters, ...{ barcode: frm.doc.item_barcode } }; } frappe.call({ - method: 'erpnext.stock.doctype.quick_stock_balance.quick_stock_balance.get_stock_item_details', + method: "erpnext.stock.doctype.quick_stock_balance.quick_stock_balance.get_stock_item_details", args: filters, callback: (r) => { if (r.message) { - let fields = ['item', 'qty', 'value', 'image']; - if (!r.message['barcodes'].includes(frm.doc.item_barcode)) { - frm.doc.item_barcode = ''; + let fields = ["item", "qty", "value", "image"]; + if (!r.message["barcodes"].includes(frm.doc.item_barcode)) { + frm.doc.item_barcode = ""; frm.refresh(); } fields.forEach(function (field) { frm.set_value(field, r.message[field]); }); } - } + }, }); } - } + }, }); diff --git a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.js b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.js index 8aec53284761..38241ae06099 100644 --- a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.js +++ b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.js @@ -1,22 +1,32 @@ // Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Repost Item Valuation', { - setup: function(frm) { +frappe.ui.form.on("Repost Item Valuation", { + setup: function (frm) { frm.set_query("warehouse", () => { let filters = { - 'is_group': 0 + is_group: 0, }; - if (frm.doc.company) filters['company'] = frm.doc.company; - return {filters: filters}; + if (frm.doc.company) filters["company"] = frm.doc.company; + return { filters: filters }; }); frm.set_query("voucher_type", () => { return { filters: { - name: ['in', ['Purchase Receipt', 'Purchase Invoice', 'Delivery Note', - 'Sales Invoice', 'Stock Entry', 'Stock Reconciliation', 'Subcontracting Receipt']] - } + name: [ + "in", + [ + "Purchase Receipt", + "Purchase Invoice", + "Delivery Note", + "Sales Invoice", + "Stock Entry", + "Stock Reconciliation", + "Subcontracting Receipt", + ], + ], + }, }; }); @@ -25,97 +35,97 @@ frappe.ui.form.on('Repost Item Valuation', { return { filters: { company: frm.doc.company, - docstatus: 1 - } + docstatus: 1, + }, }; }); } - frm.trigger('setup_realtime_progress'); + frm.trigger("setup_realtime_progress"); }, - based_on: function(frm) { + based_on: function (frm) { var fields_to_reset = []; - if (frm.doc.based_on == 'Transaction') { - fields_to_reset = ['item_code', 'warehouse']; - } else if (frm.doc.based_on == 'Item and Warehouse') { - fields_to_reset = ['voucher_type', 'voucher_no']; + if (frm.doc.based_on == "Transaction") { + fields_to_reset = ["item_code", "warehouse"]; + } else if (frm.doc.based_on == "Item and Warehouse") { + fields_to_reset = ["voucher_type", "voucher_no"]; } if (fields_to_reset) { - fields_to_reset.forEach(field => { + fields_to_reset.forEach((field) => { frm.set_value(field, undefined); }); } }, - setup_realtime_progress: function(frm) { - frappe.realtime.on('item_reposting_progress', data => { + setup_realtime_progress: function (frm) { + frappe.realtime.on("item_reposting_progress", (data) => { if (frm.doc.name !== data.name) { return; } - if (frm.doc.status == 'In Progress') { + if (frm.doc.status == "In Progress") { frm.doc.current_index = data.current_index; frm.doc.items_to_be_repost = data.items_to_be_repost; frm.dashboard.reset(); - frm.trigger('show_reposting_progress'); + frm.trigger("show_reposting_progress"); } }); }, - refresh: function(frm) { - if (frm.doc.status == "Failed" && frm.doc.docstatus==1) { - frm.add_custom_button(__('Restart'), function () { + refresh: function (frm) { + if (frm.doc.status == "Failed" && frm.doc.docstatus == 1) { + frm.add_custom_button(__("Restart"), function () { frm.trigger("restart_reposting"); }).addClass("btn-primary"); } - frm.trigger('show_reposting_progress'); + frm.trigger("show_reposting_progress"); - if (frm.doc.status === 'Queued' && frm.doc.docstatus === 1) { - frm.trigger('execute_reposting'); + if (frm.doc.status === "Queued" && frm.doc.docstatus === 1) { + frm.trigger("execute_reposting"); } }, execute_reposting(frm) { frm.add_custom_button(__("Start Reposting"), () => { frappe.call({ - method: 'erpnext.stock.doctype.repost_item_valuation.repost_item_valuation.execute_repost_item_valuation', - callback: function() { - frappe.msgprint(__('Reposting has been started in the background.')); - } + method: "erpnext.stock.doctype.repost_item_valuation.repost_item_valuation.execute_repost_item_valuation", + callback: function () { + frappe.msgprint(__("Reposting has been started in the background.")); + }, }); }); }, - show_reposting_progress: function(frm) { + show_reposting_progress: function (frm) { var bars = []; let total_count = frm.doc.items_to_be_repost ? JSON.parse(frm.doc.items_to_be_repost).length : 0; - let progress = flt(cint(frm.doc.current_index) / total_count * 100, 2) || 0.5; - var title = __('Reposting Completed {0}%', [progress]); + let progress = flt((cint(frm.doc.current_index) / total_count) * 100, 2) || 0.5; + var title = __("Reposting Completed {0}%", [progress]); bars.push({ - 'title': title, - 'width': progress + '%', - 'progress_class': 'progress-bar-success' + title: title, + width: progress + "%", + progress_class: "progress-bar-success", }); - frm.dashboard.add_progress(__('Reposting Progress'), bars); + frm.dashboard.add_progress(__("Reposting Progress"), bars); }, - restart_reposting: function(frm) { + restart_reposting: function (frm) { frappe.call({ method: "restart_reposting", doc: frm.doc, - callback: function(r) { + callback: function (r) { if (!r.exc) { frm.refresh(); } - } + }, }); - } + }, }); diff --git a/erpnext/stock/doctype/serial_no/serial_no.js b/erpnext/stock/doctype/serial_no/serial_no.js index 9d5555ed6313..88ed7abe2bdb 100644 --- a/erpnext/stock/doctype/serial_no/serial_no.js +++ b/erpnext/stock/doctype/serial_no/serial_no.js @@ -1,20 +1,20 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -cur_frm.add_fetch("customer", "customer_name", "customer_name") -cur_frm.add_fetch("supplier", "supplier_name", "supplier_name") +cur_frm.add_fetch("customer", "customer_name", "customer_name"); +cur_frm.add_fetch("supplier", "supplier_name", "supplier_name"); -cur_frm.add_fetch("item_code", "item_name", "item_name") -cur_frm.add_fetch("item_code", "description", "description") -cur_frm.add_fetch("item_code", "item_group", "item_group") -cur_frm.add_fetch("item_code", "brand", "brand") +cur_frm.add_fetch("item_code", "item_name", "item_name"); +cur_frm.add_fetch("item_code", "description", "description"); +cur_frm.add_fetch("item_code", "item_group", "item_group"); +cur_frm.add_fetch("item_code", "brand", "brand"); -cur_frm.cscript.onload = function() { - cur_frm.set_query("item_code", function() { - return erpnext.queries.item({"is_stock_item": 1, "has_serial_no": 1}) +cur_frm.cscript.onload = function () { + cur_frm.set_query("item_code", function () { + return erpnext.queries.item({ is_stock_item: 1, has_serial_no: 1 }); }); }; -frappe.ui.form.on("Serial No", "refresh", function(frm) { +frappe.ui.form.on("Serial No", "refresh", function (frm) { frm.toggle_enable("item_code", frm.doc.__islocal); }); diff --git a/erpnext/stock/doctype/serial_no/serial_no_list.js b/erpnext/stock/doctype/serial_no/serial_no_list.js index 7526d1d8a5c6..e085c2a93122 100644 --- a/erpnext/stock/doctype/serial_no/serial_no_list.js +++ b/erpnext/stock/doctype/serial_no/serial_no_list.js @@ -1,14 +1,21 @@ -frappe.listview_settings['Serial No'] = { +frappe.listview_settings["Serial No"] = { add_fields: ["item_code", "warehouse", "warranty_expiry_date", "delivery_document_type"], get_indicator: (doc) => { if (doc.delivery_document_type) { return [__("Delivered"), "green", "delivery_document_type,is,set"]; - } else if (doc.warranty_expiry_date && frappe.datetime.get_diff(doc.warranty_expiry_date, frappe.datetime.nowdate()) <= 0) { - return [__("Expired"), "red", "warranty_expiry_date,not in,|warranty_expiry_date,<=,Today|delivery_document_type,is,not set"]; + } else if ( + doc.warranty_expiry_date && + frappe.datetime.get_diff(doc.warranty_expiry_date, frappe.datetime.nowdate()) <= 0 + ) { + return [ + __("Expired"), + "red", + "warranty_expiry_date,not in,|warranty_expiry_date,<=,Today|delivery_document_type,is,not set", + ]; } else if (!doc.warehouse) { return [__("Inactive"), "grey", "warehouse,is,not set"]; } else { return [__("Active"), "green", "delivery_document_type,is,not set"]; } - } + }, }; diff --git a/erpnext/stock/doctype/shipment/shipment.js b/erpnext/stock/doctype/shipment/shipment.js index 13a17a259138..8843d3835311 100644 --- a/erpnext/stock/doctype/shipment/shipment.js +++ b/erpnext/stock/doctype/shipment/shipment.js @@ -1,34 +1,44 @@ // Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Shipment', { - address_query: function(frm, link_doctype, link_name, is_your_company_address) { +frappe.ui.form.on("Shipment", { + address_query: function (frm, link_doctype, link_name, is_your_company_address) { return { - query: 'frappe.contacts.doctype.address.address.address_query', + query: "frappe.contacts.doctype.address.address.address_query", filters: { link_doctype: link_doctype, link_name: link_name, - is_your_company_address: is_your_company_address - } + is_your_company_address: is_your_company_address, + }, }; }, - contact_query: function(frm, link_doctype, link_name) { + contact_query: function (frm, link_doctype, link_name) { return { - query: 'frappe.contacts.doctype.contact.contact.contact_query', + query: "frappe.contacts.doctype.contact.contact.contact_query", filters: { link_doctype: link_doctype, - link_name: link_name - } + link_name: link_name, + }, }; }, - onload: function(frm) { + onload: function (frm) { frm.set_query("delivery_address_name", () => { let delivery_to = `delivery_${frappe.model.scrub(frm.doc.delivery_to_type)}`; - return frm.events.address_query(frm, frm.doc.delivery_to_type, frm.doc[delivery_to], frm.doc.delivery_to_type === 'Company' ? 1 : 0); + return frm.events.address_query( + frm, + frm.doc.delivery_to_type, + frm.doc[delivery_to], + frm.doc.delivery_to_type === "Company" ? 1 : 0 + ); }); frm.set_query("pickup_address_name", () => { let pickup_from = `pickup_${frappe.model.scrub(frm.doc.pickup_from_type)}`; - return frm.events.address_query(frm, frm.doc.pickup_from_type, frm.doc[pickup_from], frm.doc.pickup_from_type === 'Company' ? 1 : 0); + return frm.events.address_query( + frm, + frm.doc.pickup_from_type, + frm.doc[pickup_from], + frm.doc.pickup_from_type === "Company" ? 1 : 0 + ); }); frm.set_query("delivery_contact_name", () => { let delivery_to = `delivery_${frappe.model.scrub(frm.doc.delivery_to_type)}`; @@ -38,8 +48,8 @@ frappe.ui.form.on('Shipment', { let pickup_from = `pickup_${frappe.model.scrub(frm.doc.pickup_from_type)}`; return frm.events.contact_query(frm, frm.doc.pickup_from_type, frm.doc[pickup_from]); }); - frm.set_query("delivery_note", "shipment_delivery_note", function() { - let customer = ''; + frm.set_query("delivery_note", "shipment_delivery_note", function () { + let customer = ""; if (frm.doc.delivery_to_type == "Customer") { customer = frm.doc.delivery_customer; } @@ -51,305 +61,329 @@ frappe.ui.form.on('Shipment', { filters: { customer: customer, docstatus: 1, - status: ["not in", ["Cancelled"]] - } + status: ["not in", ["Cancelled"]], + }, }; } }); }, - refresh: function() { - $('div[data-fieldname=pickup_address] > div > .clearfix').hide(); - $('div[data-fieldname=pickup_contact] > div > .clearfix').hide(); - $('div[data-fieldname=delivery_address] > div > .clearfix').hide(); - $('div[data-fieldname=delivery_contact] > div > .clearfix').hide(); + refresh: function () { + $("div[data-fieldname=pickup_address] > div > .clearfix").hide(); + $("div[data-fieldname=pickup_contact] > div > .clearfix").hide(); + $("div[data-fieldname=delivery_address] > div > .clearfix").hide(); + $("div[data-fieldname=delivery_contact] > div > .clearfix").hide(); }, - before_save: function(frm) { + before_save: function (frm) { let delivery_to = `delivery_${frappe.model.scrub(frm.doc.delivery_to_type)}`; frm.set_value("delivery_to", frm.doc[delivery_to]); let pickup_from = `pickup_${frappe.model.scrub(frm.doc.pickup_from_type)}`; frm.set_value("pickup", frm.doc[pickup_from]); }, - set_pickup_company_address: function(frm) { - frappe.db.get_value('Address', { - address_title: frm.doc.pickup_company, - is_your_company_address: 1 - }, 'name', (r) => { - frm.set_value("pickup_address_name", r.name); - }); + set_pickup_company_address: function (frm) { + frappe.db.get_value( + "Address", + { + address_title: frm.doc.pickup_company, + is_your_company_address: 1, + }, + "name", + (r) => { + frm.set_value("pickup_address_name", r.name); + } + ); }, - set_delivery_company_address: function(frm) { - frappe.db.get_value('Address', { - address_title: frm.doc.delivery_company, - is_your_company_address: 1 - }, 'name', (r) => { - frm.set_value("delivery_address_name", r.name); - }); + set_delivery_company_address: function (frm) { + frappe.db.get_value( + "Address", + { + address_title: frm.doc.delivery_company, + is_your_company_address: 1, + }, + "name", + (r) => { + frm.set_value("delivery_address_name", r.name); + } + ); }, - pickup_from_type: function(frm) { - if (frm.doc.pickup_from_type == 'Company') { - frm.set_value("pickup_company", frappe.defaults.get_default('company')); - frm.set_value("pickup_customer", ''); - frm.set_value("pickup_supplier", ''); + pickup_from_type: function (frm) { + if (frm.doc.pickup_from_type == "Company") { + frm.set_value("pickup_company", frappe.defaults.get_default("company")); + frm.set_value("pickup_customer", ""); + frm.set_value("pickup_supplier", ""); } else { - frm.trigger('clear_pickup_fields'); + frm.trigger("clear_pickup_fields"); } - if (frm.doc.pickup_from_type == 'Customer') { - frm.set_value("pickup_company", ''); - frm.set_value("pickup_supplier", ''); + if (frm.doc.pickup_from_type == "Customer") { + frm.set_value("pickup_company", ""); + frm.set_value("pickup_supplier", ""); } - if (frm.doc.pickup_from_type == 'Supplier') { - frm.set_value("pickup_customer", ''); - frm.set_value("pickup_company", ''); + if (frm.doc.pickup_from_type == "Supplier") { + frm.set_value("pickup_customer", ""); + frm.set_value("pickup_company", ""); } }, - delivery_to_type: function(frm) { - if (frm.doc.delivery_to_type == 'Company') { - frm.set_value("delivery_company", frappe.defaults.get_default('company')); - frm.set_value("delivery_customer", ''); - frm.set_value("delivery_supplier", ''); + delivery_to_type: function (frm) { + if (frm.doc.delivery_to_type == "Company") { + frm.set_value("delivery_company", frappe.defaults.get_default("company")); + frm.set_value("delivery_customer", ""); + frm.set_value("delivery_supplier", ""); } else { - frm.trigger('clear_delivery_fields'); + frm.trigger("clear_delivery_fields"); } - if (frm.doc.delivery_to_type == 'Customer') { - frm.set_value("delivery_company", ''); - frm.set_value("delivery_supplier", ''); + if (frm.doc.delivery_to_type == "Customer") { + frm.set_value("delivery_company", ""); + frm.set_value("delivery_supplier", ""); } - if (frm.doc.delivery_to_type == 'Supplier') { - frm.set_value("delivery_customer", ''); - frm.set_value("delivery_company", ''); + if (frm.doc.delivery_to_type == "Supplier") { + frm.set_value("delivery_customer", ""); + frm.set_value("delivery_company", ""); frm.toggle_display("shipment_delivery_note", false); } else { frm.toggle_display("shipment_delivery_note", true); } }, - delivery_address_name: function(frm) { - if (frm.doc.delivery_to_type == 'Company') { - erpnext.utils.get_address_display(frm, 'delivery_address_name', 'delivery_address', true); + delivery_address_name: function (frm) { + if (frm.doc.delivery_to_type == "Company") { + erpnext.utils.get_address_display(frm, "delivery_address_name", "delivery_address", true); } else { - erpnext.utils.get_address_display(frm, 'delivery_address_name', 'delivery_address', false); + erpnext.utils.get_address_display(frm, "delivery_address_name", "delivery_address", false); } }, - pickup_address_name: function(frm) { - if (frm.doc.pickup_from_type == 'Company') { - erpnext.utils.get_address_display(frm, 'pickup_address_name', 'pickup_address', true); + pickup_address_name: function (frm) { + if (frm.doc.pickup_from_type == "Company") { + erpnext.utils.get_address_display(frm, "pickup_address_name", "pickup_address", true); } else { - erpnext.utils.get_address_display(frm, 'pickup_address_name', 'pickup_address', false); + erpnext.utils.get_address_display(frm, "pickup_address_name", "pickup_address", false); } }, - get_contact_display: function(frm, contact_name, contact_type) { + get_contact_display: function (frm, contact_name, contact_type) { frappe.call({ method: "frappe.contacts.doctype.contact.contact.get_contact_details", args: { contact: contact_name }, - callback: function(r) { + callback: function (r) { if (r.message) { if (!(r.message.contact_email && (r.message.contact_phone || r.message.contact_mobile))) { - if (contact_type == 'Delivery') { - frm.set_value('delivery_contact_name', ''); - frm.set_value('delivery_contact', ''); + if (contact_type == "Delivery") { + frm.set_value("delivery_contact_name", ""); + frm.set_value("delivery_contact", ""); } else { - frm.set_value('pickup_contact_name', ''); - frm.set_value('pickup_contact', ''); + frm.set_value("pickup_contact_name", ""); + frm.set_value("pickup_contact", ""); } - frappe.throw(__("Email or Phone/Mobile of the Contact are mandatory to continue.") - + "
              " + __("Please set Email/Phone for the contact") - + ` ${contact_name}`); + frappe.throw( + __("Email or Phone/Mobile of the Contact are mandatory to continue.") + + "
              " + + __("Please set Email/Phone for the contact") + + ` ${contact_name}` + ); } let contact_display = r.message.contact_display; if (r.message.contact_email) { - contact_display += '
              ' + r.message.contact_email; + contact_display += "
              " + r.message.contact_email; } if (r.message.contact_phone) { - contact_display += '
              ' + r.message.contact_phone; + contact_display += "
              " + r.message.contact_phone; } if (r.message.contact_mobile && !r.message.contact_phone) { - contact_display += '
              ' + r.message.contact_mobile; + contact_display += "
              " + r.message.contact_mobile; } - if (contact_type == 'Delivery') { - frm.set_value('delivery_contact', contact_display); + if (contact_type == "Delivery") { + frm.set_value("delivery_contact", contact_display); if (r.message.contact_email) { - frm.set_value('delivery_contact_email', r.message.contact_email); + frm.set_value("delivery_contact_email", r.message.contact_email); } } else { - frm.set_value('pickup_contact', contact_display); + frm.set_value("pickup_contact", contact_display); if (r.message.contact_email) { - frm.set_value('pickup_contact_email', r.message.contact_email); + frm.set_value("pickup_contact_email", r.message.contact_email); } } } - } + }, }); }, - delivery_contact_name: function(frm) { + delivery_contact_name: function (frm) { if (frm.doc.delivery_contact_name) { - frm.events.get_contact_display(frm, frm.doc.delivery_contact_name, 'Delivery'); + frm.events.get_contact_display(frm, frm.doc.delivery_contact_name, "Delivery"); } }, - pickup_contact_name: function(frm) { + pickup_contact_name: function (frm) { if (frm.doc.pickup_contact_name) { - frm.events.get_contact_display(frm, frm.doc.pickup_contact_name, 'Pickup'); + frm.events.get_contact_display(frm, frm.doc.pickup_contact_name, "Pickup"); } }, - pickup_contact_person: function(frm) { + pickup_contact_person: function (frm) { if (frm.doc.pickup_contact_person) { frappe.call({ method: "erpnext.stock.doctype.shipment.shipment.get_company_contact", args: { user: frm.doc.pickup_contact_person }, - callback: function({ message }) { + callback: function ({ message }) { const r = message; let contact_display = `${r.first_name} ${r.last_name}`; if (r.email) { - contact_display += `
              ${ r.email }`; - frm.set_value('pickup_contact_email', r.email); + contact_display += `
              ${r.email}`; + frm.set_value("pickup_contact_email", r.email); } if (r.phone) { - contact_display += `
              ${ r.phone }`; + contact_display += `
              ${r.phone}`; } if (r.mobile_no && !r.phone) { - contact_display += `
              ${ r.mobile_no }`; + contact_display += `
              ${r.mobile_no}`; } - frm.set_value('pickup_contact', contact_display); - } + frm.set_value("pickup_contact", contact_display); + }, }); } else { - if (frm.doc.pickup_from_type === 'Company') { + if (frm.doc.pickup_from_type === "Company") { frappe.call({ method: "erpnext.stock.doctype.shipment.shipment.get_company_contact", args: { user: frappe.session.user }, - callback: function({ message }) { + callback: function ({ message }) { const r = message; let contact_display = `${r.first_name} ${r.last_name}`; if (r.email) { - contact_display += `
              ${ r.email }`; - frm.set_value('pickup_contact_email', r.email); + contact_display += `
              ${r.email}`; + frm.set_value("pickup_contact_email", r.email); } if (r.phone) { - contact_display += `
              ${ r.phone }`; + contact_display += `
              ${r.phone}`; } if (r.mobile_no && !r.phone) { - contact_display += `
              ${ r.mobile_no }`; + contact_display += `
              ${r.mobile_no}`; } - frm.set_value('pickup_contact', contact_display); - } + frm.set_value("pickup_contact", contact_display); + }, }); } } }, - set_company_contact: function(frm, delivery_type) { - frappe.db.get_value('User', { name: frappe.session.user }, ['full_name', 'last_name', 'email', 'phone', 'mobile_no'], (r) => { - if (!(r.last_name && r.email && (r.phone || r.mobile_no))) { - if (delivery_type == 'Delivery') { - frm.set_value('delivery_company', ''); - frm.set_value('delivery_contact', ''); - } else { - frm.set_value('pickup_company', ''); - frm.set_value('pickup_contact', ''); + set_company_contact: function (frm, delivery_type) { + frappe.db.get_value( + "User", + { name: frappe.session.user }, + ["full_name", "last_name", "email", "phone", "mobile_no"], + (r) => { + if (!(r.last_name && r.email && (r.phone || r.mobile_no))) { + if (delivery_type == "Delivery") { + frm.set_value("delivery_company", ""); + frm.set_value("delivery_contact", ""); + } else { + frm.set_value("pickup_company", ""); + frm.set_value("pickup_contact", ""); + } + frappe.throw( + __("Last Name, Email or Phone/Mobile of the user are mandatory to continue.") + + "
              " + + __("Please first set Last Name, Email and Phone for the user") + + ` ${frappe.session.user}` + ); } - frappe.throw(__("Last Name, Email or Phone/Mobile of the user are mandatory to continue.") + "
              " - + __("Please first set Last Name, Email and Phone for the user") - + ` ${frappe.session.user}`); - } - let contact_display = r.full_name; - if (r.email) { - contact_display += '
              ' + r.email; - } - if (r.phone) { - contact_display += '
              ' + r.phone; - } - if (r.mobile_no && !r.phone) { - contact_display += '
              ' + r.mobile_no; - } - if (delivery_type == 'Delivery') { - frm.set_value('delivery_contact', contact_display); + let contact_display = r.full_name; if (r.email) { - frm.set_value('delivery_contact_email', r.email); + contact_display += "
              " + r.email; } - } else { - frm.set_value('pickup_contact', contact_display); - if (r.email) { - frm.set_value('pickup_contact_email', r.email); + if (r.phone) { + contact_display += "
              " + r.phone; + } + if (r.mobile_no && !r.phone) { + contact_display += "
              " + r.mobile_no; + } + if (delivery_type == "Delivery") { + frm.set_value("delivery_contact", contact_display); + if (r.email) { + frm.set_value("delivery_contact_email", r.email); + } + } else { + frm.set_value("pickup_contact", contact_display); + if (r.email) { + frm.set_value("pickup_contact_email", r.email); + } } } - }); - frm.set_value('pickup_contact_person', frappe.session.user); + ); + frm.set_value("pickup_contact_person", frappe.session.user); }, - pickup_company: function(frm) { - if (frm.doc.pickup_from_type == 'Company' && frm.doc.pickup_company) { - frm.trigger('set_pickup_company_address'); - frm.events.set_company_contact(frm, 'Pickup'); + pickup_company: function (frm) { + if (frm.doc.pickup_from_type == "Company" && frm.doc.pickup_company) { + frm.trigger("set_pickup_company_address"); + frm.events.set_company_contact(frm, "Pickup"); } }, - delivery_company: function(frm) { - if (frm.doc.delivery_to_type == 'Company' && frm.doc.delivery_company) { - frm.trigger('set_delivery_company_address'); - frm.events.set_company_contact(frm, 'Delivery'); + delivery_company: function (frm) { + if (frm.doc.delivery_to_type == "Company" && frm.doc.delivery_company) { + frm.trigger("set_delivery_company_address"); + frm.events.set_company_contact(frm, "Delivery"); } }, - delivery_customer: function(frm) { - frm.trigger('clear_delivery_fields'); + delivery_customer: function (frm) { + frm.trigger("clear_delivery_fields"); if (frm.doc.delivery_customer) { - frm.events.set_address_name(frm, 'Customer', frm.doc.delivery_customer, 'Delivery'); - frm.events.set_contact_name(frm, 'Customer', frm.doc.delivery_customer, 'Delivery'); + frm.events.set_address_name(frm, "Customer", frm.doc.delivery_customer, "Delivery"); + frm.events.set_contact_name(frm, "Customer", frm.doc.delivery_customer, "Delivery"); } }, - delivery_supplier: function(frm) { - frm.trigger('clear_delivery_fields'); + delivery_supplier: function (frm) { + frm.trigger("clear_delivery_fields"); if (frm.doc.delivery_supplier) { - frm.events.set_address_name(frm, 'Supplier', frm.doc.delivery_supplier, 'Delivery'); - frm.events.set_contact_name(frm, 'Supplier', frm.doc.delivery_supplier, 'Delivery'); + frm.events.set_address_name(frm, "Supplier", frm.doc.delivery_supplier, "Delivery"); + frm.events.set_contact_name(frm, "Supplier", frm.doc.delivery_supplier, "Delivery"); } }, - pickup_customer: function(frm) { + pickup_customer: function (frm) { if (frm.doc.pickup_customer) { - frm.events.set_address_name(frm, 'Customer', frm.doc.pickup_customer, 'Pickup'); - frm.events.set_contact_name(frm, 'Customer', frm.doc.pickup_customer, 'Pickup'); + frm.events.set_address_name(frm, "Customer", frm.doc.pickup_customer, "Pickup"); + frm.events.set_contact_name(frm, "Customer", frm.doc.pickup_customer, "Pickup"); } }, - pickup_supplier: function(frm) { + pickup_supplier: function (frm) { if (frm.doc.pickup_supplier) { - frm.events.set_address_name(frm, 'Supplier', frm.doc.pickup_supplier, 'Pickup'); - frm.events.set_contact_name(frm, 'Supplier', frm.doc.pickup_supplier, 'Pickup'); + frm.events.set_address_name(frm, "Supplier", frm.doc.pickup_supplier, "Pickup"); + frm.events.set_contact_name(frm, "Supplier", frm.doc.pickup_supplier, "Pickup"); } }, - set_address_name: function(frm, ref_doctype, ref_docname, delivery_type) { + set_address_name: function (frm, ref_doctype, ref_docname, delivery_type) { frappe.call({ method: "erpnext.stock.doctype.shipment.shipment.get_address_name", args: { ref_doctype: ref_doctype, - docname: ref_docname + docname: ref_docname, }, - callback: function(r) { + callback: function (r) { if (r.message) { - if (delivery_type == 'Delivery') { - frm.set_value('delivery_address_name', r.message); + if (delivery_type == "Delivery") { + frm.set_value("delivery_address_name", r.message); } else { - frm.set_value('pickup_address_name', r.message); + frm.set_value("pickup_address_name", r.message); } } - } + }, }); }, - set_contact_name: function(frm, ref_doctype, ref_docname, delivery_type) { + set_contact_name: function (frm, ref_doctype, ref_docname, delivery_type) { frappe.call({ method: "erpnext.stock.doctype.shipment.shipment.get_contact_name", args: { ref_doctype: ref_doctype, - docname: ref_docname + docname: ref_docname, }, - callback: function(r) { + callback: function (r) { if (r.message) { - if (delivery_type == 'Delivery') { - frm.set_value('delivery_contact_name', r.message); + if (delivery_type == "Delivery") { + frm.set_value("delivery_contact_name", r.message); } else { - frm.set_value('pickup_contact_name', r.message); + frm.set_value("pickup_contact_name", r.message); } } - } + }, }); }, - add_template: function(frm) { + add_template: function (frm) { if (frm.doc.parcel_template) { frappe.model.with_doc("Shipment Parcel Template", frm.doc.parcel_template, () => { - let parcel_template = frappe.model.get_doc("Shipment Parcel Template", frm.doc.parcel_template); + let parcel_template = frappe.model.get_doc( + "Shipment Parcel Template", + frm.doc.parcel_template + ); let row = frappe.model.add_child(frm.doc, "Shipment Parcel", "shipment_parcel"); row.length = parcel_template.length; row.width = parcel_template.width; @@ -359,56 +393,71 @@ frappe.ui.form.on('Shipment', { }); } }, - pickup_date: function(frm) { + pickup_date: function (frm) { if (frm.doc.pickup_date < frappe.datetime.get_today()) { frappe.throw(__("Pickup Date cannot be before this day")); } }, - clear_pickup_fields: function(frm) { - let fields = ["pickup_address_name", "pickup_contact_name", "pickup_address", "pickup_contact", "pickup_contact_email", "pickup_contact_person"]; + clear_pickup_fields: function (frm) { + let fields = [ + "pickup_address_name", + "pickup_contact_name", + "pickup_address", + "pickup_contact", + "pickup_contact_email", + "pickup_contact_person", + ]; for (let field of fields) { - frm.set_value(field, ''); + frm.set_value(field, ""); } }, - clear_delivery_fields: function(frm) { - let fields = ["delivery_address_name", "delivery_contact_name", "delivery_address", "delivery_contact", "delivery_contact_email"]; + clear_delivery_fields: function (frm) { + let fields = [ + "delivery_address_name", + "delivery_contact_name", + "delivery_address", + "delivery_contact", + "delivery_contact_email", + ]; for (let field of fields) { - frm.set_value(field, ''); + frm.set_value(field, ""); } }, - remove_email_row: function(frm, table, fieldname) { - $.each(frm.doc[table] || [], function(i, detail) { + remove_email_row: function (frm, table, fieldname) { + $.each(frm.doc[table] || [], function (i, detail) { if (detail.email === fieldname) { cur_frm.get_field(table).grid.grid_rows[i].remove(); } }); - } + }, }); -frappe.ui.form.on('Shipment Delivery Note', { - delivery_note: function(frm, cdt, cdn) { +frappe.ui.form.on("Shipment Delivery Note", { + delivery_note: function (frm, cdt, cdn) { let row = locals[cdt][cdn]; if (row.delivery_note) { let row_index = row.idx - 1; - if (validate_duplicate(frm, 'shipment_delivery_note', row.delivery_note, row_index)) { - frappe.throw(__("You have entered a duplicate Delivery Note on Row") + ` ${row.idx}. ` + __("Please rectify and try again.")); + if (validate_duplicate(frm, "shipment_delivery_note", row.delivery_note, row_index)) { + frappe.throw( + __("You have entered a duplicate Delivery Note on Row") + + ` ${row.idx}. ` + + __("Please rectify and try again.") + ); } } }, - grand_total: function(frm, cdt, cdn) { + grand_total: function (frm, cdt, cdn) { let row = locals[cdt][cdn]; if (row.grand_total) { - var value_of_goods = parseFloat(frm.doc.value_of_goods)+parseFloat(row.grand_total); + var value_of_goods = parseFloat(frm.doc.value_of_goods) + parseFloat(row.grand_total); frm.set_value("value_of_goods", Math.round(value_of_goods)); frm.refresh_fields("value_of_goods"); } }, }); -var validate_duplicate = function(frm, table, fieldname, index) { - return ( - table === 'shipment_delivery_note' - ? frm.doc[table].some((detail, i) => detail.delivery_note === fieldname && !(index === i)) - : frm.doc[table].some((detail, i) => detail.email === fieldname && !(index === i)) - ); +var validate_duplicate = function (frm, table, fieldname, index) { + return table === "shipment_delivery_note" + ? frm.doc[table].some((detail, i) => detail.delivery_note === fieldname && !(index === i)) + : frm.doc[table].some((detail, i) => detail.email === fieldname && !(index === i)); }; diff --git a/erpnext/stock/doctype/shipment/shipment_list.js b/erpnext/stock/doctype/shipment/shipment_list.js index ae6a3c154e80..b333ccc817fb 100644 --- a/erpnext/stock/doctype/shipment/shipment_list.js +++ b/erpnext/stock/doctype/shipment/shipment_list.js @@ -1,8 +1,8 @@ -frappe.listview_settings['Shipment'] = { +frappe.listview_settings["Shipment"] = { add_fields: ["status"], - get_indicator: function(doc) { - if (doc.status=='Booked') { + get_indicator: function (doc) { + if (doc.status == "Booked") { return [__("Booked"), "green"]; } - } + }, }; diff --git a/erpnext/stock/doctype/shipment_parcel_template/shipment_parcel_template.js b/erpnext/stock/doctype/shipment_parcel_template/shipment_parcel_template.js index 785a3b304deb..3ef90fa81f37 100644 --- a/erpnext/stock/doctype/shipment_parcel_template/shipment_parcel_template.js +++ b/erpnext/stock/doctype/shipment_parcel_template/shipment_parcel_template.js @@ -1,8 +1,7 @@ // Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Shipment Parcel Template', { +frappe.ui.form.on("Shipment Parcel Template", { // refresh: function(frm) { - // } }); diff --git a/erpnext/stock/doctype/stock_entry/stock_entry_list.js b/erpnext/stock/doctype/stock_entry/stock_entry_list.js index af29d495ff7b..8a1c808cd91f 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry_list.js +++ b/erpnext/stock/doctype/stock_entry/stock_entry_list.js @@ -1,19 +1,25 @@ -frappe.listview_settings['Stock Entry'] = { - add_fields: ["`tabStock Entry`.`from_warehouse`", "`tabStock Entry`.`to_warehouse`", - "`tabStock Entry`.`purpose`", "`tabStock Entry`.`work_order`", "`tabStock Entry`.`bom_no`", - "`tabStock Entry`.`is_return`"], +frappe.listview_settings["Stock Entry"] = { + add_fields: [ + "`tabStock Entry`.`from_warehouse`", + "`tabStock Entry`.`to_warehouse`", + "`tabStock Entry`.`purpose`", + "`tabStock Entry`.`work_order`", + "`tabStock Entry`.`bom_no`", + "`tabStock Entry`.`is_return`", + ], get_indicator: function (doc) { - if(doc.is_return===1 && doc.purpose === "Material Transfer for Manufacture") { - return [__("Material Returned from WIP"), "orange", - "is_return,=,1|purpose,=,Material Transfer for Manufacture|docstatus,<,2"]; + if (doc.is_return === 1 && doc.purpose === "Material Transfer for Manufacture") { + return [ + __("Material Returned from WIP"), + "orange", + "is_return,=,1|purpose,=,Material Transfer for Manufacture|docstatus,<,2", + ]; } else if (doc.docstatus === 0) { return [__("Draft"), "red", "docstatus,=,0"]; - - } else if (doc.purpose === 'Send to Warehouse' && doc.per_transferred < 100) { + } else if (doc.purpose === "Send to Warehouse" && doc.per_transferred < 100) { // not delivered & overdue return [__("Goods In Transit"), "grey", "per_transferred,<,100"]; - - } else if (doc.purpose === 'Send to Warehouse' && doc.per_transferred === 100) { + } else if (doc.purpose === "Send to Warehouse" && doc.per_transferred === 100) { return [__("Goods Transferred"), "green", "per_transferred,=,100"]; } else if (doc.docstatus === 2) { return [__("Canceled"), "red", "docstatus,=,2"]; @@ -22,21 +28,30 @@ frappe.listview_settings['Stock Entry'] = { } }, column_render: { - "from_warehouse": function(doc) { + from_warehouse: function (doc) { var html = ""; - if(doc.from_warehouse) { - html += '' - +doc.from_warehouse+' '; + if (doc.from_warehouse) { + html += + '' + + doc.from_warehouse + + " "; } // if(doc.from_warehouse || doc.to_warehouse) { // html += ' '; // } - if(doc.to_warehouse) { - html += ''+doc.to_warehouse+''; + if (doc.to_warehouse) { + html += + '' + + doc.to_warehouse + + ""; } return html; - } - } + }, + }, }; diff --git a/erpnext/stock/doctype/stock_entry_type/stock_entry_type.js b/erpnext/stock/doctype/stock_entry_type/stock_entry_type.js index c554278334be..21e60fbcae46 100644 --- a/erpnext/stock/doctype/stock_entry_type/stock_entry_type.js +++ b/erpnext/stock/doctype/stock_entry_type/stock_entry_type.js @@ -1,8 +1,7 @@ // Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Stock Entry Type', { +frappe.ui.form.on("Stock Entry Type", { // refresh: function(frm) { - // } }); diff --git a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.js b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.js index 23018aa615b8..7196dc9f1e3a 100644 --- a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.js +++ b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.js @@ -1,8 +1,8 @@ // Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Stock Ledger Entry', { - refresh: function(frm) { - frm.page.btn_secondary.hide() - } +frappe.ui.form.on("Stock Ledger Entry", { + refresh: function (frm) { + frm.page.btn_secondary.hide(); + }, }); diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.js b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.js index 1415aa361644..0abc52644490 100644 --- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.js +++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.js @@ -5,29 +5,29 @@ frappe.provide("erpnext.stock"); frappe.provide("erpnext.accounts.dimensions"); frappe.ui.form.on("Stock Reconciliation", { - onload: function(frm) { + onload: function (frm) { frm.add_fetch("item_code", "item_name", "item_name"); // end of life - frm.set_query("item_code", "items", function(doc, cdt, cdn) { + frm.set_query("item_code", "items", function (doc, cdt, cdn) { return { query: "erpnext.controllers.queries.item_query", - filters:{ - "is_stock_item": 1 - } - } + filters: { + is_stock_item: 1, + }, + }; }); - frm.set_query("batch_no", "items", function(doc, cdt, cdn) { + frm.set_query("batch_no", "items", function (doc, cdt, cdn) { var item = locals[cdt][cdn]; return { filters: { - 'item': item.item_code - } + item: item.item_code, + }, }; }); if (frm.doc.company) { - erpnext.queries.setup_queries(frm, "Warehouse", function() { + erpnext.queries.setup_queries(frm, "Warehouse", function () { return erpnext.queries.warehouse(frm.doc); }); } @@ -39,56 +39,56 @@ frappe.ui.form.on("Stock Reconciliation", { erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype); }, - company: function(frm) { + company: function (frm) { erpnext.accounts.dimensions.update_dimension(frm, frm.doctype); }, - refresh: function(frm) { - if(frm.doc.docstatus < 1) { - frm.add_custom_button(__("Fetch Items from Warehouse"), function() { + refresh: function (frm) { + if (frm.doc.docstatus < 1) { + frm.add_custom_button(__("Fetch Items from Warehouse"), function () { frm.events.get_items(frm); }); } - if(frm.doc.company) { + if (frm.doc.company) { frm.trigger("toggle_display_account_head"); } }, - scan_barcode: function(frm) { - const barcode_scanner = new erpnext.utils.BarcodeScanner({frm:frm}); + scan_barcode: function (frm) { + const barcode_scanner = new erpnext.utils.BarcodeScanner({ frm: frm }); barcode_scanner.process_scan(); }, - scan_mode: function(frm) { + scan_mode: function (frm) { if (frm.doc.scan_mode) { frappe.show_alert({ message: __("Scan mode enabled, existing quantity will not be fetched."), - indicator: "green" + indicator: "green", }); } }, - set_warehouse: function(frm) { - let transaction_controller = new erpnext.TransactionController({frm:frm}); + set_warehouse: function (frm) { + let transaction_controller = new erpnext.TransactionController({ frm: frm }); transaction_controller.autofill_warehouse(frm.doc.items, "warehouse", frm.doc.set_warehouse); }, - get_items: function(frm) { + get_items: function (frm) { let fields = [ { - label: 'Warehouse', - fieldname: 'warehouse', - fieldtype: 'Link', - options: 'Warehouse', + label: "Warehouse", + fieldname: "warehouse", + fieldtype: "Link", + options: "Warehouse", reqd: 1, - "get_query": function() { + get_query: function () { return { - "filters": { - "company": frm.doc.company, - } + filters: { + company: frm.doc.company, + }, }; - } + }, }, { label: "Item Code", @@ -99,57 +99,62 @@ frappe.ui.form.on("Stock Reconciliation", { { label: __("Ignore Empty Stock"), fieldname: "ignore_empty_stock", - fieldtype: "Check" - } + fieldtype: "Check", + }, ]; - frappe.prompt(fields, function(data) { - frappe.call({ - method: "erpnext.stock.doctype.stock_reconciliation.stock_reconciliation.get_items", - args: { - warehouse: data.warehouse, - posting_date: frm.doc.posting_date, - posting_time: frm.doc.posting_time, - company: frm.doc.company, - item_code: data.item_code, - ignore_empty_stock: data.ignore_empty_stock - }, - callback: function(r) { - if (r.exc || !r.message || !r.message.length) return; - - frm.clear_table("items"); - - r.message.forEach((row) => { - let item = frm.add_child("items"); - $.extend(item, row); - - item.qty = item.qty || 0; - item.valuation_rate = item.valuation_rate || 0; - }); - frm.refresh_field("items"); - } - }); - }, __("Get Items"), __("Update")); + frappe.prompt( + fields, + function (data) { + frappe.call({ + method: "erpnext.stock.doctype.stock_reconciliation.stock_reconciliation.get_items", + args: { + warehouse: data.warehouse, + posting_date: frm.doc.posting_date, + posting_time: frm.doc.posting_time, + company: frm.doc.company, + item_code: data.item_code, + ignore_empty_stock: data.ignore_empty_stock, + }, + callback: function (r) { + if (r.exc || !r.message || !r.message.length) return; + + frm.clear_table("items"); + + r.message.forEach((row) => { + let item = frm.add_child("items"); + $.extend(item, row); + + item.qty = item.qty || 0; + item.valuation_rate = item.valuation_rate || 0; + }); + frm.refresh_field("items"); + }, + }); + }, + __("Get Items"), + __("Update") + ); }, - posting_date: function(frm) { + posting_date: function (frm) { frm.trigger("set_valuation_rate_and_qty_for_all_items"); }, - posting_time: function(frm) { + posting_time: function (frm) { frm.trigger("set_valuation_rate_and_qty_for_all_items"); }, - set_valuation_rate_and_qty_for_all_items: function(frm) { - frm.doc.items.forEach(row => { + set_valuation_rate_and_qty_for_all_items: function (frm) { + frm.doc.items.forEach((row) => { frm.events.set_valuation_rate_and_qty(frm, row.doctype, row.name); }); }, - set_valuation_rate_and_qty: function(frm, cdt, cdn) { + set_valuation_rate_and_qty: function (frm, cdt, cdn) { var d = frappe.model.get_doc(cdt, cdn); - if(d.item_code && d.warehouse) { + if (d.item_code && d.warehouse) { frappe.call({ method: "erpnext.stock.doctype.stock_reconciliation.stock_reconciliation.get_stock_balance_for", args: { @@ -157,9 +162,9 @@ frappe.ui.form.on("Stock Reconciliation", { warehouse: d.warehouse, posting_date: frm.doc.posting_date, posting_time: frm.doc.posting_time, - batch_no: d.batch_no + batch_no: d.batch_no, }, - callback: function(r) { + callback: function (r) { const row = frappe.model.get_doc(cdt, cdn); if (!frm.doc.scan_mode) { frappe.model.set_value(cdt, cdn, "qty", r.message.qty); @@ -174,12 +179,12 @@ frappe.ui.form.on("Stock Reconciliation", { if (frm.doc.purpose == "Stock Reconciliation" && !frm.doc.scan_mode) { frappe.model.set_value(cdt, cdn, "serial_no", r.message.serial_nos); } - } + }, }); } }, - set_amount_quantity: function(doc, cdt, cdn) { + set_amount_quantity: function (doc, cdt, cdn) { var d = frappe.model.get_doc(cdt, cdn); if (d.qty & d.valuation_rate) { frappe.model.set_value(cdt, cdn, "amount", flt(d.qty) * flt(d.valuation_rate)); @@ -187,37 +192,38 @@ frappe.ui.form.on("Stock Reconciliation", { frappe.model.set_value(cdt, cdn, "amount_difference", flt(d.amount) - flt(d.current_amount)); } }, - company: function(frm) { + company: function (frm) { frm.trigger("toggle_display_account_head"); }, - toggle_display_account_head: function(frm) { - frm.toggle_display(['expense_account', 'cost_center'], - erpnext.is_perpetual_inventory_enabled(frm.doc.company)); + toggle_display_account_head: function (frm) { + frm.toggle_display( + ["expense_account", "cost_center"], + erpnext.is_perpetual_inventory_enabled(frm.doc.company) + ); }, - purpose: function(frm) { + purpose: function (frm) { frm.trigger("set_expense_account"); }, - set_expense_account: function(frm) { + set_expense_account: function (frm) { if (frm.doc.company && erpnext.is_perpetual_inventory_enabled(frm.doc.company)) { return frm.call({ method: "erpnext.stock.doctype.stock_reconciliation.stock_reconciliation.get_difference_account", args: { - "purpose": frm.doc.purpose, - "company": frm.doc.company + purpose: frm.doc.purpose, + company: frm.doc.company, }, - callback: function(r) { + callback: function (r) { if (!r.exc) { frm.set_value("expense_account", r.message); } - } + }, }); } - } + }, }); frappe.ui.form.on("Stock Reconciliation Item", { - - warehouse: function(frm, cdt, cdn) { + warehouse: function (frm, cdt, cdn) { var child = locals[cdt][cdn]; if (child.batch_no && !frm.doc.scan_mode) { frappe.model.set_value(child.cdt, child.cdn, "batch_no", ""); @@ -226,7 +232,7 @@ frappe.ui.form.on("Stock Reconciliation Item", { frm.events.set_valuation_rate_and_qty(frm, cdt, cdn); }, - item_code: function(frm, cdt, cdn) { + item_code: function (frm, cdt, cdn) { var child = locals[cdt][cdn]; if (child.batch_no && !frm.doc.scan_mode) { frappe.model.set_value(cdt, cdn, "batch_no", ""); @@ -235,34 +241,33 @@ frappe.ui.form.on("Stock Reconciliation Item", { frm.events.set_valuation_rate_and_qty(frm, cdt, cdn); }, - batch_no: function(frm, cdt, cdn) { + batch_no: function (frm, cdt, cdn) { frm.events.set_valuation_rate_and_qty(frm, cdt, cdn); }, - qty: function(frm, cdt, cdn) { + qty: function (frm, cdt, cdn) { frm.events.set_amount_quantity(frm, cdt, cdn); }, - valuation_rate: function(frm, cdt, cdn) { + valuation_rate: function (frm, cdt, cdn) { frm.events.set_amount_quantity(frm, cdt, cdn); }, - serial_no: function(frm, cdt, cdn) { + serial_no: function (frm, cdt, cdn) { var child = locals[cdt][cdn]; if (child.serial_no) { - const serial_nos = child.serial_no.trim().split('\n'); + const serial_nos = child.serial_no.trim().split("\n"); frappe.model.set_value(cdt, cdn, "qty", serial_nos.length); } }, - items_add: function(frm, cdt, cdn) { + items_add: function (frm, cdt, cdn) { var item = frappe.get_doc(cdt, cdn); if (!item.warehouse && frm.doc.set_warehouse) { frappe.model.set_value(cdt, cdn, "warehouse", frm.doc.set_warehouse); } }, - }); erpnext.stock.StockReconciliation = class StockReconciliation extends erpnext.stock.StockController { @@ -274,37 +279,36 @@ erpnext.stock.StockReconciliation = class StockReconciliation extends erpnext.st if (me.frm.doc.company && erpnext.is_perpetual_inventory_enabled(me.frm.doc.company)) { this.frm.add_fetch("company", "cost_center", "cost_center"); } - this.frm.fields_dict["expense_account"].get_query = function() { - if(erpnext.is_perpetual_inventory_enabled(me.frm.doc.company)) { + this.frm.fields_dict["expense_account"].get_query = function () { + if (erpnext.is_perpetual_inventory_enabled(me.frm.doc.company)) { return { - "filters": { - 'company': me.frm.doc.company, - "is_group": 0 - } - } + filters: { + company: me.frm.doc.company, + is_group: 0, + }, + }; } - } - this.frm.fields_dict["cost_center"].get_query = function() { - if(erpnext.is_perpetual_inventory_enabled(me.frm.doc.company)) { + }; + this.frm.fields_dict["cost_center"].get_query = function () { + if (erpnext.is_perpetual_inventory_enabled(me.frm.doc.company)) { return { - "filters": { - 'company': me.frm.doc.company, - "is_group": 0 - } - } + filters: { + company: me.frm.doc.company, + is_group: 0, + }, + }; } - } + }; } refresh() { - if(this.frm.doc.docstatus > 0) { + if (this.frm.doc.docstatus > 0) { this.show_stock_ledger(); if (erpnext.is_perpetual_inventory_enabled(this.frm.doc.company)) { this.show_general_ledger(); } } } - }; -cur_frm.cscript = new erpnext.stock.StockReconciliation({frm: cur_frm}); +cur_frm.cscript = new erpnext.stock.StockReconciliation({ frm: cur_frm }); diff --git a/erpnext/stock/doctype/stock_reposting_settings/stock_reposting_settings.js b/erpnext/stock/doctype/stock_reposting_settings/stock_reposting_settings.js index 5f81679bade8..e8c14372416b 100644 --- a/erpnext/stock/doctype/stock_reposting_settings/stock_reposting_settings.js +++ b/erpnext/stock/doctype/stock_reposting_settings/stock_reposting_settings.js @@ -1,23 +1,23 @@ // Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Stock Reposting Settings', { - refresh: function(frm) { - frm.trigger('convert_to_item_based_reposting'); +frappe.ui.form.on("Stock Reposting Settings", { + refresh: function (frm) { + frm.trigger("convert_to_item_based_reposting"); }, - convert_to_item_based_reposting: function(frm) { - frm.add_custom_button(__('Convert to Item Based Reposting'), function() { + convert_to_item_based_reposting: function (frm) { + frm.add_custom_button(__("Convert to Item Based Reposting"), function () { frm.call({ - method: 'convert_to_item_wh_reposting', + method: "convert_to_item_wh_reposting", frezz: true, doc: frm.doc, - callback: function(r) { + callback: function (r) { if (!r.exc) { frm.reload_doc(); } - } - }) - }) - } + }, + }); + }); + }, }); diff --git a/erpnext/stock/doctype/stock_settings/stock_settings.js b/erpnext/stock/doctype/stock_settings/stock_settings.js index 89ac4b5fc907..1972b1937325 100644 --- a/erpnext/stock/doctype/stock_settings/stock_settings.js +++ b/erpnext/stock/doctype/stock_settings/stock_settings.js @@ -1,29 +1,31 @@ // Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Stock Settings', { - refresh: function(frm) { - let filters = function() { +frappe.ui.form.on("Stock Settings", { + refresh: function (frm) { + let filters = function () { return { - filters : { - is_group : 0 - } + filters: { + is_group: 0, + }, }; }; frm.set_query("default_warehouse", filters); frm.set_query("sample_retention_warehouse", filters); }, - allow_negative_stock: function(frm) { + allow_negative_stock: function (frm) { if (!frm.doc.allow_negative_stock) { return; } - let msg = __("Using negative stock disables FIFO/Moving average valuation when inventory is negative."); + let msg = __( + "Using negative stock disables FIFO/Moving average valuation when inventory is negative." + ); msg += " "; - msg += __("This is considered dangerous from accounting point of view.") + msg += __("This is considered dangerous from accounting point of view."); msg += "
              "; - msg += ("Do you still want to enable negative inventory?"); + msg += "Do you still want to enable negative inventory?"; frappe.confirm( msg, @@ -32,5 +34,5 @@ frappe.ui.form.on('Stock Settings', { frm.set_value("allow_negative_stock", 0); } ); - } + }, }); diff --git a/erpnext/stock/doctype/uom_category/uom_category.js b/erpnext/stock/doctype/uom_category/uom_category.js index 48026da1bed4..b53190f7482b 100644 --- a/erpnext/stock/doctype/uom_category/uom_category.js +++ b/erpnext/stock/doctype/uom_category/uom_category.js @@ -1,8 +1,6 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('UOM Category', { - refresh: function() { - - } +frappe.ui.form.on("UOM Category", { + refresh: function () {}, }); diff --git a/erpnext/stock/doctype/variant_field/variant_field.js b/erpnext/stock/doctype/variant_field/variant_field.js index 13db3f9272d1..8455d9125318 100644 --- a/erpnext/stock/doctype/variant_field/variant_field.js +++ b/erpnext/stock/doctype/variant_field/variant_field.js @@ -1,8 +1,6 @@ // Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Variant Field', { - refresh: function() { - - } +frappe.ui.form.on("Variant Field", { + refresh: function () {}, }); diff --git a/erpnext/stock/doctype/warehouse/warehouse.js b/erpnext/stock/doctype/warehouse/warehouse.js index 746a1cbaf17b..4f44db023dd3 100644 --- a/erpnext/stock/doctype/warehouse/warehouse.js +++ b/erpnext/stock/doctype/warehouse/warehouse.js @@ -35,18 +35,15 @@ frappe.ui.form.on("Warehouse", { refresh: function (frm) { frm.toggle_display("warehouse_name", frm.doc.__islocal); - frm.toggle_display( - ["address_html", "contact_html"], - !frm.doc.__islocal - ); + frm.toggle_display(["address_html", "contact_html"], !frm.doc.__islocal); if (!frm.is_new()) { frappe.contacts.render_address_and_contact(frm); let enable_toggle = frm.doc.disabled ? "Enable" : "Disable"; frm.add_custom_button(__(enable_toggle), () => { - frm.set_value('disabled', 1 - frm.doc.disabled); - frm.save() + frm.set_value("disabled", 1 - frm.doc.disabled); + frm.save(); }); frm.add_custom_button(__("Stock Balance"), function () { @@ -61,25 +58,20 @@ frappe.ui.form.on("Warehouse", { : __("Convert to Group", null, "Warehouse"), function () { convert_to_group_or_ledger(frm); - }, + } ); - } else { frappe.contacts.clear_address_and_contact(frm); } - if (!frm.doc.is_group && frm.doc.__onload && frm.doc.__onload.account) { - frm.add_custom_button( - __("General Ledger", null, "Warehouse"), - function () { - frappe.route_options = { - account: frm.doc.__onload.account, - company: frm.doc.company, - }; - frappe.set_route("query-report", "General Ledger"); - } - ); + frm.add_custom_button(__("General Ledger", null, "Warehouse"), function () { + frappe.route_options = { + account: frm.doc.__onload.account, + company: frm.doc.company, + }; + frappe.set_route("query-report", "General Ledger"); + }); } frm.toggle_enable(["is_group", "company"], false); diff --git a/erpnext/stock/doctype/warehouse/warehouse_tree.js b/erpnext/stock/doctype/warehouse/warehouse_tree.js index eb635e6757d6..d9070b33d104 100644 --- a/erpnext/stock/doctype/warehouse/warehouse_tree.js +++ b/erpnext/stock/doctype/warehouse/warehouse_tree.js @@ -1,20 +1,25 @@ -frappe.treeview_settings['Warehouse'] = { +frappe.treeview_settings["Warehouse"] = { get_tree_nodes: "erpnext.stock.doctype.warehouse.warehouse.get_children", add_tree_node: "erpnext.stock.doctype.warehouse.warehouse.add_node", get_tree_root: false, root_label: "Warehouses", - filters: [{ - fieldname: "company", - fieldtype:"Select", - options: erpnext.utils.get_tree_options("company"), - label: __("Company"), - default: erpnext.utils.get_tree_default("company") - }], - fields:[ - {fieldtype:'Data', fieldname: 'warehouse_name', - label:__('New Warehouse Name'), reqd:true}, - {fieldtype:'Check', fieldname:'is_group', label:__('Is Group'), - description: __("Child nodes can be only created under 'Group' type nodes")} + filters: [ + { + fieldname: "company", + fieldtype: "Select", + options: erpnext.utils.get_tree_options("company"), + label: __("Company"), + default: erpnext.utils.get_tree_default("company"), + }, ], - ignore_fields:["parent_warehouse"], -} + fields: [ + { fieldtype: "Data", fieldname: "warehouse_name", label: __("New Warehouse Name"), reqd: true }, + { + fieldtype: "Check", + fieldname: "is_group", + label: __("Is Group"), + description: __("Child nodes can be only created under 'Group' type nodes"), + }, + ], + ignore_fields: ["parent_warehouse"], +}; diff --git a/erpnext/stock/doctype/warehouse_type/warehouse_type.js b/erpnext/stock/doctype/warehouse_type/warehouse_type.js index 4c4b89ce301b..521b07a33d75 100644 --- a/erpnext/stock/doctype/warehouse_type/warehouse_type.js +++ b/erpnext/stock/doctype/warehouse_type/warehouse_type.js @@ -1,8 +1,7 @@ // Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Warehouse Type', { +frappe.ui.form.on("Warehouse Type", { // refresh: function(frm) { - // } }); diff --git a/erpnext/stock/landed_taxes_and_charges_common.js b/erpnext/stock/landed_taxes_and_charges_common.js index 1d76a3d95a13..48cf773f627d 100644 --- a/erpnext/stock/landed_taxes_and_charges_common.js +++ b/erpnext/stock/landed_taxes_and_charges_common.js @@ -1,61 +1,74 @@ -let document_list = ['Landed Cost Voucher', 'Stock Entry', 'Subcontracting Order', 'Subcontracting Receipt']; +let document_list = ["Landed Cost Voucher", "Stock Entry", "Subcontracting Order", "Subcontracting Receipt"]; document_list.forEach((doctype) => { frappe.ui.form.on(doctype, { - refresh: function(frm) { - let tax_field = frm.doc.doctype == 'Landed Cost Voucher' ? 'taxes' : 'additional_costs'; - frm.set_query("expense_account", tax_field, function() { + refresh: function (frm) { + let tax_field = frm.doc.doctype == "Landed Cost Voucher" ? "taxes" : "additional_costs"; + frm.set_query("expense_account", tax_field, function () { return { filters: { - "account_type": ['in', ["Tax", "Chargeable", "Income Account", "Expenses Included In Valuation", "Expenses Included In Asset Valuation"]], - "company": frm.doc.company - } + account_type: [ + "in", + [ + "Tax", + "Chargeable", + "Income Account", + "Expenses Included In Valuation", + "Expenses Included In Asset Valuation", + ], + ], + company: frm.doc.company, + }, }; }); }, - set_account_currency: function(frm, cdt, cdn) { + set_account_currency: function (frm, cdt, cdn) { let row = locals[cdt][cdn]; if (row.expense_account) { - frappe.db.get_value('Account', row.expense_account, 'account_currency', function(value) { + frappe.db.get_value("Account", row.expense_account, "account_currency", function (value) { frappe.model.set_value(cdt, cdn, "account_currency", value.account_currency); frm.events.set_exchange_rate(frm, cdt, cdn); }); } }, - set_exchange_rate: function(frm, cdt, cdn) { + set_exchange_rate: function (frm, cdt, cdn) { let row = locals[cdt][cdn]; let company_currency = frappe.get_doc(":Company", frm.doc.company).default_currency; if (row.account_currency == company_currency) { row.exchange_rate = 1; - frm.set_df_property('taxes', 'hidden', 1, row.name, 'exchange_rate'); + frm.set_df_property("taxes", "hidden", 1, row.name, "exchange_rate"); } else if (!row.exchange_rate || row.exchange_rate == 1) { - frm.set_df_property('taxes', 'hidden', 0, row.name, 'exchange_rate'); + frm.set_df_property("taxes", "hidden", 0, row.name, "exchange_rate"); frappe.call({ method: "erpnext.accounts.doctype.journal_entry.journal_entry.get_exchange_rate", args: { posting_date: frm.doc.posting_date, account: row.expense_account, account_currency: row.account_currency, - company: frm.doc.company + company: frm.doc.company, }, - callback: function(r) { + callback: function (r) { if (r.message) { frappe.model.set_value(cdt, cdn, "exchange_rate", r.message); } - } + }, }); } - frm.refresh_field('taxes'); + frm.refresh_field("taxes"); }, - set_base_amount: function(frm, cdt, cdn) { + set_base_amount: function (frm, cdt, cdn) { let row = locals[cdt][cdn]; - frappe.model.set_value(cdt, cdn, "base_amount", - flt(flt(row.amount)*row.exchange_rate, precision("base_amount", row))); - } + frappe.model.set_value( + cdt, + cdn, + "base_amount", + flt(flt(row.amount) * row.exchange_rate, precision("base_amount", row)) + ); + }, }); }); diff --git a/erpnext/stock/page/stock_balance/stock_balance.js b/erpnext/stock/page/stock_balance/stock_balance.js index 90b8d453420d..a5fba9f98f38 100644 --- a/erpnext/stock/page/stock_balance/stock_balance.js +++ b/erpnext/stock/page/stock_balance/stock_balance.js @@ -1,103 +1,101 @@ -frappe.pages['stock-balance'].on_page_load = function(wrapper) { +frappe.pages["stock-balance"].on_page_load = function (wrapper) { var page = frappe.ui.make_app_page({ parent: wrapper, - title: __('Stock Summary'), - single_column: true + title: __("Stock Summary"), + single_column: true, }); page.start = 0; page.warehouse_field = page.add_field({ - fieldname: 'warehouse', - label: __('Warehouse'), - fieldtype:'Link', - options:'Warehouse', + fieldname: "warehouse", + label: __("Warehouse"), + fieldtype: "Link", + options: "Warehouse", default: frappe.route_options && frappe.route_options.warehouse, - change: function() { + change: function () { page.item_dashboard.start = 0; page.item_dashboard.refresh(); - } + }, }); page.item_field = page.add_field({ - fieldname: 'item_code', - label: __('Item'), - fieldtype:'Link', - options:'Item', + fieldname: "item_code", + label: __("Item"), + fieldtype: "Link", + options: "Item", default: frappe.route_options && frappe.route_options.item_code, - change: function() { + change: function () { page.item_dashboard.start = 0; page.item_dashboard.refresh(); - } + }, }); page.item_group_field = page.add_field({ - fieldname: 'item_group', - label: __('Item Group'), - fieldtype:'Link', - options:'Item Group', + fieldname: "item_group", + label: __("Item Group"), + fieldtype: "Link", + options: "Item Group", default: frappe.route_options && frappe.route_options.item_group, - change: function() { + change: function () { page.item_dashboard.start = 0; page.item_dashboard.refresh(); - } + }, }); page.sort_selector = new frappe.ui.SortSelector({ - parent: page.wrapper.find('.page-form'), + parent: page.wrapper.find(".page-form"), args: { - sort_by: 'projected_qty', - sort_order: 'asc', + sort_by: "projected_qty", + sort_order: "asc", options: [ - {fieldname: 'projected_qty', label: __('Projected qty')}, - {fieldname: 'reserved_qty', label: __('Reserved for sale')}, - {fieldname: 'reserved_qty_for_production', label: __('Reserved for manufacturing')}, - {fieldname: 'reserved_qty_for_sub_contract', label: __('Reserved for sub contracting')}, - {fieldname: 'actual_qty', label: __('Actual qty in stock')}, - ] + { fieldname: "projected_qty", label: __("Projected qty") }, + { fieldname: "reserved_qty", label: __("Reserved for sale") }, + { fieldname: "reserved_qty_for_production", label: __("Reserved for manufacturing") }, + { fieldname: "reserved_qty_for_sub_contract", label: __("Reserved for sub contracting") }, + { fieldname: "actual_qty", label: __("Actual qty in stock") }, + ], }, - change: function(sort_by, sort_order) { + change: function (sort_by, sort_order) { page.item_dashboard.sort_by = sort_by; page.item_dashboard.sort_order = sort_order; page.item_dashboard.start = 0; page.item_dashboard.refresh(); - } + }, }); // page.sort_selector.wrapper.css({'margin-right': '15px', 'margin-top': '4px'}); - frappe.require('item-dashboard.bundle.js', function() { + frappe.require("item-dashboard.bundle.js", function () { page.item_dashboard = new erpnext.stock.ItemDashboard({ parent: page.main, page_length: 20, - method: 'erpnext.stock.dashboard.item_dashboard.get_data', - template: 'item_dashboard_list' - }) + method: "erpnext.stock.dashboard.item_dashboard.get_data", + template: "item_dashboard_list", + }); - page.item_dashboard.before_refresh = function() { + page.item_dashboard.before_refresh = function () { this.item_code = page.item_field.get_value(); this.warehouse = page.warehouse_field.get_value(); this.item_group = page.item_group_field.get_value(); - } + }; page.item_dashboard.refresh(); // item click - var setup_click = function(doctype) { - page.main.on('click', 'a[data-type="'+ doctype.toLowerCase() +'"]', function() { - var name = $(this).attr('data-name'); - var field = page[doctype.toLowerCase() + '_field']; - if(field.get_value()===name) { - frappe.set_route('Form', doctype, name) + var setup_click = function (doctype) { + page.main.on("click", 'a[data-type="' + doctype.toLowerCase() + '"]', function () { + var name = $(this).attr("data-name"); + var field = page[doctype.toLowerCase() + "_field"]; + if (field.get_value() === name) { + frappe.set_route("Form", doctype, name); } else { field.set_input(name); page.item_dashboard.refresh(); } }); - } + }; - setup_click('Item'); - setup_click('Warehouse'); + setup_click("Item"); + setup_click("Warehouse"); }); - - -} +}; diff --git a/erpnext/stock/page/warehouse_capacity_summary/warehouse_capacity_summary.js b/erpnext/stock/page/warehouse_capacity_summary/warehouse_capacity_summary.js index 61927f51a828..f03c5ca65e8d 100644 --- a/erpnext/stock/page/warehouse_capacity_summary/warehouse_capacity_summary.js +++ b/erpnext/stock/page/warehouse_capacity_summary/warehouse_capacity_summary.js @@ -1,98 +1,98 @@ -frappe.pages['warehouse-capacity-summary'].on_page_load = function(wrapper) { +frappe.pages["warehouse-capacity-summary"].on_page_load = function (wrapper) { var page = frappe.ui.make_app_page({ parent: wrapper, - title: 'Warehouse Capacity Summary', - single_column: true + title: "Warehouse Capacity Summary", + single_column: true, }); - page.set_secondary_action('Refresh', () => page.capacity_dashboard.refresh(), 'refresh'); + page.set_secondary_action("Refresh", () => page.capacity_dashboard.refresh(), "refresh"); page.start = 0; page.company_field = page.add_field({ - fieldname: 'company', - label: __('Company'), - fieldtype: 'Link', - options: 'Company', + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", reqd: 1, default: frappe.defaults.get_default("company"), - change: function() { + change: function () { page.capacity_dashboard.start = 0; page.capacity_dashboard.refresh(); - } + }, }); page.warehouse_field = page.add_field({ - fieldname: 'warehouse', - label: __('Warehouse'), - fieldtype: 'Link', - options: 'Warehouse', - change: function() { + fieldname: "warehouse", + label: __("Warehouse"), + fieldtype: "Link", + options: "Warehouse", + change: function () { page.capacity_dashboard.start = 0; page.capacity_dashboard.refresh(); - } + }, }); page.item_field = page.add_field({ - fieldname: 'item_code', - label: __('Item'), - fieldtype: 'Link', - options: 'Item', - change: function() { + fieldname: "item_code", + label: __("Item"), + fieldtype: "Link", + options: "Item", + change: function () { page.capacity_dashboard.start = 0; page.capacity_dashboard.refresh(); - } + }, }); page.parent_warehouse_field = page.add_field({ - fieldname: 'parent_warehouse', - label: __('Parent Warehouse'), - fieldtype: 'Link', - options: 'Warehouse', - get_query: function() { + fieldname: "parent_warehouse", + label: __("Parent Warehouse"), + fieldtype: "Link", + options: "Warehouse", + get_query: function () { return { filters: { - "is_group": 1 - } + is_group: 1, + }, }; }, - change: function() { + change: function () { page.capacity_dashboard.start = 0; page.capacity_dashboard.refresh(); - } + }, }); page.sort_selector = new frappe.ui.SortSelector({ - parent: page.wrapper.find('.page-form'), + parent: page.wrapper.find(".page-form"), args: { - sort_by: 'stock_capacity', - sort_order: 'desc', + sort_by: "stock_capacity", + sort_order: "desc", options: [ - {fieldname: 'stock_capacity', label: __('Capacity (Stock UOM)')}, - {fieldname: 'percent_occupied', label: __('% Occupied')}, - {fieldname: 'actual_qty', label: __('Balance Qty (Stock)')} - ] + { fieldname: "stock_capacity", label: __("Capacity (Stock UOM)") }, + { fieldname: "percent_occupied", label: __("% Occupied") }, + { fieldname: "actual_qty", label: __("Balance Qty (Stock)") }, + ], }, - change: function(sort_by, sort_order) { + change: function (sort_by, sort_order) { page.capacity_dashboard.sort_by = sort_by; page.capacity_dashboard.sort_order = sort_order; page.capacity_dashboard.start = 0; page.capacity_dashboard.refresh(); - } + }, }); - frappe.require('item-dashboard.bundle.js', function() { - $(frappe.render_template('warehouse_capacity_summary_header')).appendTo(page.main); + frappe.require("item-dashboard.bundle.js", function () { + $(frappe.render_template("warehouse_capacity_summary_header")).appendTo(page.main); page.capacity_dashboard = new erpnext.stock.ItemDashboard({ page_name: "warehouse-capacity-summary", page_length: 10, parent: page.main, - sort_by: 'stock_capacity', - sort_order: 'desc', - method: 'erpnext.stock.dashboard.warehouse_capacity_dashboard.get_data', - template: 'warehouse_capacity_summary' + sort_by: "stock_capacity", + sort_order: "desc", + method: "erpnext.stock.dashboard.warehouse_capacity_dashboard.get_data", + template: "warehouse_capacity_summary", }); - page.capacity_dashboard.before_refresh = function() { + page.capacity_dashboard.before_refresh = function () { this.item_code = page.item_field.get_value(); this.warehouse = page.warehouse_field.get_value(); this.parent_warehouse = page.parent_warehouse_field.get_value(); @@ -101,12 +101,12 @@ frappe.pages['warehouse-capacity-summary'].on_page_load = function(wrapper) { page.capacity_dashboard.refresh(); - let setup_click = function(doctype) { - page.main.on('click', 'a[data-type="'+ doctype.toLowerCase() +'"]', function() { - var name = $(this).attr('data-name'); - var field = page[doctype.toLowerCase() + '_field']; - if (field.get_value()===name) { - frappe.set_route('Form', doctype, name); + let setup_click = function (doctype) { + page.main.on("click", 'a[data-type="' + doctype.toLowerCase() + '"]', function () { + var name = $(this).attr("data-name"); + var field = page[doctype.toLowerCase() + "_field"]; + if (field.get_value() === name) { + frappe.set_route("Form", doctype, name); } else { field.set_input(name); page.capacity_dashboard.refresh(); @@ -114,7 +114,7 @@ frappe.pages['warehouse-capacity-summary'].on_page_load = function(wrapper) { }); }; - setup_click('Item'); - setup_click('Warehouse'); + setup_click("Item"); + setup_click("Warehouse"); }); }; diff --git a/erpnext/stock/report/batch_item_expiry_status/batch_item_expiry_status.js b/erpnext/stock/report/batch_item_expiry_status/batch_item_expiry_status.js index 48a72a2bfe5a..a15b69b112a4 100644 --- a/erpnext/stock/report/batch_item_expiry_status/batch_item_expiry_status.js +++ b/erpnext/stock/report/batch_item_expiry_status/batch_item_expiry_status.js @@ -2,34 +2,34 @@ // For license information, please see license.txt frappe.query_reports["Batch Item Expiry Status"] = { - "filters": [ + filters: [ { - "fieldname":"from_date", - "label": __("From Date"), - "fieldtype": "Date", - "width": "80", - "default": frappe.sys_defaults.year_start_date, - "reqd": 1, + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + width: "80", + default: frappe.sys_defaults.year_start_date, + reqd: 1, }, { - "fieldname":"to_date", - "label": __("To Date"), - "fieldtype": "Date", - "width": "80", - "default": frappe.datetime.get_today(), - "reqd": 1, + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + width: "80", + default: frappe.datetime.get_today(), + reqd: 1, }, { - "fieldname":"item", - "label": __("Item"), - "fieldtype": "Link", - "options": "Item", - "width": "100", - "get_query": function () { + fieldname: "item", + label: __("Item"), + fieldtype: "Link", + options: "Item", + width: "100", + get_query: function () { return { - filters: {"has_batch_no": 1} - } - } - } - ] -} + filters: { has_batch_no: 1 }, + }; + }, + }, + ], +}; diff --git a/erpnext/stock/report/batch_wise_balance_history/batch_wise_balance_history.js b/erpnext/stock/report/batch_wise_balance_history/batch_wise_balance_history.js index 74b5a5ae36e5..1694abe7c086 100644 --- a/erpnext/stock/report/batch_wise_balance_history/batch_wise_balance_history.js +++ b/erpnext/stock/report/batch_wise_balance_history/batch_wise_balance_history.js @@ -2,87 +2,90 @@ // License: GNU General Public License v3. See license.txt frappe.query_reports["Batch-Wise Balance History"] = { - "filters": [ + filters: [ { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_user_default("Company"), - "reqd": 1 + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), + reqd: 1, }, { - "fieldname":"from_date", - "label": __("From Date"), - "fieldtype": "Date", - "width": "80", - "default": frappe.sys_defaults.year_start_date, - "reqd": 1 + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + width: "80", + default: frappe.sys_defaults.year_start_date, + reqd: 1, }, { - "fieldname":"to_date", - "label": __("To Date"), - "fieldtype": "Date", - "width": "80", - "default": frappe.datetime.get_today(), - "reqd": 1 + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + width: "80", + default: frappe.datetime.get_today(), + reqd: 1, }, { - "fieldname":"item_code", - "label": __("Item Code"), - "fieldtype": "Link", - "options": "Item", - "get_query": function() { + fieldname: "item_code", + label: __("Item Code"), + fieldtype: "Link", + options: "Item", + get_query: function () { return { filters: { - "has_batch_no": 1 - } + has_batch_no: 1, + }, }; - } + }, }, { - "fieldname":"warehouse", - "label": __("Warehouse"), - "fieldtype": "Link", - "options": "Warehouse", - "get_query": function() { - let company = frappe.query_report.get_filter_value('company'); + fieldname: "warehouse", + label: __("Warehouse"), + fieldtype: "Link", + options: "Warehouse", + get_query: function () { + let company = frappe.query_report.get_filter_value("company"); return { filters: { - "company": company - } + company: company, + }, }; - } + }, }, { - "fieldname":"batch_no", - "label": __("Batch No"), - "fieldtype": "Link", - "options": "Batch", - "get_query": function() { - let item_code = frappe.query_report.get_filter_value('item_code'); + fieldname: "batch_no", + label: __("Batch No"), + fieldtype: "Link", + options: "Batch", + get_query: function () { + let item_code = frappe.query_report.get_filter_value("item_code"); return { filters: { - "item": item_code - } + item: item_code, + }, }; - } + }, }, ], - "formatter": function (value, row, column, data, default_formatter) { + formatter: function (value, row, column, data, default_formatter) { if (column.fieldname == "Batch" && data && !!data["Batch"]) { value = data["Batch"]; - column.link_onclick = "frappe.query_reports['Batch-Wise Balance History'].set_batch_route_to_stock_ledger(" + JSON.stringify(data) + ")"; + column.link_onclick = + "frappe.query_reports['Batch-Wise Balance History'].set_batch_route_to_stock_ledger(" + + JSON.stringify(data) + + ")"; } value = default_formatter(value, row, column, data); return value; }, - "set_batch_route_to_stock_ledger": function (data) { + set_batch_route_to_stock_ledger: function (data) { frappe.route_options = { - "batch_no": data["Batch"] + batch_no: data["Batch"], }; frappe.set_route("query-report", "Stock Ledger"); - } -} + }, +}; diff --git a/erpnext/stock/report/bom_search/bom_search.js b/erpnext/stock/report/bom_search/bom_search.js index e9e763cb889d..b6f3c9633e1e 100644 --- a/erpnext/stock/report/bom_search/bom_search.js +++ b/erpnext/stock/report/bom_search/bom_search.js @@ -2,41 +2,41 @@ // For license information, please see license.txt frappe.query_reports["BOM Search"] = { - "filters": [ + filters: [ { fieldname: "item1", label: __("Item 1"), fieldtype: "Link", - options: "Item" + options: "Item", }, { fieldname: "item2", label: __("Item 2"), fieldtype: "Link", - options: "Item" + options: "Item", }, { fieldname: "item3", label: __("Item 3"), fieldtype: "Link", - options: "Item" + options: "Item", }, { fieldname: "item4", label: __("Item 4"), fieldtype: "Link", - options: "Item" + options: "Item", }, { fieldname: "item5", label: __("Item 5"), fieldtype: "Link", - options: "Item" + options: "Item", }, { fieldname: "search_sub_assemblies", label: __("Search Sub Assemblies"), fieldtype: "Check", }, - ] -} + ], +}; diff --git a/erpnext/stock/report/cogs_by_item_group/cogs_by_item_group.js b/erpnext/stock/report/cogs_by_item_group/cogs_by_item_group.js index d7c50a66979f..e61791cc8cdf 100644 --- a/erpnext/stock/report/cogs_by_item_group/cogs_by_item_group.js +++ b/erpnext/stock/report/cogs_by_item_group/cogs_by_item_group.js @@ -2,30 +2,29 @@ // For license information, please see license.txt /* eslint-disable */ - frappe.query_reports["COGS By Item Group"] = { filters: [ - { - label: __("Company"), - fieldname: "company", - fieldtype: "Link", - options: "Company", - mandatory: true, - default: frappe.defaults.get_user_default("Company"), - }, - { - label: __("From Date"), - fieldname: "from_date", - fieldtype: "Date", - mandatory: true, - default: frappe.datetime.year_start(), - }, - { - label: __("To Date"), - fieldname: "to_date", - fieldtype: "Date", - mandatory: true, - default: frappe.datetime.get_today(), - }, - ] + { + label: __("Company"), + fieldname: "company", + fieldtype: "Link", + options: "Company", + mandatory: true, + default: frappe.defaults.get_user_default("Company"), + }, + { + label: __("From Date"), + fieldname: "from_date", + fieldtype: "Date", + mandatory: true, + default: frappe.datetime.year_start(), + }, + { + label: __("To Date"), + fieldname: "to_date", + fieldtype: "Date", + mandatory: true, + default: frappe.datetime.get_today(), + }, + ], }; diff --git a/erpnext/stock/report/delayed_item_report/delayed_item_report.js b/erpnext/stock/report/delayed_item_report/delayed_item_report.js index 40e6abefeb0d..317fa77827a4 100644 --- a/erpnext/stock/report/delayed_item_report/delayed_item_report.js +++ b/erpnext/stock/report/delayed_item_report/delayed_item_report.js @@ -3,60 +3,60 @@ /* eslint-disable */ frappe.query_reports["Delayed Item Report"] = { - "filters": [ + filters: [ { fieldname: "company", label: __("Company"), fieldtype: "Link", options: "Company", default: frappe.defaults.get_default("company"), - reqd: 1 + reqd: 1, }, { - fieldname:"from_date", + fieldname: "from_date", label: __("From Date"), fieldtype: "Date", default: frappe.datetime.month_start(), - reqd: 1 + reqd: 1, }, { - fieldname:"to_date", + fieldname: "to_date", label: __("To Date"), fieldtype: "Date", default: frappe.datetime.now_date(), - reqd: 1 + reqd: 1, }, { - fieldname:"sales_order", + fieldname: "sales_order", label: __("Sales Order"), fieldtype: "Link", options: "Sales Order", }, { - fieldname:"customer", + fieldname: "customer", label: __("Customer"), fieldtype: "Link", options: "Customer", }, { - fieldname:"customer_group", + fieldname: "customer_group", label: __("Customer Group"), fieldtype: "Link", options: "Customer Group", }, { - fieldname:"item_group", + fieldname: "item_group", label: __("Item Group"), fieldtype: "Link", options: "Item Group", }, { - fieldname:"based_on", + fieldname: "based_on", label: __("Based On"), fieldtype: "Select", options: ["Delivery Note", "Sales Invoice"], default: "Sales Invoice", - reqd: 1 + reqd: 1, }, - ] -} + ], +}; diff --git a/erpnext/stock/report/delayed_order_report/delayed_order_report.js b/erpnext/stock/report/delayed_order_report/delayed_order_report.js index aab0f3d0d1f5..34ea3240de08 100644 --- a/erpnext/stock/report/delayed_order_report/delayed_order_report.js +++ b/erpnext/stock/report/delayed_order_report/delayed_order_report.js @@ -3,60 +3,60 @@ /* eslint-disable */ frappe.query_reports["Delayed Order Report"] = { - "filters": [ + filters: [ { fieldname: "company", label: __("Company"), fieldtype: "Link", options: "Company", default: frappe.defaults.get_default("company"), - reqd: 1 + reqd: 1, }, { - fieldname:"from_date", + fieldname: "from_date", label: __("From Date"), fieldtype: "Date", default: frappe.datetime.month_start(), - reqd: 1 + reqd: 1, }, { - fieldname:"to_date", + fieldname: "to_date", label: __("To Date"), fieldtype: "Date", default: frappe.datetime.now_date(), - reqd: 1 + reqd: 1, }, { - fieldname:"sales_order", + fieldname: "sales_order", label: __("Sales Order"), fieldtype: "Link", options: "Sales Order", }, { - fieldname:"customer", + fieldname: "customer", label: __("Customer"), fieldtype: "Link", options: "Customer", }, { - fieldname:"customer_group", + fieldname: "customer_group", label: __("Customer Group"), fieldtype: "Link", options: "Customer Group", }, { - fieldname:"item_group", + fieldname: "item_group", label: __("Item Group"), fieldtype: "Link", options: "Item Group", }, { - fieldname:"based_on", + fieldname: "based_on", label: __("Based On"), fieldtype: "Select", options: ["Delivery Note", "Sales Invoice"], default: "Sales Invoice", - reqd: 1 + reqd: 1, }, - ] -} + ], +}; diff --git a/erpnext/stock/report/delivery_note_trends/delivery_note_trends.js b/erpnext/stock/report/delivery_note_trends/delivery_note_trends.js index 8a04565c197e..5e7dc8b2a633 100644 --- a/erpnext/stock/report/delivery_note_trends/delivery_note_trends.js +++ b/erpnext/stock/report/delivery_note_trends/delivery_note_trends.js @@ -1,8 +1,8 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -frappe.require("assets/erpnext/js/sales_trends_filters.js", function() { +frappe.require("assets/erpnext/js/sales_trends_filters.js", function () { frappe.query_reports["Delivery Note Trends"] = { - filters: erpnext.get_sales_trends_filters() - } + filters: erpnext.get_sales_trends_filters(), + }; }); diff --git a/erpnext/stock/report/fifo_queue_vs_qty_after_transaction_comparison/fifo_queue_vs_qty_after_transaction_comparison.js b/erpnext/stock/report/fifo_queue_vs_qty_after_transaction_comparison/fifo_queue_vs_qty_after_transaction_comparison.js index 0b8f49653dd7..8fc3590c4d66 100644 --- a/erpnext/stock/report/fifo_queue_vs_qty_after_transaction_comparison/fifo_queue_vs_qty_after_transaction_comparison.js +++ b/erpnext/stock/report/fifo_queue_vs_qty_after_transaction_comparison/fifo_queue_vs_qty_after_transaction_comparison.js @@ -2,48 +2,45 @@ // For license information, please see license.txt /* eslint-disable */ -const DIFFERNCE_FIELD_NAMES = [ - "fifo_qty_diff", - "fifo_value_diff", -]; +const DIFFERNCE_FIELD_NAMES = ["fifo_qty_diff", "fifo_value_diff"]; frappe.query_reports["FIFO Queue vs Qty After Transaction Comparison"] = { - "filters": [ + filters: [ { - "fieldname": "item_code", - "fieldtype": "Link", - "label": "Item", - "options": "Item", - get_query: function() { + fieldname: "item_code", + fieldtype: "Link", + label: "Item", + options: "Item", + get_query: function () { return { - filters: {is_stock_item: 1, has_serial_no: 0} - } - } + filters: { is_stock_item: 1, has_serial_no: 0 }, + }; + }, }, { - "fieldname": "item_group", - "fieldtype": "Link", - "label": "Item Group", - "options": "Item Group", + fieldname: "item_group", + fieldtype: "Link", + label: "Item Group", + options: "Item Group", }, { - "fieldname": "warehouse", - "fieldtype": "Link", - "label": "Warehouse", - "options": "Warehouse", + fieldname: "warehouse", + fieldtype: "Link", + label: "Warehouse", + options: "Warehouse", }, { - "fieldname": "from_date", - "fieldtype": "Date", - "label": "From Posting Date", + fieldname: "from_date", + fieldtype: "Date", + label: "From Posting Date", }, { - "fieldname": "to_date", - "fieldtype": "Date", - "label": "From Posting Date", - } + fieldname: "to_date", + fieldtype: "Date", + label: "From Posting Date", + }, ], - formatter (value, row, column, data, default_formatter) { + formatter(value, row, column, data, default_formatter) { value = default_formatter(value, row, column, data); if (DIFFERNCE_FIELD_NAMES.includes(column.fieldname) && Math.abs(data[column.fieldname]) > 0.001) { value = "" + value + ""; diff --git a/erpnext/stock/report/incorrect_balance_qty_after_transaction/incorrect_balance_qty_after_transaction.js b/erpnext/stock/report/incorrect_balance_qty_after_transaction/incorrect_balance_qty_after_transaction.js index bf11277d9c48..0e6f7a0d177c 100644 --- a/erpnext/stock/report/incorrect_balance_qty_after_transaction/incorrect_balance_qty_after_transaction.js +++ b/erpnext/stock/report/incorrect_balance_qty_after_transaction/incorrect_balance_qty_after_transaction.js @@ -3,25 +3,25 @@ /* eslint-disable */ frappe.query_reports["Incorrect Balance Qty After Transaction"] = { - "filters": [ + filters: [ { label: __("Company"), fieldtype: "Link", fieldname: "company", options: "Company", default: frappe.defaults.get_user_default("Company"), - reqd: 1 + reqd: 1, }, { - label: __('Item Code'), - fieldtype: 'Link', - fieldname: 'item_code', - options: 'Item' + label: __("Item Code"), + fieldtype: "Link", + fieldname: "item_code", + options: "Item", }, { - label: __('Warehouse'), - fieldtype: 'Link', - fieldname: 'warehouse' - } - ] + label: __("Warehouse"), + fieldtype: "Link", + fieldname: "warehouse", + }, + ], }; diff --git a/erpnext/stock/report/incorrect_serial_no_valuation/incorrect_serial_no_valuation.js b/erpnext/stock/report/incorrect_serial_no_valuation/incorrect_serial_no_valuation.js index c62d48081c25..4d0472ceaa8d 100644 --- a/erpnext/stock/report/incorrect_serial_no_valuation/incorrect_serial_no_valuation.js +++ b/erpnext/stock/report/incorrect_serial_no_valuation/incorrect_serial_no_valuation.js @@ -3,33 +3,33 @@ /* eslint-disable */ frappe.query_reports["Incorrect Serial No Valuation"] = { - "filters": [ + filters: [ { - label: __('Item Code'), - fieldtype: 'Link', - fieldname: 'item_code', - options: 'Item', - get_query: function() { + label: __("Item Code"), + fieldtype: "Link", + fieldname: "item_code", + options: "Item", + get_query: function () { return { filters: { - 'has_serial_no': 1 - } - } - } + has_serial_no: 1, + }, + }; + }, }, { - label: __('From Date'), - fieldtype: 'Date', - fieldname: 'from_date', + label: __("From Date"), + fieldtype: "Date", + fieldname: "from_date", reqd: 1, - default: frappe.defaults.get_user_default("year_start_date") + default: frappe.defaults.get_user_default("year_start_date"), }, { - label: __('To Date'), - fieldtype: 'Date', - fieldname: 'to_date', + label: __("To Date"), + fieldtype: "Date", + fieldname: "to_date", reqd: 1, - default: frappe.defaults.get_user_default("year_end_date") - } - ] + default: frappe.defaults.get_user_default("year_end_date"), + }, + ], }; diff --git a/erpnext/stock/report/incorrect_stock_value_report/incorrect_stock_value_report.js b/erpnext/stock/report/incorrect_stock_value_report/incorrect_stock_value_report.js index ff424807e3e9..65e0b928bb79 100644 --- a/erpnext/stock/report/incorrect_stock_value_report/incorrect_stock_value_report.js +++ b/erpnext/stock/report/incorrect_stock_value_report/incorrect_stock_value_report.js @@ -3,34 +3,34 @@ /* eslint-disable */ frappe.query_reports["Incorrect Stock Value Report"] = { - "filters": [ + filters: [ { - "label": __("Company"), - "fieldname": "company", - "fieldtype": "Link", - "options": "Company", - "reqd": 1, - "default": frappe.defaults.get_user_default("Company") + label: __("Company"), + fieldname: "company", + fieldtype: "Link", + options: "Company", + reqd: 1, + default: frappe.defaults.get_user_default("Company"), }, { - "label": __("Account"), - "fieldname": "account", - "fieldtype": "Link", - "options": "Account", - get_query: function() { - var company = frappe.query_report.get_filter_value('company'); + label: __("Account"), + fieldname: "account", + fieldtype: "Link", + options: "Account", + get_query: function () { + var company = frappe.query_report.get_filter_value("company"); return { filters: { - "account_type": "Stock", - "company": company - } - } - } + account_type: "Stock", + company: company, + }, + }; + }, }, { - "label": __("From Date"), - "fieldname": "from_date", - "fieldtype": "Date" - } - ] + label: __("From Date"), + fieldname: "from_date", + fieldtype: "Date", + }, + ], }; diff --git a/erpnext/stock/report/item_price_stock/item_price_stock.js b/erpnext/stock/report/item_price_stock/item_price_stock.js index 7af1dab6a0be..aa2b7aaa4f32 100644 --- a/erpnext/stock/report/item_price_stock/item_price_stock.js +++ b/erpnext/stock/report/item_price_stock/item_price_stock.js @@ -3,12 +3,12 @@ /* eslint-disable */ frappe.query_reports["Item Price Stock"] = { - "filters": [ + filters: [ { - "fieldname":"item_code", - "label": __("Item"), - "fieldtype": "Link", - "options": "Item" - } - ] -} + fieldname: "item_code", + label: __("Item"), + fieldtype: "Link", + options: "Item", + }, + ], +}; diff --git a/erpnext/stock/report/item_prices/item_prices.js b/erpnext/stock/report/item_prices/item_prices.js index 77bca4466d0b..868b503eb73d 100644 --- a/erpnext/stock/report/item_prices/item_prices.js +++ b/erpnext/stock/report/item_prices/item_prices.js @@ -2,16 +2,16 @@ // For license information, please see license.txt frappe.query_reports["Item Prices"] = { - "filters": [ + filters: [ { - "fieldname": "items", - "label": __("Items Filter"), - "fieldtype": "Select", - "options": "Enabled Items only\nDisabled Items only\nAll Items", - "default": "Enabled Items only", - "on_change": function(query_report) { + fieldname: "items", + label: __("Items Filter"), + fieldtype: "Select", + options: "Enabled Items only\nDisabled Items only\nAll Items", + default: "Enabled Items only", + on_change: function (query_report) { query_report.trigger_refresh(); - } - } - ] -} + }, + }, + ], +}; diff --git a/erpnext/stock/report/item_shortage_report/item_shortage_report.js b/erpnext/stock/report/item_shortage_report/item_shortage_report.js index ca42a331e91d..5a6a54734a4f 100644 --- a/erpnext/stock/report/item_shortage_report/item_shortage_report.js +++ b/erpnext/stock/report/item_shortage_report/item_shortage_report.js @@ -3,24 +3,24 @@ /* eslint-disable */ frappe.query_reports["Item Shortage Report"] = { - "filters": [ + filters: [ { - "fieldname": "company", - "label": __("Company"), - "fieldtype": "Link", - "width": "80", - "options": "Company", - "reqd": 1, - "default": frappe.defaults.get_default("company") + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + width: "80", + options: "Company", + reqd: 1, + default: frappe.defaults.get_default("company"), }, { - "fieldname": "warehouse", - "label": __("Warehouse"), - "fieldtype": "MultiSelectList", - "width": "100", - get_data: function(txt) { - return frappe.db.get_link_options('Warehouse', txt); - } - } - ] + fieldname: "warehouse", + label: __("Warehouse"), + fieldtype: "MultiSelectList", + width: "100", + get_data: function (txt) { + return frappe.db.get_link_options("Warehouse", txt); + }, + }, + ], }; diff --git a/erpnext/stock/report/item_variant_details/item_variant_details.js b/erpnext/stock/report/item_variant_details/item_variant_details.js index 78eab4050c1d..f61e7417724a 100644 --- a/erpnext/stock/report/item_variant_details/item_variant_details.js +++ b/erpnext/stock/report/item_variant_details/item_variant_details.js @@ -3,7 +3,7 @@ /* eslint-disable */ frappe.query_reports["Item Variant Details"] = { - "filters": [ + filters: [ { reqd: 1, default: "", @@ -13,9 +13,9 @@ frappe.query_reports["Item Variant Details"] = { fieldtype: "Link", get_query: () => { return { - filters: { "has_variants": 1 } - } - } - } - ] -} + filters: { has_variants: 1 }, + }; + }, + }, + ], +}; diff --git a/erpnext/stock/report/itemwise_recommended_reorder_level/itemwise_recommended_reorder_level.js b/erpnext/stock/report/itemwise_recommended_reorder_level/itemwise_recommended_reorder_level.js index 173aad6d5a92..3b12dab939a1 100644 --- a/erpnext/stock/report/itemwise_recommended_reorder_level/itemwise_recommended_reorder_level.js +++ b/erpnext/stock/report/itemwise_recommended_reorder_level/itemwise_recommended_reorder_level.js @@ -2,31 +2,31 @@ // License: GNU General Public License v3. See license.txt frappe.query_reports["Itemwise Recommended Reorder Level"] = { - "filters": [ + filters: [ { - "fieldname":"from_date", - "label": __("From Date"), - "fieldtype": "Date", - "default": frappe.sys_defaults.year_start_date + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + default: frappe.sys_defaults.year_start_date, }, { - "fieldname":"to_date", - "label": __("To Date"), - "fieldtype": "Date", - "default": frappe.datetime.get_today() + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + default: frappe.datetime.get_today(), }, { - "fieldname":"item_group", - "label": __("Item Group"), - "fieldtype": "Link", - "options": "Item Group", - "reqd": 1 + fieldname: "item_group", + label: __("Item Group"), + fieldtype: "Link", + options: "Item Group", + reqd: 1, }, { - "fieldname":"brand", - "label": __("Brand"), - "fieldtype": "Link", - "options": "Brand" - } - ] -} + fieldname: "brand", + label: __("Brand"), + fieldtype: "Link", + options: "Brand", + }, + ], +}; diff --git a/erpnext/stock/report/product_bundle_balance/product_bundle_balance.js b/erpnext/stock/report/product_bundle_balance/product_bundle_balance.js index 4458a7245f35..5cef5c703412 100644 --- a/erpnext/stock/report/product_bundle_balance/product_bundle_balance.js +++ b/erpnext/stock/report/product_bundle_balance/product_bundle_balance.js @@ -2,51 +2,51 @@ // For license information, please see license.txt frappe.query_reports["Product Bundle Balance"] = { - "filters": [ + filters: [ { - "fieldname":"date", - "label": __("Date"), - "fieldtype": "Date", - "width": "80", - "reqd": 1, - "default": frappe.datetime.get_today(), + fieldname: "date", + label: __("Date"), + fieldtype: "Date", + width: "80", + reqd: 1, + default: frappe.datetime.get_today(), }, { - "fieldname": "item_code", - "label": __("Item"), - "fieldtype": "Link", - "width": "80", - "options": "Item", - "get_query": function() { + fieldname: "item_code", + label: __("Item"), + fieldtype: "Link", + width: "80", + options: "Item", + get_query: function () { return { query: "erpnext.controllers.queries.item_query", - filters: {"is_stock_item": 0} + filters: { is_stock_item: 0 }, }; - } + }, }, { - "fieldname": "item_group", - "label": __("Item Group"), - "fieldtype": "Link", - "width": "80", - "options": "Item Group" + fieldname: "item_group", + label: __("Item Group"), + fieldtype: "Link", + width: "80", + options: "Item Group", }, { - "fieldname":"brand", - "label": __("Brand"), - "fieldtype": "Link", - "options": "Brand" + fieldname: "brand", + label: __("Brand"), + fieldtype: "Link", + options: "Brand", }, { - "fieldname": "warehouse", - "label": __("Warehouse"), - "fieldtype": "Link", - "width": "80", - "options": "Warehouse" + fieldname: "warehouse", + label: __("Warehouse"), + fieldtype: "Link", + width: "80", + options: "Warehouse", }, ], - "initial_depth": 0, - "formatter": function(value, row, column, data, default_formatter) { + initial_depth: 0, + formatter: function (value, row, column, data, default_formatter) { value = default_formatter(value, row, column, data); if (!data.parent_item) { value = $(`${value}`); @@ -54,5 +54,5 @@ frappe.query_reports["Product Bundle Balance"] = { value = $value.wrap("

              ").parent().html(); } return value; - } + }, }; diff --git a/erpnext/stock/report/purchase_receipt_trends/purchase_receipt_trends.js b/erpnext/stock/report/purchase_receipt_trends/purchase_receipt_trends.js index 695efacb6946..bddfe5d7705c 100644 --- a/erpnext/stock/report/purchase_receipt_trends/purchase_receipt_trends.js +++ b/erpnext/stock/report/purchase_receipt_trends/purchase_receipt_trends.js @@ -1,8 +1,8 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -frappe.require("assets/erpnext/js/purchase_trends_filters.js", function() { +frappe.require("assets/erpnext/js/purchase_trends_filters.js", function () { frappe.query_reports["Purchase Receipt Trends"] = { - filters: erpnext.get_purchase_trends_filters() - } + filters: erpnext.get_purchase_trends_filters(), + }; }); diff --git a/erpnext/stock/report/serial_no_ledger/serial_no_ledger.js b/erpnext/stock/report/serial_no_ledger/serial_no_ledger.js index 616312e31189..6c2c17db52c0 100644 --- a/erpnext/stock/report/serial_no_ledger/serial_no_ledger.js +++ b/erpnext/stock/report/serial_no_ledger/serial_no_ledger.js @@ -3,50 +3,50 @@ /* eslint-disable */ frappe.query_reports["Serial No Ledger"] = { - "filters": [ + filters: [ { - 'label': __('Item Code'), - 'fieldtype': 'Link', - 'fieldname': 'item_code', - 'reqd': 1, - 'options': 'Item', - get_query: function() { + label: __("Item Code"), + fieldtype: "Link", + fieldname: "item_code", + reqd: 1, + options: "Item", + get_query: function () { return { filters: { - 'has_serial_no': 1 - } - } - } + has_serial_no: 1, + }, + }; + }, }, { - 'label': __('Serial No'), - 'fieldtype': 'Link', - 'fieldname': 'serial_no', - 'options': 'Serial No', - 'reqd': 1 + label: __("Serial No"), + fieldtype: "Link", + fieldname: "serial_no", + options: "Serial No", + reqd: 1, }, { - 'label': __('Warehouse'), - 'fieldtype': 'Link', - 'fieldname': 'warehouse', - 'options': 'Warehouse', - get_query: function() { - let company = frappe.query_report.get_filter_value('company'); + label: __("Warehouse"), + fieldtype: "Link", + fieldname: "warehouse", + options: "Warehouse", + get_query: function () { + let company = frappe.query_report.get_filter_value("company"); if (company) { return { filters: { - 'company': company - } - } + company: company, + }, + }; } - } + }, }, { - 'label': __('As On Date'), - 'fieldtype': 'Date', - 'fieldname': 'posting_date', - 'default': frappe.datetime.get_today() + label: __("As On Date"), + fieldtype: "Date", + fieldname: "posting_date", + default: frappe.datetime.get_today(), }, - ] + ], }; diff --git a/erpnext/stock/report/stock_ageing/stock_ageing.js b/erpnext/stock/report/stock_ageing/stock_ageing.js index db463b7ca098..641084149abd 100644 --- a/erpnext/stock/report/stock_ageing/stock_ageing.js +++ b/erpnext/stock/report/stock_ageing/stock_ageing.js @@ -2,74 +2,74 @@ // License: GNU General Public License v3. See license.txt frappe.query_reports["Stock Ageing"] = { - "filters": [ + filters: [ { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_user_default("Company"), - "reqd": 1 + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), + reqd: 1, }, { - "fieldname":"to_date", - "label": __("As On Date"), - "fieldtype": "Date", - "default": frappe.datetime.get_today(), - "reqd": 1 + fieldname: "to_date", + label: __("As On Date"), + fieldtype: "Date", + default: frappe.datetime.get_today(), + reqd: 1, }, { - "fieldname":"warehouse", - "label": __("Warehouse"), - "fieldtype": "Link", - "options": "Warehouse", + fieldname: "warehouse", + label: __("Warehouse"), + fieldtype: "Link", + options: "Warehouse", get_query: () => { const company = frappe.query_report.get_filter_value("company"); return { filters: { - ...company && {company}, - } + ...(company && { company }), + }, }; - } + }, }, { - "fieldname":"item_code", - "label": __("Item"), - "fieldtype": "Link", - "options": "Item" + fieldname: "item_code", + label: __("Item"), + fieldtype: "Link", + options: "Item", }, { - "fieldname":"brand", - "label": __("Brand"), - "fieldtype": "Link", - "options": "Brand" + fieldname: "brand", + label: __("Brand"), + fieldtype: "Link", + options: "Brand", }, { - "fieldname":"range1", - "label": __("Ageing Range 1"), - "fieldtype": "Int", - "default": "30", - "reqd": 1 + fieldname: "range1", + label: __("Ageing Range 1"), + fieldtype: "Int", + default: "30", + reqd: 1, }, { - "fieldname":"range2", - "label": __("Ageing Range 2"), - "fieldtype": "Int", - "default": "60", - "reqd": 1 + fieldname: "range2", + label: __("Ageing Range 2"), + fieldtype: "Int", + default: "60", + reqd: 1, }, { - "fieldname":"range3", - "label": __("Ageing Range 3"), - "fieldtype": "Int", - "default": "90", - "reqd": 1 + fieldname: "range3", + label: __("Ageing Range 3"), + fieldtype: "Int", + default: "90", + reqd: 1, }, { - "fieldname":"show_warehouse_wise_stock", - "label": __("Show Warehouse-wise Stock"), - "fieldtype": "Check", - "default": 0 - } - ] -} + fieldname: "show_warehouse_wise_stock", + label: __("Show Warehouse-wise Stock"), + fieldtype: "Check", + default: 0, + }, + ], +}; diff --git a/erpnext/stock/report/stock_analytics/stock_analytics.js b/erpnext/stock/report/stock_analytics/stock_analytics.js index 071bfa22959c..0cfed95ba6b4 100644 --- a/erpnext/stock/report/stock_analytics/stock_analytics.js +++ b/erpnext/stock/report/stock_analytics/stock_analytics.js @@ -3,38 +3,38 @@ /* eslint-disable */ frappe.query_reports["Stock Analytics"] = { - "filters": [ + filters: [ { fieldname: "item_group", label: __("Item Group"), fieldtype: "Link", - options:"Item Group", + options: "Item Group", default: "", }, { fieldname: "item_code", label: __("Item"), fieldtype: "Link", - options:"Item", + options: "Item", default: "", - get_query: () => ({filters: { 'is_stock_item': 1 }}), + get_query: () => ({ filters: { is_stock_item: 1 } }), }, { fieldname: "value_quantity", label: __("Value Or Qty"), fieldtype: "Select", options: [ - { "value": "Value", "label": __("Value") }, - { "value": "Quantity", "label": __("Quantity") } + { value: "Value", label: __("Value") }, + { value: "Quantity", label: __("Quantity") }, ], default: "Value", - reqd: 1 + reqd: 1, }, { fieldname: "brand", label: __("Brand"), fieldtype: "Link", - options:"Brand", + options: "Brand", default: "", }, { @@ -51,92 +51,91 @@ frappe.query_reports["Stock Analytics"] = { fieldtype: "Link", options: "Warehouse", default: "", - get_query: function() { - const company = frappe.query_report.get_filter_value('company'); + get_query: function () { + const company = frappe.query_report.get_filter_value("company"); return { - filters: { 'company': company } - } - } + filters: { company: company }, + }; + }, }, { fieldname: "from_date", label: __("From Date"), fieldtype: "Date", default: frappe.defaults.get_global_default("year_start_date"), - reqd: 1 + reqd: 1, }, { - fieldname:"to_date", + fieldname: "to_date", label: __("To Date"), fieldtype: "Date", default: frappe.defaults.get_global_default("year_end_date"), - reqd: 1 + reqd: 1, }, { fieldname: "range", label: __("Range"), fieldtype: "Select", options: [ - { "value": "Weekly", "label": __("Weekly") }, - { "value": "Monthly", "label": __("Monthly") }, - { "value": "Quarterly", "label": __("Quarterly") }, - { "value": "Yearly", "label": __("Yearly") } + { value: "Weekly", label: __("Weekly") }, + { value: "Monthly", label: __("Monthly") }, + { value: "Quarterly", label: __("Quarterly") }, + { value: "Yearly", label: __("Yearly") }, ], default: "Monthly", - reqd: 1 - } + reqd: 1, + }, ], - after_datatable_render: function(datatable_obj) { - $(datatable_obj.wrapper).find(".dt-row-0").find('input[type=checkbox]').click(); + after_datatable_render: function (datatable_obj) { + $(datatable_obj.wrapper).find(".dt-row-0").find("input[type=checkbox]").click(); }, get_datatable_options(options) { return Object.assign(options, { checkboxColumn: true, events: { - onCheckRow: function(data) { + onCheckRow: function (data) { row_name = data[2].content; row_values = data.slice(7).map(function (column) { return column.content; - }) - entry = { - 'name':row_name, - 'values':row_values - } + }); + entry = { + name: row_name, + values: row_values, + }; let raw_data = frappe.query_report.chart.data; let new_datasets = raw_data.datasets; var found = false; - for(var i=0; i < new_datasets.length;i++){ - if(new_datasets[i].name == row_name){ + for (var i = 0; i < new_datasets.length; i++) { + if (new_datasets[i].name == row_name) { found = true; - new_datasets.splice(i,1); + new_datasets.splice(i, 1); break; } } - if(!found){ + if (!found) { new_datasets.push(entry); } let new_data = { labels: raw_data.labels, - datasets: new_datasets - } + datasets: new_datasets, + }; setTimeout(() => { - frappe.query_report.chart.update(new_data) - },500) - + frappe.query_report.chart.update(new_data); + }, 500); setTimeout(() => { frappe.query_report.chart.draw(true); - }, 1000) + }, 1000); frappe.query_report.raw_chart_data = new_data; }, - } + }, }); - } -} + }, +}; diff --git a/erpnext/stock/report/stock_and_account_value_comparison/stock_and_account_value_comparison.js b/erpnext/stock/report/stock_and_account_value_comparison/stock_and_account_value_comparison.js index 254f5273be24..6204c4f725f3 100644 --- a/erpnext/stock/report/stock_and_account_value_comparison/stock_and_account_value_comparison.js +++ b/erpnext/stock/report/stock_and_account_value_comparison/stock_and_account_value_comparison.js @@ -3,35 +3,35 @@ /* eslint-disable */ frappe.query_reports["Stock and Account Value Comparison"] = { - "filters": [ + filters: [ { - "label": __("Company"), - "fieldname": "company", - "fieldtype": "Link", - "options": "Company", - "reqd": 1, - "default": frappe.defaults.get_user_default("Company") + label: __("Company"), + fieldname: "company", + fieldtype: "Link", + options: "Company", + reqd: 1, + default: frappe.defaults.get_user_default("Company"), }, { - "label": __("Account"), - "fieldname": "account", - "fieldtype": "Link", - "options": "Account", - get_query: function() { - var company = frappe.query_report.get_filter_value('company'); + label: __("Account"), + fieldname: "account", + fieldtype: "Link", + options: "Account", + get_query: function () { + var company = frappe.query_report.get_filter_value("company"); return { filters: { - "account_type": "Stock", - "company": company - } - } - } + account_type: "Stock", + company: company, + }, + }; + }, }, { - "label": __("As On Date"), - "fieldname": "as_on_date", - "fieldtype": "Date", - "default": frappe.datetime.get_today(), + label: __("As On Date"), + fieldname: "as_on_date", + fieldtype: "Date", + default: frappe.datetime.get_today(), }, ], @@ -42,7 +42,7 @@ frappe.query_reports["Stock and Account Value Comparison"] = { }, onload(report) { - report.page.add_inner_button(__("Create Reposting Entries"), function() { + report.page.add_inner_button(__("Create Reposting Entries"), function () { let message = `

              Reposting Entries will change the value of @@ -54,7 +54,7 @@ frappe.query_reports["Stock and Account Value Comparison"] = {

              `; let indexes = frappe.query_report.datatable.rowmanager.getCheckedRows(); - let selected_rows = indexes.map(i => frappe.query_report.data[i]); + let selected_rows = indexes.map((i) => frappe.query_report.data[i]); if (!selected_rows.length) { frappe.throw(__("Please select rows to create Reposting Entries")); @@ -65,11 +65,10 @@ frappe.query_reports["Stock and Account Value Comparison"] = { method: "erpnext.stock.report.stock_and_account_value_comparison.stock_and_account_value_comparison.create_reposting_entries", args: { rows: selected_rows, - company: frappe.query_report.get_filter_values().company - } + company: frappe.query_report.get_filter_values().company, + }, }); - }); }); - } + }, }; diff --git a/erpnext/stock/report/stock_balance/stock_balance.js b/erpnext/stock/report/stock_balance/stock_balance.js index fe6e83eddade..ca2c053fdb14 100644 --- a/erpnext/stock/report/stock_balance/stock_balance.js +++ b/erpnext/stock/report/stock_balance/stock_balance.js @@ -2,119 +2,118 @@ // For license information, please see license.txt frappe.query_reports["Stock Balance"] = { - "filters": [ + filters: [ { - "fieldname": "company", - "label": __("Company"), - "fieldtype": "Link", - "width": "80", - "options": "Company", - "default": frappe.defaults.get_default("company") + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + width: "80", + options: "Company", + default: frappe.defaults.get_default("company"), }, { - "fieldname":"from_date", - "label": __("From Date"), - "fieldtype": "Date", - "width": "80", - "reqd": 1, - "default": frappe.datetime.add_months(frappe.datetime.get_today(), -1), + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + width: "80", + reqd: 1, + default: frappe.datetime.add_months(frappe.datetime.get_today(), -1), }, { - "fieldname":"to_date", - "label": __("To Date"), - "fieldtype": "Date", - "width": "80", - "reqd": 1, - "default": frappe.datetime.get_today() + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + width: "80", + reqd: 1, + default: frappe.datetime.get_today(), }, { - "fieldname": "item_group", - "label": __("Item Group"), - "fieldtype": "Link", - "width": "80", - "options": "Item Group" + fieldname: "item_group", + label: __("Item Group"), + fieldtype: "Link", + width: "80", + options: "Item Group", }, { - "fieldname": "item_code", - "label": __("Item"), - "fieldtype": "Link", - "width": "80", - "options": "Item", - "get_query": function() { + fieldname: "item_code", + label: __("Item"), + fieldtype: "Link", + width: "80", + options: "Item", + get_query: function () { return { query: "erpnext.controllers.queries.item_query", }; - } + }, }, { - "fieldname": "warehouse", - "label": __("Warehouse"), - "fieldtype": "Link", - "width": "80", - "options": "Warehouse", + fieldname: "warehouse", + label: __("Warehouse"), + fieldtype: "Link", + width: "80", + options: "Warehouse", get_query: () => { let warehouse_type = frappe.query_report.get_filter_value("warehouse_type"); let company = frappe.query_report.get_filter_value("company"); return { filters: { - ...warehouse_type && {warehouse_type}, - ...company && {company} - } - } - } + ...(warehouse_type && { warehouse_type }), + ...(company && { company }), + }, + }; + }, }, { - "fieldname": "warehouse_type", - "label": __("Warehouse Type"), - "fieldtype": "Link", - "width": "80", - "options": "Warehouse Type" + fieldname: "warehouse_type", + label: __("Warehouse Type"), + fieldtype: "Link", + width: "80", + options: "Warehouse Type", }, { - "fieldname": "valuation_field_type", - "label": __("Valuation Field Type"), - "fieldtype": "Select", - "width": "80", - "options": "Currency\nFloat", - "default": "Currency" + fieldname: "valuation_field_type", + label: __("Valuation Field Type"), + fieldtype: "Select", + width: "80", + options: "Currency\nFloat", + default: "Currency", }, { - "fieldname":"include_uom", - "label": __("Include UOM"), - "fieldtype": "Link", - "options": "UOM" + fieldname: "include_uom", + label: __("Include UOM"), + fieldtype: "Link", + options: "UOM", }, { - "fieldname": "show_variant_attributes", - "label": __("Show Variant Attributes"), - "fieldtype": "Check" + fieldname: "show_variant_attributes", + label: __("Show Variant Attributes"), + fieldtype: "Check", }, { - "fieldname": 'show_stock_ageing_data', - "label": __('Show Stock Ageing Data'), - "fieldtype": 'Check' + fieldname: "show_stock_ageing_data", + label: __("Show Stock Ageing Data"), + fieldtype: "Check", }, { - "fieldname": 'ignore_closing_balance', - "label": __('Ignore Closing Balance'), - "fieldtype": 'Check', - "default": 0 + fieldname: "ignore_closing_balance", + label: __("Ignore Closing Balance"), + fieldtype: "Check", + default: 0, }, ], - "formatter": function (value, row, column, data, default_formatter) { + formatter: function (value, row, column, data, default_formatter) { value = default_formatter(value, row, column, data); if (column.fieldname == "out_qty" && data && data.out_qty > 0) { value = "" + value + ""; - } - else if (column.fieldname == "in_qty" && data && data.in_qty > 0) { + } else if (column.fieldname == "in_qty" && data && data.in_qty > 0) { value = "" + value + ""; } return value; - } + }, }; -erpnext.utils.add_inventory_dimensions('Stock Balance', 8); \ No newline at end of file +erpnext.utils.add_inventory_dimensions("Stock Balance", 8); diff --git a/erpnext/stock/report/stock_ledger/stock_ledger.js b/erpnext/stock/report/stock_ledger/stock_ledger.js index b00b422a67a3..2c670bee9c1f 100644 --- a/erpnext/stock/report/stock_ledger/stock_ledger.js +++ b/erpnext/stock/report/stock_ledger/stock_ledger.js @@ -2,102 +2,101 @@ // License: GNU General Public License v3. See license.txt frappe.query_reports["Stock Ledger"] = { - "filters": [ + filters: [ { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_user_default("Company"), - "reqd": 1 + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), + reqd: 1, }, { - "fieldname":"from_date", - "label": __("From Date"), - "fieldtype": "Date", - "default": frappe.datetime.add_months(frappe.datetime.get_today(), -1), - "reqd": 1 + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + default: frappe.datetime.add_months(frappe.datetime.get_today(), -1), + reqd: 1, }, { - "fieldname":"to_date", - "label": __("To Date"), - "fieldtype": "Date", - "default": frappe.datetime.get_today(), - "reqd": 1 + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + default: frappe.datetime.get_today(), + reqd: 1, }, { - "fieldname":"warehouse", - "label": __("Warehouse"), - "fieldtype": "Link", - "options": "Warehouse", - "get_query": function() { - const company = frappe.query_report.get_filter_value('company'); + fieldname: "warehouse", + label: __("Warehouse"), + fieldtype: "Link", + options: "Warehouse", + get_query: function () { + const company = frappe.query_report.get_filter_value("company"); return { - filters: { 'company': company } - } - } + filters: { company: company }, + }; + }, }, { - "fieldname":"item_code", - "label": __("Item"), - "fieldtype": "Link", - "options": "Item", - "get_query": function() { + fieldname: "item_code", + label: __("Item"), + fieldtype: "Link", + options: "Item", + get_query: function () { return { - query: "erpnext.controllers.queries.item_query" - } - } + query: "erpnext.controllers.queries.item_query", + }; + }, }, { - "fieldname":"item_group", - "label": __("Item Group"), - "fieldtype": "Link", - "options": "Item Group" + fieldname: "item_group", + label: __("Item Group"), + fieldtype: "Link", + options: "Item Group", }, { - "fieldname":"batch_no", - "label": __("Batch No"), - "fieldtype": "Link", - "options": "Batch" + fieldname: "batch_no", + label: __("Batch No"), + fieldtype: "Link", + options: "Batch", }, { - "fieldname":"brand", - "label": __("Brand"), - "fieldtype": "Link", - "options": "Brand" + fieldname: "brand", + label: __("Brand"), + fieldtype: "Link", + options: "Brand", }, { - "fieldname":"voucher_no", - "label": __("Voucher #"), - "fieldtype": "Data" + fieldname: "voucher_no", + label: __("Voucher #"), + fieldtype: "Data", }, { - "fieldname":"project", - "label": __("Project"), - "fieldtype": "Link", - "options": "Project" + fieldname: "project", + label: __("Project"), + fieldtype: "Link", + options: "Project", }, { - "fieldname":"include_uom", - "label": __("Include UOM"), - "fieldtype": "Link", - "options": "UOM" + fieldname: "include_uom", + label: __("Include UOM"), + fieldtype: "Link", + options: "UOM", }, { - "fieldname": "valuation_field_type", - "label": __("Valuation Field Type"), - "fieldtype": "Select", - "width": "80", - "options": "Currency\nFloat", - "default": "Currency" + fieldname: "valuation_field_type", + label: __("Valuation Field Type"), + fieldtype: "Select", + width: "80", + options: "Currency\nFloat", + default: "Currency", }, ], - "formatter": function (value, row, column, data, default_formatter) { + formatter: function (value, row, column, data, default_formatter) { value = default_formatter(value, row, column, data); if (column.fieldname == "out_qty" && data && data.out_qty < 0) { value = "" + value + ""; - } - else if (column.fieldname == "in_qty" && data && data.in_qty > 0) { + } else if (column.fieldname == "in_qty" && data && data.in_qty > 0) { value = "" + value + ""; } @@ -105,4 +104,4 @@ frappe.query_reports["Stock Ledger"] = { }, }; -erpnext.utils.add_inventory_dimensions('Stock Ledger', 10); \ No newline at end of file +erpnext.utils.add_inventory_dimensions("Stock Ledger", 10); diff --git a/erpnext/stock/report/stock_ledger_invariant_check/stock_ledger_invariant_check.js b/erpnext/stock/report/stock_ledger_invariant_check/stock_ledger_invariant_check.js index 94e0b2dce3b4..166837dcc78a 100644 --- a/erpnext/stock/report/stock_ledger_invariant_check/stock_ledger_invariant_check.js +++ b/erpnext/stock/report/stock_ledger_invariant_check/stock_ledger_invariant_check.js @@ -3,42 +3,42 @@ /* eslint-disable */ const DIFFERENCE_FIELD_NAMES = [ - 'difference_in_qty', - 'fifo_qty_diff', - 'fifo_value_diff', - 'fifo_valuation_diff', - 'valuation_diff', - 'fifo_difference_diff', - 'diff_value_diff' + "difference_in_qty", + "fifo_qty_diff", + "fifo_value_diff", + "fifo_valuation_diff", + "valuation_diff", + "fifo_difference_diff", + "diff_value_diff", ]; -frappe.query_reports['Stock Ledger Invariant Check'] = { - 'filters': [ +frappe.query_reports["Stock Ledger Invariant Check"] = { + filters: [ { - 'fieldname': 'item_code', - 'fieldtype': 'Link', - 'label': 'Item', - 'mandatory': 1, - 'options': 'Item', - get_query: function() { + fieldname: "item_code", + fieldtype: "Link", + label: "Item", + mandatory: 1, + options: "Item", + get_query: function () { return { - filters: {is_stock_item: 1, has_serial_no: 0} - } - } + filters: { is_stock_item: 1, has_serial_no: 0 }, + }; + }, }, { - 'fieldname': 'warehouse', - 'fieldtype': 'Link', - 'label': 'Warehouse', - 'mandatory': 1, - 'options': 'Warehouse', - } + fieldname: "warehouse", + fieldtype: "Link", + label: "Warehouse", + mandatory: 1, + options: "Warehouse", + }, ], - formatter (value, row, column, data, default_formatter) { + formatter(value, row, column, data, default_formatter) { value = default_formatter(value, row, column, data); if (DIFFERENCE_FIELD_NAMES.includes(column.fieldname) && Math.abs(data[column.fieldname]) > 0.001) { - value = '' + value + ''; + value = '' + value + ""; } return value; }, @@ -50,7 +50,7 @@ frappe.query_reports['Stock Ledger Invariant Check'] = { }, onload(report) { - report.page.add_inner_button(__('Create Reposting Entry'), () => { + report.page.add_inner_button(__("Create Reposting Entry"), () => { let message = `

              @@ -62,23 +62,21 @@ frappe.query_reports['Stock Ledger Invariant Check'] = {

              Are you sure you want to create a Reposting Entry?

              `; let indexes = frappe.query_report.datatable.rowmanager.getCheckedRows(); - let selected_rows = indexes.map(i => frappe.query_report.data[i]); + let selected_rows = indexes.map((i) => frappe.query_report.data[i]); if (!selected_rows.length) { - frappe.throw(__('Please select a row to create a Reposting Entry')); - } - else if (selected_rows.length > 1) { - frappe.throw(__('Please select only one row to create a Reposting Entry')); - } - else { + frappe.throw(__("Please select a row to create a Reposting Entry")); + } else if (selected_rows.length > 1) { + frappe.throw(__("Please select only one row to create a Reposting Entry")); + } else { frappe.confirm(__(message), () => { frappe.call({ - method: 'erpnext.stock.report.stock_ledger_invariant_check.stock_ledger_invariant_check.create_reposting_entries', + method: "erpnext.stock.report.stock_ledger_invariant_check.stock_ledger_invariant_check.create_reposting_entries", args: { rows: selected_rows, item_code: frappe.query_report.get_filter_values().item_code, warehouse: frappe.query_report.get_filter_values().warehouse, - } + }, }); }); } diff --git a/erpnext/stock/report/stock_ledger_variance/stock_ledger_variance.js b/erpnext/stock/report/stock_ledger_variance/stock_ledger_variance.js index bf3a397feefc..07e7b59b5146 100644 --- a/erpnext/stock/report/stock_ledger_variance/stock_ledger_variance.js +++ b/erpnext/stock/report/stock_ledger_variance/stock_ledger_variance.js @@ -8,60 +8,55 @@ const DIFFERENCE_FIELD_NAMES = [ "fifo_valuation_diff", "valuation_diff", "fifo_difference_diff", - "diff_value_diff" + "diff_value_diff", ]; frappe.query_reports["Stock Ledger Variance"] = { - "filters": [ + filters: [ { - "fieldname": "company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "reqd": 1, - "default": frappe.defaults.get_user_default("Company") + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + reqd: 1, + default: frappe.defaults.get_user_default("Company"), }, { - "fieldname": "item_code", - "fieldtype": "Link", - "label": __("Item"), - "options": "Item", - get_query: function() { + fieldname: "item_code", + fieldtype: "Link", + label: __("Item"), + options: "Item", + get_query: function () { return { - filters: {is_stock_item: 1, has_serial_no: 0} - } - } + filters: { is_stock_item: 1, has_serial_no: 0 }, + }; + }, }, { - "fieldname": "warehouse", - "fieldtype": "Link", - "label": __("Warehouse"), - "options": "Warehouse", - get_query: function() { + fieldname: "warehouse", + fieldtype: "Link", + label: __("Warehouse"), + options: "Warehouse", + get_query: function () { return { - filters: {is_group: 0, disabled: 0} - } - } + filters: { is_group: 0, disabled: 0 }, + }; + }, }, { - "fieldname": "difference_in", - "fieldtype": "Select", - "label": __("Difference In"), - "options": [ - "", - "Qty", - "Value", - "Valuation", - ], + fieldname: "difference_in", + fieldtype: "Select", + label: __("Difference In"), + options: ["", "Qty", "Value", "Valuation"], }, { - "fieldname": "include_disabled", - "fieldtype": "Check", - "label": __("Include Disabled"), - } + fieldname: "include_disabled", + fieldtype: "Check", + label: __("Include Disabled"), + }, ], - formatter (value, row, column, data, default_formatter) { + formatter(value, row, column, data, default_formatter) { value = default_formatter(value, row, column, data); if (DIFFERENCE_FIELD_NAMES.includes(column.fieldname) && Math.abs(data[column.fieldname]) > 0.001) { @@ -78,7 +73,7 @@ frappe.query_reports["Stock Ledger Variance"] = { }, onload(report) { - report.page.add_inner_button(__('Create Reposting Entries'), () => { + report.page.add_inner_button(__("Create Reposting Entries"), () => { let message = `

              @@ -90,7 +85,7 @@ frappe.query_reports["Stock Ledger Variance"] = {

              Are you sure you want to create Reposting Entries?

              `; let indexes = frappe.query_report.datatable.rowmanager.getCheckedRows(); - let selected_rows = indexes.map(i => frappe.query_report.data[i]); + let selected_rows = indexes.map((i) => frappe.query_report.data[i]); if (!selected_rows.length) { frappe.throw(__("Please select rows to create Reposting Entries")); @@ -98,10 +93,10 @@ frappe.query_reports["Stock Ledger Variance"] = { frappe.confirm(__(message), () => { frappe.call({ - method: 'erpnext.stock.report.stock_ledger_invariant_check.stock_ledger_invariant_check.create_reposting_entries', + method: "erpnext.stock.report.stock_ledger_invariant_check.stock_ledger_invariant_check.create_reposting_entries", args: { rows: selected_rows, - } + }, }); }); }); diff --git a/erpnext/stock/report/stock_projected_qty/stock_projected_qty.js b/erpnext/stock/report/stock_projected_qty/stock_projected_qty.js index cb109f8050d6..6e333aadfa51 100644 --- a/erpnext/stock/report/stock_projected_qty/stock_projected_qty.js +++ b/erpnext/stock/report/stock_projected_qty/stock_projected_qty.js @@ -2,55 +2,55 @@ // License: GNU General Public License v3. See license.txt frappe.query_reports["Stock Projected Qty"] = { - "filters": [ + filters: [ { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_user_default("Company") + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), }, { - "fieldname":"warehouse", - "label": __("Warehouse"), - "fieldtype": "Link", - "options": "Warehouse", - "get_query": () => { + fieldname: "warehouse", + label: __("Warehouse"), + fieldtype: "Link", + options: "Warehouse", + get_query: () => { return { filters: { - company: frappe.query_report.get_filter_value('company') - } - } - } + company: frappe.query_report.get_filter_value("company"), + }, + }; + }, }, { - "fieldname":"item_code", - "label": __("Item"), - "fieldtype": "Link", - "options": "Item", - "get_query": function() { + fieldname: "item_code", + label: __("Item"), + fieldtype: "Link", + options: "Item", + get_query: function () { return { - query: "erpnext.controllers.queries.item_query" - } - } + query: "erpnext.controllers.queries.item_query", + }; + }, }, { - "fieldname":"item_group", - "label": __("Item Group"), - "fieldtype": "Link", - "options": "Item Group" + fieldname: "item_group", + label: __("Item Group"), + fieldtype: "Link", + options: "Item Group", }, { - "fieldname":"brand", - "label": __("Brand"), - "fieldtype": "Link", - "options": "Brand" + fieldname: "brand", + label: __("Brand"), + fieldtype: "Link", + options: "Brand", }, { - "fieldname":"include_uom", - "label": __("Include UOM"), - "fieldtype": "Link", - "options": "UOM" - } - ] -} + fieldname: "include_uom", + label: __("Include UOM"), + fieldtype: "Link", + options: "UOM", + }, + ], +}; diff --git a/erpnext/stock/report/stock_qty_vs_serial_no_count/stock_qty_vs_serial_no_count.js b/erpnext/stock/report/stock_qty_vs_serial_no_count/stock_qty_vs_serial_no_count.js index 2a0fd4025cc0..b0f5f5ccd5af 100644 --- a/erpnext/stock/report/stock_qty_vs_serial_no_count/stock_qty_vs_serial_no_count.js +++ b/erpnext/stock/report/stock_qty_vs_serial_no_count/stock_qty_vs_serial_no_count.js @@ -3,40 +3,39 @@ /* eslint-disable */ frappe.query_reports["Stock Qty vs Serial No Count"] = { - "filters": [ + filters: [ { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "default": frappe.defaults.get_user_default("Company"), - "reqd": 1 + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), + reqd: 1, }, { - "fieldname":"warehouse", - "label": __("Warehouse"), - "fieldtype": "Link", - "options": "Warehouse", - "get_query": function() { - const company = frappe.query_report.get_filter_value('company'); + fieldname: "warehouse", + label: __("Warehouse"), + fieldtype: "Link", + options: "Warehouse", + get_query: function () { + const company = frappe.query_report.get_filter_value("company"); return { - filters: { 'company': company } - } + filters: { company: company }, + }; }, - "reqd": 1 + reqd: 1, }, ], - "formatter": function (value, row, column, data, default_formatter) { + formatter: function (value, row, column, data, default_formatter) { value = default_formatter(value, row, column, data); if (column.fieldname == "difference" && data) { if (data.difference > 0) { value = "" + value + ""; - } - else if (data.difference < 0) { + } else if (data.difference < 0) { value = "" + value + ""; } } return value; - } + }, }; diff --git a/erpnext/stock/report/supplier_wise_sales_analytics/supplier_wise_sales_analytics.js b/erpnext/stock/report/supplier_wise_sales_analytics/supplier_wise_sales_analytics.js index 5b0064707569..92a01c4ce201 100644 --- a/erpnext/stock/report/supplier_wise_sales_analytics/supplier_wise_sales_analytics.js +++ b/erpnext/stock/report/supplier_wise_sales_analytics/supplier_wise_sales_analytics.js @@ -2,27 +2,27 @@ // License: GNU General Public License v3. See license.txt frappe.query_reports["Supplier-Wise Sales Analytics"] = { - "filters": [ + filters: [ { - "fieldname":"supplier", - "label": __("Supplier"), - "fieldtype": "Link", - "options": "Supplier", - "width": "80" + fieldname: "supplier", + label: __("Supplier"), + fieldtype: "Link", + options: "Supplier", + width: "80", }, { - "fieldname":"from_date", - "label": __("From Date"), - "fieldtype": "Date", - "width": "80", - "default": frappe.datetime.month_start() + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + width: "80", + default: frappe.datetime.month_start(), }, { - "fieldname":"to_date", - "label": __("To Date"), - "fieldtype": "Date", - "width": "80", - "default": frappe.datetime.month_end() + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + width: "80", + default: frappe.datetime.month_end(), }, - ] -} + ], +}; diff --git a/erpnext/stock/report/total_stock_summary/total_stock_summary.js b/erpnext/stock/report/total_stock_summary/total_stock_summary.js index 88054aaea736..78ab31a7df73 100644 --- a/erpnext/stock/report/total_stock_summary/total_stock_summary.js +++ b/erpnext/stock/report/total_stock_summary/total_stock_summary.js @@ -3,25 +3,25 @@ /* eslint-disable */ frappe.query_reports["Total Stock Summary"] = { - "filters": [ + filters: [ { - "fieldname":"group_by", - "label": __("Group By"), - "fieldtype": "Select", - "width": "80", - "reqd": 1, - "options": ["Warehouse", "Company"], - "default": "Warehouse", + fieldname: "group_by", + label: __("Group By"), + fieldtype: "Select", + width: "80", + reqd: 1, + options: ["Warehouse", "Company"], + default: "Warehouse", }, { - "fieldname": "company", - "label": __("Company"), - "fieldtype": "Link", - "width": "80", - "options": "Company", - "reqd": 1, - "default": frappe.defaults.get_user_default("Company"), - "depends_on": "eval: doc.group_by != 'Company'", + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + width: "80", + options: "Company", + reqd: 1, + default: frappe.defaults.get_user_default("Company"), + depends_on: "eval: doc.group_by != 'Company'", }, - ] -} + ], +}; diff --git a/erpnext/stock/report/warehouse_wise_item_balance_age_and_value/warehouse_wise_item_balance_age_and_value.js b/erpnext/stock/report/warehouse_wise_item_balance_age_and_value/warehouse_wise_item_balance_age_and_value.js index 39cfd7274f2b..8a0c1a7af6d7 100644 --- a/erpnext/stock/report/warehouse_wise_item_balance_age_and_value/warehouse_wise_item_balance_age_and_value.js +++ b/erpnext/stock/report/warehouse_wise_item_balance_age_and_value/warehouse_wise_item_balance_age_and_value.js @@ -3,49 +3,49 @@ /* eslint-disable */ frappe.query_reports["Warehouse wise Item Balance Age and Value"] = { - "filters": [ -{ - "fieldname":"from_date", - "label": __("From Date"), - "fieldtype": "Date", - "width": "80", - "reqd": 1, - "default": frappe.datetime.add_months(frappe.datetime.get_today(), -1), - }, - { - "fieldname":"to_date", - "label": __("To Date"), - "fieldtype": "Date", - "width": "80", - "reqd": 1, - "default": frappe.datetime.get_today() - }, - { - "fieldname": "item_group", - "label": __("Item Group"), - "fieldtype": "Link", - "width": "80", - "options": "Item Group" - }, - { - "fieldname": "item_code", - "label": __("Item"), - "fieldtype": "Link", - "width": "80", - "options": "Item" - }, - { - "fieldname": "warehouse", - "label": __("Warehouse"), - "fieldtype": "Link", - "width": "80", - "options": "Warehouse" - }, - { - "fieldname": "filter_total_zero_qty", - "label": __("Filter Total Zero Qty"), - "fieldtype": "Check", - "default": 1 - }, - ] -} + filters: [ + { + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + width: "80", + reqd: 1, + default: frappe.datetime.add_months(frappe.datetime.get_today(), -1), + }, + { + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + width: "80", + reqd: 1, + default: frappe.datetime.get_today(), + }, + { + fieldname: "item_group", + label: __("Item Group"), + fieldtype: "Link", + width: "80", + options: "Item Group", + }, + { + fieldname: "item_code", + label: __("Item"), + fieldtype: "Link", + width: "80", + options: "Item", + }, + { + fieldname: "warehouse", + label: __("Warehouse"), + fieldtype: "Link", + width: "80", + options: "Warehouse", + }, + { + fieldname: "filter_total_zero_qty", + label: __("Filter Total Zero Qty"), + fieldtype: "Check", + default: 1, + }, + ], +}; diff --git a/erpnext/stock/report/warehouse_wise_stock_balance/warehouse_wise_stock_balance.js b/erpnext/stock/report/warehouse_wise_stock_balance/warehouse_wise_stock_balance.js index 752e464e27cd..808fe29237fe 100644 --- a/erpnext/stock/report/warehouse_wise_stock_balance/warehouse_wise_stock_balance.js +++ b/erpnext/stock/report/warehouse_wise_stock_balance/warehouse_wise_stock_balance.js @@ -3,25 +3,24 @@ /* eslint-disable */ frappe.query_reports["Warehouse Wise Stock Balance"] = { - "filters": [ + filters: [ { - "fieldname":"company", - "label": __("Company"), - "fieldtype": "Link", - "options": "Company", - "reqd": 1, - "default": frappe.defaults.get_user_default("Company") + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + reqd: 1, + default: frappe.defaults.get_user_default("Company"), }, { - "fieldname":"show_disabled_warehouses", - "label": __("Show Disabled Warehouses"), - "fieldtype": "Check", - "default": 0 - - } + fieldname: "show_disabled_warehouses", + label: __("Show Disabled Warehouses"), + fieldtype: "Check", + default: 0, + }, ], - "initial_depth": 3, - "tree": true, - "parent_field": "parent_warehouse", - "name_field": "warehouse" + initial_depth: 3, + tree: true, + parent_field: "parent_warehouse", + name_field: "warehouse", }; diff --git a/erpnext/subcontracting/doctype/subcontracting_order/subcontracting_order_list.js b/erpnext/subcontracting/doctype/subcontracting_order/subcontracting_order_list.js index 7ca12642c5f5..7c12abd67223 100644 --- a/erpnext/subcontracting/doctype/subcontracting_order/subcontracting_order_list.js +++ b/erpnext/subcontracting/doctype/subcontracting_order/subcontracting_order_list.js @@ -1,18 +1,18 @@ // Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.listview_settings['Subcontracting Order'] = { +frappe.listview_settings["Subcontracting Order"] = { get_indicator: function (doc) { const status_colors = { - "Draft": "grey", - "Open": "orange", + Draft: "grey", + Open: "orange", "Partially Received": "yellow", - "Completed": "green", + Completed: "green", "Partial Material Transferred": "purple", "Material Transferred": "blue", - "Closed": "red", - "Cancelled": "red", + Closed: "red", + Cancelled: "red", }; return [__(doc.status), status_colors[doc.status], "status,=," + doc.status]; }, -}; \ No newline at end of file +}; diff --git a/erpnext/subcontracting/doctype/subcontracting_receipt/subcontracting_receipt_list.js b/erpnext/subcontracting/doctype/subcontracting_receipt/subcontracting_receipt_list.js index 14a4e4ad6cbc..be6c0d0b18f3 100644 --- a/erpnext/subcontracting/doctype/subcontracting_receipt/subcontracting_receipt_list.js +++ b/erpnext/subcontracting/doctype/subcontracting_receipt/subcontracting_receipt_list.js @@ -1,14 +1,14 @@ // Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.listview_settings['Subcontracting Receipt'] = { +frappe.listview_settings["Subcontracting Receipt"] = { get_indicator: function (doc) { const status_colors = { - "Draft": "grey", - "Return": "gray", + Draft: "grey", + Return: "gray", "Return Issued": "grey", - "Completed": "green", + Completed: "green", }; return [__(doc.status), status_colors[doc.status], "status,=," + doc.status]; }, -}; \ No newline at end of file +}; diff --git a/erpnext/support/doctype/issue/issue.js b/erpnext/support/doctype/issue/issue.js index 9f91dc1726da..03d209e99e33 100644 --- a/erpnext/support/doctype/issue/issue.js +++ b/erpnext/support/doctype/issue/issue.js @@ -1,40 +1,47 @@ frappe.ui.form.on("Issue", { - onload: function(frm) { + onload: function (frm) { frm.email_field = "raised_by"; - frappe.db.get_value("Support Settings", {name: "Support Settings"}, - ["allow_resetting_service_level_agreement", "track_service_level_agreement"], (r) => { + frappe.db.get_value( + "Support Settings", + { name: "Support Settings" }, + ["allow_resetting_service_level_agreement", "track_service_level_agreement"], + (r) => { if (r && r.track_service_level_agreement == "0") { frm.set_df_property("service_level_section", "hidden", 1); } if (r && r.allow_resetting_service_level_agreement == "0") { frm.set_df_property("reset_service_level_agreement", "hidden", 1); } - }); + } + ); // buttons if (frm.doc.status !== "Closed") { - frm.add_custom_button(__("Close"), function() { + frm.add_custom_button(__("Close"), function () { frm.set_value("status", "Closed"); frm.save(); }); - frm.add_custom_button(__("Task"), function() { - frappe.model.open_mapped_doc({ - method: "erpnext.support.doctype.issue.issue.make_task", - frm: frm - }); - }, __("Create")); - + frm.add_custom_button( + __("Task"), + function () { + frappe.model.open_mapped_doc({ + method: "erpnext.support.doctype.issue.issue.make_task", + frm: frm, + }); + }, + __("Create") + ); } else { - frm.add_custom_button(__("Reopen"), function() { + frm.add_custom_button(__("Reopen"), function () { frm.set_value("status", "Open"); frm.save(); }); } }, - reset_service_level_agreement: function(frm) { + reset_service_level_agreement: function (frm) { let reset_sla = new frappe.ui.Dialog({ title: __("Reset Service Level Agreement"), fields: [ @@ -42,8 +49,8 @@ frappe.ui.form.on("Issue", { fieldtype: "Data", fieldname: "reason", label: __("Reason"), - reqd: 1 - } + reqd: 1, + }, ], primary_action_label: __("Reset"), primary_action: (values) => { @@ -53,39 +60,42 @@ frappe.ui.form.on("Issue", { frappe.show_alert({ indicator: "green", - message: __("Resetting Service Level Agreement.") + message: __("Resetting Service Level Agreement."), }); - frappe.call("erpnext.support.doctype.service_level_agreement.service_level_agreement.reset_service_level_agreement", { - reason: values.reason, - user: frappe.session.user_email, - doctype: frm.doc.doctype, - docname: frm.doc.name, - }, () => { - reset_sla.enable_primary_action(); - frm.refresh(); - frappe.msgprint(__("Service Level Agreement was reset.")); - }); - } + frappe.call( + "erpnext.support.doctype.service_level_agreement.service_level_agreement.reset_service_level_agreement", + { + reason: values.reason, + user: frappe.session.user_email, + doctype: frm.doc.doctype, + docname: frm.doc.name, + }, + () => { + reset_sla.enable_primary_action(); + frm.refresh(); + frappe.msgprint(__("Service Level Agreement was reset.")); + } + ); + }, }); reset_sla.show(); }, - - timeline_refresh: function(frm) { + timeline_refresh: function (frm) { if (!frm.timeline.wrapper.find(".btn-split-issue").length) { let split_issue_btn = $(` - ${frappe.utils.icon('branch', 'sm')} + ${frappe.utils.icon("branch", "sm")} `); let communication_box = frm.timeline.wrapper.find('.timeline-item[data-doctype="Communication"]'); - communication_box.find('.actions').prepend(split_issue_btn); + communication_box.find(".actions").prepend(split_issue_btn); if (!frm.timeline.wrapper.data("split-issue-event-attached")) { - frm.timeline.wrapper.on('click', '.btn-split-issue', (e) => { + frm.timeline.wrapper.on("click", ".btn-split-issue", (e) => { var dialog = new frappe.ui.Dialog({ title: __("Split Issue"), fields: [ @@ -94,20 +104,30 @@ frappe.ui.form.on("Issue", { fieldtype: "Data", reqd: 1, label: __("Subject"), - description: __("All communications including and above this shall be moved into the new Issue") - } + description: __( + "All communications including and above this shall be moved into the new Issue" + ), + }, ], primary_action_label: __("Split"), primary_action: () => { - frm.call("split_issue", { - subject: dialog.fields_dict.subject.value, - communication_id: e.currentTarget.closest(".timeline-item").getAttribute("data-name") - }, (r) => { - frappe.msgprint(`New issue created: ${r.message}`); - frm.reload_doc(); - dialog.hide(); - }); - } + frm.call( + "split_issue", + { + subject: dialog.fields_dict.subject.value, + communication_id: e.currentTarget + .closest(".timeline-item") + .getAttribute("data-name"), + }, + (r) => { + frappe.msgprint( + `New issue created: ${r.message}` + ); + frm.reload_doc(); + dialog.hide(); + } + ); + }, }); dialog.show(); }); diff --git a/erpnext/support/doctype/issue/issue_list.js b/erpnext/support/doctype/issue/issue_list.js index 5c9d4ed98906..8aa1650c5999 100644 --- a/erpnext/support/doctype/issue/issue_list.js +++ b/erpnext/support/doctype/issue/issue_list.js @@ -1,30 +1,30 @@ -frappe.listview_settings['Issue'] = { - colwidths: {"subject": 6}, - add_fields: ['priority'], +frappe.listview_settings["Issue"] = { + colwidths: { subject: 6 }, + add_fields: ["priority"], filters: [["status", "=", "Open"]], - onload: function(listview) { + onload: function (listview) { var method = "erpnext.support.doctype.issue.issue.set_multiple_status"; - listview.page.add_action_item(__("Set as Open"), function() { - listview.call_for_selected_items(method, {"status": "Open"}); + listview.page.add_action_item(__("Set as Open"), function () { + listview.call_for_selected_items(method, { status: "Open" }); }); - listview.page.add_action_item(__("Set as Closed"), function() { - listview.call_for_selected_items(method, {"status": "Closed"}); + listview.page.add_action_item(__("Set as Closed"), function () { + listview.call_for_selected_items(method, { status: "Closed" }); }); }, - get_indicator: function(doc) { - if (doc.status === 'Open') { + get_indicator: function (doc) { + if (doc.status === "Open") { const color = { - 'Low': 'yellow', - 'Medium': 'orange', - 'High': 'red' + Low: "yellow", + Medium: "orange", + High: "red", }; - return [__(doc.status), color[doc.priority] || 'red', `status,=,Open`]; - } else if (doc.status === 'Closed') { + return [__(doc.status), color[doc.priority] || "red", `status,=,Open`]; + } else if (doc.status === "Closed") { return [__(doc.status), "green", "status,=," + doc.status]; } else { return [__(doc.status), "gray", "status,=," + doc.status]; } - } -} + }, +}; diff --git a/erpnext/support/doctype/issue_priority/issue_priority.js b/erpnext/support/doctype/issue_priority/issue_priority.js index 37ce6a54bf79..e777d0690ca7 100644 --- a/erpnext/support/doctype/issue_priority/issue_priority.js +++ b/erpnext/support/doctype/issue_priority/issue_priority.js @@ -1,8 +1,7 @@ // Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Issue Priority', { +frappe.ui.form.on("Issue Priority", { // refresh: function(frm) { - // } }); diff --git a/erpnext/support/doctype/issue_type/issue_type.js b/erpnext/support/doctype/issue_type/issue_type.js index 2b3d14ef712b..aa0c4565d6ca 100644 --- a/erpnext/support/doctype/issue_type/issue_type.js +++ b/erpnext/support/doctype/issue_type/issue_type.js @@ -1,8 +1,6 @@ // Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Issue Type', { - refresh: function(frm) { - - } +frappe.ui.form.on("Issue Type", { + refresh: function (frm) {}, }); diff --git a/erpnext/support/doctype/service_level_agreement/service_level_agreement.js b/erpnext/support/doctype/service_level_agreement/service_level_agreement.js index 4dbb0e7e86f8..a8b85de9d6a6 100644 --- a/erpnext/support/doctype/service_level_agreement/service_level_agreement.js +++ b/erpnext/support/doctype/service_level_agreement/service_level_agreement.js @@ -1,121 +1,145 @@ // Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Service Level Agreement', { - setup: function(frm) { +frappe.ui.form.on("Service Level Agreement", { + setup: function (frm) { if (cint(frm.doc.apply_sla_for_resolution) === 1) { - frm.get_field('priorities').grid.editable_fields = [ - {fieldname: 'default_priority', columns: 1}, - {fieldname: 'priority', columns: 2}, - {fieldname: 'response_time', columns: 2}, - {fieldname: 'resolution_time', columns: 2} + frm.get_field("priorities").grid.editable_fields = [ + { fieldname: "default_priority", columns: 1 }, + { fieldname: "priority", columns: 2 }, + { fieldname: "response_time", columns: 2 }, + { fieldname: "resolution_time", columns: 2 }, ]; } else { - frm.get_field('priorities').grid.editable_fields = [ - {fieldname: 'default_priority', columns: 1}, - {fieldname: 'priority', columns: 2}, - {fieldname: 'response_time', columns: 3}, + frm.get_field("priorities").grid.editable_fields = [ + { fieldname: "default_priority", columns: 1 }, + { fieldname: "priority", columns: 2 }, + { fieldname: "response_time", columns: 3 }, ]; } }, - refresh: function(frm) { - frm.trigger('fetch_status_fields'); - frm.trigger('toggle_resolution_fields'); - frm.trigger('default_service_level_agreement'); - frm.trigger('entity'); + refresh: function (frm) { + frm.trigger("fetch_status_fields"); + frm.trigger("toggle_resolution_fields"); + frm.trigger("default_service_level_agreement"); + frm.trigger("entity"); }, - default_service_level_agreement: function(frm) { - const field = frm.get_field('default_service_level_agreement'); + default_service_level_agreement: function (frm) { + const field = frm.get_field("default_service_level_agreement"); if (frm.doc.default_service_level_agreement) { - field.set_description(__('SLA will be applied on every {0}', [frm.doc.document_type])); + field.set_description(__("SLA will be applied on every {0}", [frm.doc.document_type])); } else { - field.set_description(__('Enable to apply SLA on every {0}', [frm.doc.document_type])); + field.set_description(__("Enable to apply SLA on every {0}", [frm.doc.document_type])); } }, - document_type: function(frm) { - frm.trigger('fetch_status_fields'); - frm.trigger('default_service_level_agreement'); + document_type: function (frm) { + frm.trigger("fetch_status_fields"); + frm.trigger("default_service_level_agreement"); }, - entity_type: function(frm) { - frm.set_value('entity', undefined); + entity_type: function (frm) { + frm.set_value("entity", undefined); }, - entity: function(frm) { - const field = frm.get_field('entity'); + entity: function (frm) { + const field = frm.get_field("entity"); if (frm.doc.entity) { - const and_descendants = frm.doc.entity_type != 'Customer' ? ' ' + __('or its descendants') : ''; + const and_descendants = frm.doc.entity_type != "Customer" ? " " + __("or its descendants") : ""; field.set_description( - __('SLA will be applied if {1} is set as {2}{3}', [ - frm.doc.document_type, frm.doc.entity_type, - frm.doc.entity, and_descendants + __("SLA will be applied if {1} is set as {2}{3}", [ + frm.doc.document_type, + frm.doc.entity_type, + frm.doc.entity, + and_descendants, ]) ); } else { - field.set_description(''); + field.set_description(""); } }, - fetch_status_fields: function(frm) { + fetch_status_fields: function (frm) { let allow_statuses = []; let exclude_statuses = []; if (frm.doc.document_type) { frappe.model.with_doctype(frm.doc.document_type, () => { - let statuses = frappe.meta.get_docfield(frm.doc.document_type, 'status', frm.doc.name).options; - statuses = statuses.split('\n'); - - exclude_statuses = ['Open', 'Closed']; + let statuses = frappe.meta.get_docfield( + frm.doc.document_type, + "status", + frm.doc.name + ).options; + statuses = statuses.split("\n"); + + exclude_statuses = ["Open", "Closed"]; allow_statuses = statuses.filter((status) => !exclude_statuses.includes(status)); frm.fields_dict.pause_sla_on.grid.update_docfield_property( - 'status', 'options', [''].concat(allow_statuses) + "status", + "options", + [""].concat(allow_statuses) ); - exclude_statuses = ['Open']; + exclude_statuses = ["Open"]; allow_statuses = statuses.filter((status) => !exclude_statuses.includes(status)); frm.fields_dict.sla_fulfilled_on.grid.update_docfield_property( - 'status', 'options', [''].concat(allow_statuses) + "status", + "options", + [""].concat(allow_statuses) ); }); } - frm.refresh_field('pause_sla_on'); + frm.refresh_field("pause_sla_on"); }, - apply_sla_for_resolution: function(frm) { - frm.trigger('toggle_resolution_fields'); + apply_sla_for_resolution: function (frm) { + frm.trigger("toggle_resolution_fields"); }, - toggle_resolution_fields: function(frm) { + toggle_resolution_fields: function (frm) { if (cint(frm.doc.apply_sla_for_resolution) === 1) { - frm.fields_dict.priorities.grid.update_docfield_property('resolution_time', 'hidden', 0); - frm.fields_dict.priorities.grid.update_docfield_property('resolution_time', 'reqd', 1); + frm.fields_dict.priorities.grid.update_docfield_property("resolution_time", "hidden", 0); + frm.fields_dict.priorities.grid.update_docfield_property("resolution_time", "reqd", 1); } else { - frm.fields_dict.priorities.grid.update_docfield_property('resolution_time', 'hidden', 1); - frm.fields_dict.priorities.grid.update_docfield_property('resolution_time', 'reqd', 0); + frm.fields_dict.priorities.grid.update_docfield_property("resolution_time", "hidden", 1); + frm.fields_dict.priorities.grid.update_docfield_property("resolution_time", "reqd", 0); } - frm.refresh_field('priorities'); + frm.refresh_field("priorities"); }, - onload: function(frm) { - frm.set_query("document_type", function() { + onload: function (frm) { + frm.set_query("document_type", function () { let invalid_doctypes = frappe.model.core_doctypes_list; - invalid_doctypes.push(frm.doc.doctype, 'Cost Center', 'Company'); + invalid_doctypes.push(frm.doc.doctype, "Cost Center", "Company"); return { filters: [ - ['DocType', 'issingle', '=', 0], - ['DocType', 'istable', '=', 0], - ['DocType', 'is_submittable', '=', 0], - ['DocType', 'name', 'not in', invalid_doctypes], - ['DocType', 'module', 'not in', ["Email", "Core", "Custom", "Event Streaming", "Social", "Data Migration", "Geo", "Desk"]] - ] + ["DocType", "issingle", "=", 0], + ["DocType", "istable", "=", 0], + ["DocType", "is_submittable", "=", 0], + ["DocType", "name", "not in", invalid_doctypes], + [ + "DocType", + "module", + "not in", + [ + "Email", + "Core", + "Custom", + "Event Streaming", + "Social", + "Data Migration", + "Geo", + "Desk", + ], + ], + ], }; }); - } + }, }); diff --git a/erpnext/support/doctype/support_settings/support_settings.js b/erpnext/support/doctype/support_settings/support_settings.js index 78adca81ca57..3a1cb84ba854 100644 --- a/erpnext/support/doctype/support_settings/support_settings.js +++ b/erpnext/support/doctype/support_settings/support_settings.js @@ -1,8 +1,8 @@ // Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Support Settings', { - refresh: function(frm) { +frappe.ui.form.on("Support Settings", { + refresh: function (frm) { // - } + }, }); diff --git a/erpnext/support/doctype/warranty_claim/warranty_claim.js b/erpnext/support/doctype/warranty_claim/warranty_claim.js index 10cb37f51240..d7b77f71c5ee 100644 --- a/erpnext/support/doctype/warranty_claim/warranty_claim.js +++ b/erpnext/support/doctype/warranty_claim/warranty_claim.js @@ -43,10 +43,7 @@ frappe.ui.form.on("Warranty Claim", { doctype: "Customer", }; - if ( - !frm.doc.__islocal && - ["Open", "Work In Progress"].includes(frm.doc.status) - ) { + if (!frm.doc.__islocal && ["Open", "Work In Progress"].includes(frm.doc.status)) { frm.add_custom_button(__("Maintenance Visit"), () => { frappe.model.open_mapped_doc({ method: "erpnext.support.doctype.warranty_claim.warranty_claim.make_maintenance_visit", diff --git a/erpnext/support/doctype/warranty_claim/warranty_claim_list.js b/erpnext/support/doctype/warranty_claim/warranty_claim_list.js index e162e137ba62..fdafb0ec59f8 100644 --- a/erpnext/support/doctype/warranty_claim/warranty_claim_list.js +++ b/erpnext/support/doctype/warranty_claim/warranty_claim_list.js @@ -1,4 +1,4 @@ -frappe.listview_settings['Warranty Claim'] = { +frappe.listview_settings["Warranty Claim"] = { add_fields: ["status", "customer", "item_code"], - filters:[["status","=", "Open"]] + filters: [["status", "=", "Open"]], }; diff --git a/erpnext/support/report/first_response_time_for_issues/first_response_time_for_issues.js b/erpnext/support/report/first_response_time_for_issues/first_response_time_for_issues.js index 18691fe264f5..304515b1f0cd 100644 --- a/erpnext/support/report/first_response_time_for_issues/first_response_time_for_issues.js +++ b/erpnext/support/report/first_response_time_for_issues/first_response_time_for_issues.js @@ -3,41 +3,43 @@ /* eslint-disable */ frappe.query_reports["First Response Time for Issues"] = { - "filters": [ + filters: [ { - "fieldname": "from_date", - "label": __("From Date"), - "fieldtype": "Date", - "reqd": 1, - "default": frappe.datetime.add_days(frappe.datetime.nowdate(), -30) + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + reqd: 1, + default: frappe.datetime.add_days(frappe.datetime.nowdate(), -30), }, { - "fieldname": "to_date", - "label": __("To Date"), - "fieldtype": "Date", - "reqd": 1, - "default":frappe.datetime.nowdate() - } + fieldname: "to_date", + label: __("To Date"), + fieldtype: "Date", + reqd: 1, + default: frappe.datetime.nowdate(), + }, ], - get_chart_data: function(_columns, result) { + get_chart_data: function (_columns, result) { return { data: { - labels: result.map(d => d.creation_date), - datasets: [{ - name: 'First Response Time', - values: result.map(d => d.first_response_time) - }] + labels: result.map((d) => d.creation_date), + datasets: [ + { + name: "First Response Time", + values: result.map((d) => d.first_response_time), + }, + ], }, type: "line", tooltipOptions: { - formatTooltipY: d => { + formatTooltipY: (d) => { let duration_options = { hide_days: 0, - hide_seconds: 0 + hide_seconds: 0, }; return frappe.utils.get_formatted_duration(d, duration_options); - } - } - } - } + }, + }, + }; + }, }; diff --git a/erpnext/support/report/issue_analytics/issue_analytics.js b/erpnext/support/report/issue_analytics/issue_analytics.js index 746eee025a57..4680321979fd 100644 --- a/erpnext/support/report/issue_analytics/issue_analytics.js +++ b/erpnext/support/report/issue_analytics/issue_analytics.js @@ -3,14 +3,14 @@ /* eslint-disable */ frappe.query_reports["Issue Analytics"] = { - "filters": [ + filters: [ { fieldname: "company", label: __("Company"), fieldtype: "Link", options: "Company", default: frappe.defaults.get_user_default("Company"), - reqd: 1 + reqd: 1, }, { fieldname: "based_on", @@ -18,125 +18,124 @@ frappe.query_reports["Issue Analytics"] = { fieldtype: "Select", options: ["Customer", "Issue Type", "Issue Priority", "Assigned To"], default: "Customer", - reqd: 1 + reqd: 1, }, { fieldname: "from_date", label: __("From Date"), fieldtype: "Date", default: frappe.defaults.get_global_default("year_start_date"), - reqd: 1 + reqd: 1, }, { - fieldname:"to_date", + fieldname: "to_date", label: __("To Date"), fieldtype: "Date", default: frappe.defaults.get_global_default("year_end_date"), - reqd: 1 + reqd: 1, }, { fieldname: "range", label: __("Range"), fieldtype: "Select", options: [ - { "value": "Weekly", "label": __("Weekly") }, - { "value": "Monthly", "label": __("Monthly") }, - { "value": "Quarterly", "label": __("Quarterly") }, - { "value": "Yearly", "label": __("Yearly") } + { value: "Weekly", label: __("Weekly") }, + { value: "Monthly", label: __("Monthly") }, + { value: "Quarterly", label: __("Quarterly") }, + { value: "Yearly", label: __("Yearly") }, ], default: "Monthly", - reqd: 1 + reqd: 1, }, { fieldname: "status", label: __("Status"), fieldtype: "Select", - options:[ + options: [ "", - {label: __('Open'), value: 'Open'}, - {label: __('Replied'), value: 'Replied'}, - {label: __('Resolved'), value: 'Resolved'}, - {label: __('Closed'), value: 'Closed'} - ] + { label: __("Open"), value: "Open" }, + { label: __("Replied"), value: "Replied" }, + { label: __("Resolved"), value: "Resolved" }, + { label: __("Closed"), value: "Closed" }, + ], }, { fieldname: "priority", label: __("Issue Priority"), fieldtype: "Link", - options: "Issue Priority" + options: "Issue Priority", }, { fieldname: "customer", label: __("Customer"), fieldtype: "Link", - options: "Customer" + options: "Customer", }, { fieldname: "project", label: __("Project"), fieldtype: "Link", - options: "Project" + options: "Project", }, { fieldname: "assigned_to", label: __("Assigned To"), fieldtype: "Link", - options: "User" - } + options: "User", + }, ], - after_datatable_render: function(datatable_obj) { - $(datatable_obj.wrapper).find(".dt-row-0").find('input[type=checkbox]').click(); + after_datatable_render: function (datatable_obj) { + $(datatable_obj.wrapper).find(".dt-row-0").find("input[type=checkbox]").click(); }, get_datatable_options(options) { return Object.assign(options, { checkboxColumn: true, events: { - onCheckRow: function(data) { + onCheckRow: function (data) { if (data && data.length) { row_name = data[2].content; - row_values = data.slice(3).map(function(column) { + row_values = data.slice(3).map(function (column) { return column.content; - }) - entry = { - 'name': row_name, - 'values': row_values - } + }); + entry = { + name: row_name, + values: row_values, + }; let raw_data = frappe.query_report.chart.data; let new_datasets = raw_data.datasets; var found = false; - for(var i=0; i < new_datasets.length; i++){ - if (new_datasets[i].name == row_name){ + for (var i = 0; i < new_datasets.length; i++) { + if (new_datasets[i].name == row_name) { found = true; - new_datasets.splice(i,1); + new_datasets.splice(i, 1); break; } } - if (!found){ + if (!found) { new_datasets.push(entry); } let new_data = { labels: raw_data.labels, - datasets: new_datasets - } + datasets: new_datasets, + }; setTimeout(() => { - frappe.query_report.chart.update(new_data) - },500) - + frappe.query_report.chart.update(new_data); + }, 500); setTimeout(() => { frappe.query_report.chart.draw(true); - }, 1000) + }, 1000); frappe.query_report.raw_chart_data = new_data; } }, - } + }, }); - } + }, }; diff --git a/erpnext/support/report/issue_summary/issue_summary.js b/erpnext/support/report/issue_summary/issue_summary.js index a5122d03ad1b..15d55ba6543b 100644 --- a/erpnext/support/report/issue_summary/issue_summary.js +++ b/erpnext/support/report/issue_summary/issue_summary.js @@ -3,14 +3,14 @@ /* eslint-disable */ frappe.query_reports["Issue Summary"] = { - "filters": [ + filters: [ { fieldname: "company", label: __("Company"), fieldtype: "Link", options: "Company", default: frappe.defaults.get_user_default("Company"), - reqd: 1 + reqd: 1, }, { fieldname: "based_on", @@ -18,58 +18,58 @@ frappe.query_reports["Issue Summary"] = { fieldtype: "Select", options: ["Customer", "Issue Type", "Issue Priority", "Assigned To"], default: "Customer", - reqd: 1 + reqd: 1, }, { fieldname: "from_date", label: __("From Date"), fieldtype: "Date", default: frappe.defaults.get_global_default("year_start_date"), - reqd: 1 + reqd: 1, }, { - fieldname:"to_date", + fieldname: "to_date", label: __("To Date"), fieldtype: "Date", default: frappe.defaults.get_global_default("year_end_date"), - reqd: 1 + reqd: 1, }, { fieldname: "status", label: __("Status"), fieldtype: "Select", - options:[ + options: [ "", - {label: __('Open'), value: 'Open'}, - {label: __('Replied'), value: 'Replied'}, - {label: __('On Hold'), value: 'On Hold'}, - {label: __('Resolved'), value: 'Resolved'}, - {label: __('Closed'), value: 'Closed'} - ] + { label: __("Open"), value: "Open" }, + { label: __("Replied"), value: "Replied" }, + { label: __("On Hold"), value: "On Hold" }, + { label: __("Resolved"), value: "Resolved" }, + { label: __("Closed"), value: "Closed" }, + ], }, { fieldname: "priority", label: __("Issue Priority"), fieldtype: "Link", - options: "Issue Priority" + options: "Issue Priority", }, { fieldname: "customer", label: __("Customer"), fieldtype: "Link", - options: "Customer" + options: "Customer", }, { fieldname: "project", label: __("Project"), fieldtype: "Link", - options: "Project" + options: "Project", }, { fieldname: "assigned_to", label: __("Assigned To"), fieldtype: "Link", - options: "User" - } - ] + options: "User", + }, + ], }; diff --git a/erpnext/support/report/support_hour_distribution/support_hour_distribution.js b/erpnext/support/report/support_hour_distribution/support_hour_distribution.js index ae30b6a5507c..8137a50d7645 100644 --- a/erpnext/support/report/support_hour_distribution/support_hour_distribution.js +++ b/erpnext/support/report/support_hour_distribution/support_hour_distribution.js @@ -3,20 +3,20 @@ /* eslint-disable */ frappe.query_reports["Support Hour Distribution"] = { - "filters": [ + filters: [ { - 'lable': __("From Date"), - 'fieldname': 'from_date', - 'fieldtype': 'Date', - 'default': frappe.datetime.nowdate(), - 'reqd': 1 + lable: __("From Date"), + fieldname: "from_date", + fieldtype: "Date", + default: frappe.datetime.nowdate(), + reqd: 1, }, { - 'lable': __("To Date"), - 'fieldname': 'to_date', - 'fieldtype': 'Date', - 'default': frappe.datetime.nowdate(), - 'reqd': 1 - } - ] -} + lable: __("To Date"), + fieldname: "to_date", + fieldtype: "Date", + default: frappe.datetime.nowdate(), + reqd: 1, + }, + ], +}; diff --git a/erpnext/support/web_form/issues/issues.js b/erpnext/support/web_form/issues/issues.js index ffc5e984253b..8f56ebb353de 100644 --- a/erpnext/support/web_form/issues/issues.js +++ b/erpnext/support/web_form/issues/issues.js @@ -1,3 +1,3 @@ -frappe.ready(function() { +frappe.ready(function () { // bind events here -}) +}); diff --git a/erpnext/telephony/doctype/call_log/call_log.js b/erpnext/telephony/doctype/call_log/call_log.js index e7afa0b7d09e..1fd152660039 100644 --- a/erpnext/telephony/doctype/call_log/call_log.js +++ b/erpnext/telephony/doctype/call_log/call_log.js @@ -1,21 +1,21 @@ // Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Call Log', { - refresh: function(frm) { +frappe.ui.form.on("Call Log", { + refresh: function (frm) { frm.events.setup_recording_audio_control(frm); - const incoming_call = frm.doc.type == 'Incoming'; - frm.add_custom_button(incoming_call ? __('Callback'): __('Call Again'), () => { + const incoming_call = frm.doc.type == "Incoming"; + frm.add_custom_button(incoming_call ? __("Callback") : __("Call Again"), () => { const number = incoming_call ? frm.doc.from : frm.doc.to; frappe.phone_call.handler(number, frm); }); }, setup_recording_audio_control(frm) { - const recording_wrapper = frm.get_field('recording_html').$wrapper; - if (!frm.doc.recording_url || frm.doc.recording_url == 'null') { + const recording_wrapper = frm.get_field("recording_html").$wrapper; + if (!frm.doc.recording_url || frm.doc.recording_url == "null") { recording_wrapper.empty(); } else { - recording_wrapper.addClass('input-max-width'); + recording_wrapper.addClass("input-max-width"); recording_wrapper.html(`