-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
maniamartial
committed
May 19, 2024
1 parent
e7d8160
commit a3c15ed
Showing
30 changed files
with
1,026 additions
and
1 deletion.
There are no files selected for viewing
File renamed without changes.
Empty file.
Empty file.
8 changes: 8 additions & 0 deletions
8
nl_piece_rate_pay/casual_piece_rate/doctype/casual_activity_item/casual_activity_item.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Copyright (c) 2024, Navari Limited and contributors | ||
// For license information, please see license.txt | ||
|
||
frappe.ui.form.on('Casual Activity Item', { | ||
// refresh: function(frm) { | ||
|
||
// } | ||
}); |
103 changes: 103 additions & 0 deletions
103
nl_piece_rate_pay/casual_piece_rate/doctype/casual_activity_item/casual_activity_item.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
{ | ||
"actions": [], | ||
"allow_import": 1, | ||
"allow_rename": 1, | ||
"autoname": "format:PROJ-{MM}-{####}", | ||
"creation": "2024-04-17 15:40:31.404174", | ||
"default_view": "List", | ||
"doctype": "DocType", | ||
"document_type": "Setup", | ||
"engine": "InnoDB", | ||
"field_order": [ | ||
"activity_type", | ||
"column_break_2", | ||
"item", | ||
"column_break_hm4ee", | ||
"costing_rate", | ||
"section_break_4", | ||
"billing_rate", | ||
"column_break_6", | ||
"title" | ||
], | ||
"fields": [ | ||
{ | ||
"fieldname": "activity_type", | ||
"fieldtype": "Link", | ||
"in_list_view": 1, | ||
"in_standard_filter": 1, | ||
"label": "Activity Type", | ||
"options": "Activity Type", | ||
"reqd": 1 | ||
}, | ||
{ | ||
"fieldname": "column_break_2", | ||
"fieldtype": "Column Break" | ||
}, | ||
{ | ||
"fieldname": "item", | ||
"fieldtype": "Link", | ||
"label": "Item", | ||
"options": "Item" | ||
}, | ||
{ | ||
"fieldname": "section_break_4", | ||
"fieldtype": "Section Break" | ||
}, | ||
{ | ||
"default": "0", | ||
"description": "per hour", | ||
"fieldname": "billing_rate", | ||
"fieldtype": "Currency", | ||
"hidden": 1, | ||
"label": "Billing Rate" | ||
}, | ||
{ | ||
"fieldname": "column_break_6", | ||
"fieldtype": "Column Break" | ||
}, | ||
{ | ||
"default": "0", | ||
"description": "per item", | ||
"fieldname": "costing_rate", | ||
"fieldtype": "Currency", | ||
"label": "Costing Rate" | ||
}, | ||
{ | ||
"fieldname": "title", | ||
"fieldtype": "Data", | ||
"hidden": 1, | ||
"label": "title", | ||
"no_copy": 1, | ||
"read_only": 1 | ||
}, | ||
{ | ||
"fieldname": "column_break_hm4ee", | ||
"fieldtype": "Column Break" | ||
} | ||
], | ||
"links": [], | ||
"modified": "2024-05-19 21:40:03.831886", | ||
"modified_by": "Administrator", | ||
"module": "Casual Piece Rate", | ||
"name": "Casual Activity Item", | ||
"naming_rule": "Expression", | ||
"owner": "Administrator", | ||
"permissions": [ | ||
{ | ||
"create": 1, | ||
"delete": 1, | ||
"email": 1, | ||
"export": 1, | ||
"print": 1, | ||
"read": 1, | ||
"report": 1, | ||
"role": "Projects User", | ||
"share": 1, | ||
"write": 1 | ||
} | ||
], | ||
"sort_field": "modified", | ||
"sort_order": "DESC", | ||
"states": [], | ||
"title_field": "title" | ||
} |
8 changes: 8 additions & 0 deletions
8
nl_piece_rate_pay/casual_piece_rate/doctype/casual_activity_item/casual_activity_item.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Copyright (c) 2024, Navari Limited and contributors | ||
# For license information, please see license.txt | ||
|
||
# import frappe | ||
from frappe.model.document import Document | ||
|
||
class CasualActivityItem(Document): | ||
pass |
9 changes: 9 additions & 0 deletions
9
...iece_rate_pay/casual_piece_rate/doctype/casual_activity_item/test_casual_activity_item.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Copyright (c) 2024, Navari Limited and Contributors | ||
# See license.txt | ||
|
||
# import frappe | ||
from frappe.tests.utils import FrappeTestCase | ||
|
||
|
||
class TestCasualActivityItem(FrappeTestCase): | ||
pass |
Empty file.
47 changes: 47 additions & 0 deletions
47
nl_piece_rate_pay/casual_piece_rate/doctype/casual_payment_record/casual_payment_record.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"actions": [], | ||
"allow_rename": 1, | ||
"creation": "2024-04-23 09:20:26.480486", | ||
"doctype": "DocType", | ||
"editable_grid": 1, | ||
"engine": "InnoDB", | ||
"field_order": [ | ||
"employee", | ||
"employee_name", | ||
"amount" | ||
], | ||
"fields": [ | ||
{ | ||
"fieldname": "employee", | ||
"fieldtype": "Link", | ||
"in_list_view": 1, | ||
"label": "Employee", | ||
"options": "Employee" | ||
}, | ||
{ | ||
"fieldname": "amount", | ||
"fieldtype": "Currency", | ||
"in_list_view": 1, | ||
"label": "Basic Salary" | ||
}, | ||
{ | ||
"fetch_from": "employee.employee_name", | ||
"fieldname": "employee_name", | ||
"fieldtype": "Data", | ||
"in_list_view": 1, | ||
"label": "Employee Name" | ||
} | ||
], | ||
"index_web_pages_for_search": 1, | ||
"istable": 1, | ||
"links": [], | ||
"modified": "2024-04-28 08:27:43.330454", | ||
"modified_by": "Administrator", | ||
"module": "CSF KE", | ||
"name": "Casual Payment Record", | ||
"owner": "Administrator", | ||
"permissions": [], | ||
"sort_field": "modified", | ||
"sort_order": "DESC", | ||
"states": [] | ||
} |
8 changes: 8 additions & 0 deletions
8
nl_piece_rate_pay/casual_piece_rate/doctype/casual_payment_record/casual_payment_record.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Copyright (c) 2024, Navari Limited and contributors | ||
# For license information, please see license.txt | ||
|
||
# import frappe | ||
from frappe.model.document import Document | ||
|
||
class CasualPaymentRecord(Document): | ||
pass |
Empty file.
148 changes: 148 additions & 0 deletions
148
nl_piece_rate_pay/casual_piece_rate/doctype/casual_payroll_payout/casual_payroll_payout.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
// Copyright (c) 2024, Navari Limited and contributors | ||
// For license information, please see license.txt | ||
|
||
frappe.ui.form.on('Casual Payroll Payout', { | ||
refresh: function(frm) { | ||
if(frm.doc.attendance_date!=null){ | ||
frm.add_custom_button(__('Get Employees'), function() { | ||
// Handle button click event | ||
var attendanceDate = frm.doc.attendance_date; | ||
var shiftType = frm.doc.shift_type; | ||
var company = frm.doc.company; | ||
fetchEmployees(frm, attendanceDate, shiftType, company); | ||
}), | ||
frm.add_custom_button(__('Calculate Payout'), function() { | ||
calculatePayout(frm); | ||
} | ||
) | ||
} | ||
|
||
}, | ||
|
||
attendance_date: function(frm) { | ||
frm.add_custom_button(__('Get Employees'), function() { | ||
var attendanceDate = frm.doc.attendance_date; | ||
var shiftType = frm.doc.shift_type; | ||
var company = frm.doc.company; | ||
fetchEmployees(frm, attendanceDate, shiftType, company); | ||
}), | ||
frm.add_custom_button(__('Calculate Payout'), function() { | ||
calculatePayout(frm); | ||
} | ||
) | ||
|
||
} | ||
|
||
}); | ||
|
||
// Define a function to handle rate, amount, and totals calculation | ||
function updateItemDetails(frm, cdt, cdn, child) { | ||
var total_quantity = 0; | ||
var total_amount = 0; | ||
|
||
frappe.call({ | ||
method: 'nl_piece_rate_pay.casual_piece_rate.doctype.casual_payroll_payout.casual_payroll_payout.get_rate', | ||
args: { | ||
activity: child.activity_type, | ||
item: child.item, | ||
}, | ||
callback: function(response) { | ||
if (response && response.message) { | ||
var rate = response.message; | ||
var amount = rate * (child.quantity || 1); // Use child.quantity or default to 1 if undefined | ||
|
||
frappe.model.set_value(cdt, cdn, 'rate', rate); | ||
frappe.model.set_value(cdt, cdn, 'amount', amount); | ||
|
||
frm.refresh_field('casual_payroll_payout_item'); | ||
|
||
frm.doc.casual_payrol_payout_item.forEach(function(row) { | ||
total_quantity += row.quantity || 0; | ||
total_amount += row.amount || 0; | ||
}); | ||
|
||
frm.set_value('total_quantity', total_quantity); | ||
frm.set_value('total_amount', total_amount); | ||
frm.refresh_field('total_quantity'); | ||
frm.refresh_field('total_amount'); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
// Attach event handlers using a single function for both 'item' and 'quantity' events | ||
frappe.ui.form.on('Casual Payroll Payout Item', { | ||
item: function(frm, cdt, cdn) { | ||
var child = locals[cdt][cdn]; | ||
// Set child.quantity to 1 if it's null or undefined | ||
frappe.model.set_value(cdt, cdn, 'quantity', 1.00); | ||
child.quantity = child.quantity || 1; | ||
updateItemDetails(frm, cdt, cdn, child); | ||
}, | ||
|
||
quantity: function(frm, cdt, cdn) { | ||
var child = locals[cdt][cdn]; | ||
updateItemDetails(frm, cdt, cdn, child); | ||
}, | ||
|
||
|
||
}); | ||
|
||
// Function to fetch employees based on predefined filters | ||
function fetchEmployees(frm, attendanceDate, shiftType, company) { | ||
frappe.call({ | ||
method: 'nl_piece_rate_pay.casual_piece_rate.doctype.casual_payroll_payout.casual_payroll_payout.fetch_employees', | ||
args: { | ||
"attendance_date": attendanceDate, | ||
"shift_type": shiftType, | ||
"company": company, | ||
"total_amount": frm.doc.total_amount, | ||
"salary_structure": frm.doc.salary_structure, | ||
|
||
}, | ||
|
||
callback: function(response) { | ||
if (response && response.message) { | ||
var employees = response.message; | ||
frappe.model.clear_table(frm.doc, 'casual_payrol_payout_employee'); | ||
|
||
response.message.forEach(function(casual) { | ||
var new_casual_payrol_payout_employee = frm.add_child('casual_payrol_payout_employee'); | ||
|
||
|
||
new_casual_payrol_payout_employee.employee = casual.employee; | ||
new_casual_payrol_payout_employee.employee_name = casual.employee_name; | ||
new_casual_payrol_payout_employee.shift_type = casual.shift_type; | ||
new_casual_payrol_payout_employee.attendance = casual.attendance; | ||
|
||
new_casual_payrol_payout_employee.amount = casual.amount; | ||
new_casual_payrol_payout_employee.checkin=casual.checkin; | ||
new_casual_payrol_payout_employee.checkout=casual.checkout; | ||
|
||
}); | ||
|
||
frm.refresh(); | ||
|
||
} | ||
} | ||
}); | ||
} | ||
|
||
// Function to calculate payout based on total amount and number of employees | ||
function calculatePayout(frm) { | ||
var totalAmount = frm.doc.total_amount || 0; | ||
var numberOfEmployees = frm.doc.casual_payrol_payout_employee.length; | ||
|
||
if (numberOfEmployees > 0) { | ||
var payoutPerEmployee = totalAmount / numberOfEmployees; | ||
|
||
frm.doc.casual_payrol_payout_employee.forEach(function(employee) { | ||
frappe.model.set_value(employee.doctype, employee.name, 'amount', payoutPerEmployee); | ||
}); | ||
|
||
frm.refresh_field('casual_payrol_payout_employee'); | ||
|
||
} else { | ||
frappe.msgprint("No employees found. Unable to calculate payout."); | ||
} | ||
} |
Oops, something went wrong.