Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function allocate_budget_popup(project, sub_budget_item, fiscal_years, available_amount, labels){
- let d = new frappe.ui.Dialog({
- title: 'Team Allocation',
- size: "large",
- fields: [
- {
- label: "Fiscal Year",
- fieldname: "fiscal_year",
- fieldtype: "Select",
- options: fiscal_years,
- reqd: 1,
- onchange: function(e) {
- var primary_action_label = 'Allocate';
- var selected_fiscal_year = this.value;
- var idx = fiscal_years.indexOf(selected_fiscal_year);
- primary_action_label = labels[idx];
- d.set_value('allocated_amount', available_amount[idx]);
- d.set_primary_action(primary_action_label, (values) => {
- allocate_budget_to_teams(project, sub_budget_item, values.fiscal_year, values);
- d.hide();
- });
- frappe.db.get_value("Budget Item", sub_budget_item, 'parent_budget_item').then((result) => {
- d.set_value('budget_item', result.message.parent_budget_item)
- d.set_value('sub_budget_item', sub_budget_item)
- });
- }
- },
- {
- label: "Budget Item",
- fieldname: "budget_item",
- fieldtype: "Link",
- options: 'Budget Item',
- read_only: 1,
- depends_on: "eval: doc.fiscal_year"
- },
- {
- label: "Sub Budget Item",
- fieldname: "sub_budget_item",
- fieldtype: "Link",
- options: 'Budget Item',
- read_only: 1,
- depends_on: "eval: doc.fiscal_year"
- },
- {
- label: "Available Amount",
- fieldname: "allocated_amount",
- fieldtype: "Currency",
- read_only: 1,
- default: 0,
- depends_on: "eval: doc.fiscal_year",
- onchange: function(e) {
- var allocated_amount = this.value;
- var fiscal_year = d.get_value('fiscal_year');
- frappe.call({
- method: 'pradan.pradan.doctype.pradan_budget.pradan_budget.get_team_wise_budget',
- args: {
- project: project,
- available_amount: allocated_amount,
- sub_budget_item: sub_budget_item,
- fiscal_year: fiscal_year
- },
- freeze: true,
- freeze_message: __("Fetching team details.."),
- callback: (r) => {
- if(r.message){
- let data = r.message.team_wise_budget;
- d.fields_dict.team_wise_budget.df.read_only = r.message.is_salary_head
- d.fields_dict.team_wise_budget.df.fields[2].read_only = r.message.is_salary_head
- d.fields_dict.team_wise_budget.df.data = data
- let available_amount = parseFloat(d.get_value('allocated_amount')) || 0;
- let allocated_amount = 0;
- data.forEach(row => {
- allocated_amount += row.allocated_amount;
- });
- let balance_amount = available_amount - allocated_amount;
- d.set_value('balance_amount', balance_amount);
- d.fields_dict.team_wise_budget.grid.refresh();
- }
- else {
- frappe.throw('No team has allocated to this Project')
- }
- }
- });
- }
- },
- {
- label: "Team wise Budget",
- fieldname: "team_wise_budget",
- fieldtype: "Table",
- reqd: 1,
- cannot_add_rows: true,
- cannot_delete_rows: true,
- cannot_delete_all_rows: true,
- in_place_edit: true,
- depends_on: "eval: doc.fiscal_year",
- fields: [
- {
- fieldtype: 'Link',
- label: 'Project',
- fieldname: 'project',
- options: 'Project',
- in_list_view: 1,
- reqd: 1,
- read_only: 1
- },
- {
- fieldtype: 'Link',
- label: 'Teams',
- fieldname: 'teams',
- options: 'Branch',
- in_list_view: 1,
- reqd: 1,
- read_only: 1
- },
- {
- fieldtype: 'Currency',
- label: 'Allocated Amount',
- fieldname: 'allocated_amount',
- in_list_view: 1,
- reqd: 1,
- default: 0,
- onchange: function(e) {
- var available_amount = parseFloat(d.get_value('allocated_amount')) || 0;
- var table_data = d.get_value('team_wise_budget');
- var allocated_amount = 0;
- table_data.forEach(row => {
- allocated_amount += row.allocated_amount;
- });
- var balance_amount = available_amount - allocated_amount;
- d.set_value('balance_amount', balance_amount);
- // if(available_amount<allocated_amount){
- // frappe.throw('Total allocation should not exceed than the available amount!');
- // }
- }
- },
- {
- fieldtype: 'Data',
- label: 'Remarks',
- fieldname: 'remarks',
- in_list_view: 1
- },
- ]
- },
- {
- label: "Balance Amount",
- fieldname: "balance_amount",
- fieldtype: "Currency",
- default: 0,
- read_only: 1
- }
- ]
- });
- d.show();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement