refator: Rename files and move code
diff --git a/erpnext/crm/call_summary/call_summary_utils.py b/erpnext/crm/call_summary/call_summary_utils.py
deleted file mode 100644
index 49491d5..0000000
--- a/erpnext/crm/call_summary/call_summary_utils.py
+++ /dev/null
@@ -1,18 +0,0 @@
-import frappe
-
-@frappe.whitelist()
-def get_contact_doc(phone_number):
-	phone_number = phone_number[-10:]
-	contacts = frappe.get_all('Contact', or_filters={
-		'phone': ['like', '%{}'.format(phone_number)],
-		'mobile_no': ['like', '%{}'.format(phone_number)]
-	}, fields=['name'])
-
-	if contacts:
-		return frappe.get_doc(contacts[0].name)
-
-@frappe.whitelist()
-def get_last_communication(phone_number, customer=None):
-	# find last communication through phone_number
-	# find last issues, opportunity, lead
-	pass
\ No newline at end of file
diff --git a/erpnext/crm/call_summary/exotel_call_handler.py b/erpnext/crm/call_summary/exotel_call_handler.py
deleted file mode 100644
index a0c3b7d..0000000
--- a/erpnext/crm/call_summary/exotel_call_handler.py
+++ /dev/null
@@ -1,43 +0,0 @@
-import frappe
-
-@frappe.whitelist(allow_guest=True)
-def handle_request(*args, **kwargs):
-	# r = frappe.request
-
-	# print(r.args.to_dict(), args, kwargs)
-
-	incoming_phone_number = kwargs.get('CallFrom')
-	contact = get_contact_doc(incoming_phone_number)
-	last_communication = get_last_communication(incoming_phone_number, contact)
-
-	data = {
-		'contact': contact,
-		'call_payload': kwargs,
-		'last_communication': last_communication
-	}
-
-	frappe.publish_realtime('incoming_call', data)
-
-
-def get_contact_doc(phone_number):
-	phone_number = phone_number[-10:]
-	number_filter = {
-		'phone': ['like', '%{}'.format(phone_number)],
-		'mobile_no': ['like', '%{}'.format(phone_number)]
-	}
-	contacts = frappe.get_all('Contact', or_filters=number_filter,
-		fields=['name'], limit=1)
-
-	if contacts:
-		return frappe.get_doc('Contact', contacts[0].name)
-
-	leads = frappe.get_all('Leads', or_filters=number_filter,
-		fields=['name'], limit=1)
-
-	if leads:
-		return frappe.get_doc('Lead', leads[0].name)
-
-
-def get_last_communication(phone_number, contact):
-	# frappe.get_all('Communication', filter={})
-	return {}
diff --git a/erpnext/crm/doctype/utils.py b/erpnext/crm/doctype/utils.py
new file mode 100644
index 0000000..3bd9246
--- /dev/null
+++ b/erpnext/crm/doctype/utils.py
@@ -0,0 +1,20 @@
+import frappe
+
+def get_document_with_phone_number(number):
+	# finds contacts and leads
+	number = number[-10:]
+	number_filter = {
+		'phone': ['like', '%{}'.format(number)],
+		'mobile_no': ['like', '%{}'.format(number)]
+	}
+	contacts = frappe.get_all('Contact', or_filters=number_filter,
+		fields=['name'], limit=1)
+
+	if contacts:
+		return frappe.get_doc('Contact', contacts[0].name)
+
+	leads = frappe.get_all('Leads', or_filters=number_filter,
+		fields=['name'], limit=1)
+
+	if leads:
+		return frappe.get_doc('Lead', leads[0].name)
\ No newline at end of file
diff --git a/erpnext/erpnext_integrations/exotel_integration.py b/erpnext/erpnext_integrations/exotel_integration.py
new file mode 100644
index 0000000..f8b605a
--- /dev/null
+++ b/erpnext/erpnext_integrations/exotel_integration.py
@@ -0,0 +1,41 @@
+import frappe
+from erpnext.crm.doctype.utils import get_document_with_phone_number
+
+@frappe.whitelist(allow_guest=True)
+def handle_incoming_call(*args, **kwargs):
+	incoming_phone_number = kwargs.get('CallFrom')
+
+	contact = get_document_with_phone_number(incoming_phone_number)
+	last_communication = get_last_communication(incoming_phone_number, contact)
+	call_log = create_call_log(kwargs)
+	data = {
+		'contact': contact,
+		'call_payload': kwargs,
+		'last_communication': last_communication,
+		'call_log': call_log
+	}
+
+	frappe.publish_realtime('incoming_call', data)
+
+
+def get_last_communication(phone_number, contact):
+	# frappe.get_all('Communication', filter={})
+	return {}
+
+def create_call_log(call_payload):
+	communication = frappe.new_doc('Communication')
+	communication.subject = frappe._('Call from {}').format(call_payload.get("CallFrom"))
+	communication.communication_medium = 'Phone'
+	communication.send_email = 0
+	communication.phone_no = call_payload.get("CallFrom")
+	communication.comment_type = 'Info'
+	communication.communication_type = 'Communication'
+	communication.status = 'Open'
+	communication.sent_or_received = 'Received'
+	communication.content = 'call_payload'
+	communication.communication_date = call_payload.get('StartTime')
+	# communication.sid = call_payload.get('CallSid')
+	# communication.exophone = call_payload.get('CallTo')
+	# communication.call_receiver = call_payload.get('DialWhomNumber')
+	communication.save(ignore_permissions=True)
+	return communication
diff --git a/erpnext/public/js/call_popup/call_summary_dialog.js b/erpnext/public/js/call_popup/call_popup.js
similarity index 75%
rename from erpnext/public/js/call_popup/call_summary_dialog.js
rename to erpnext/public/js/call_popup/call_popup.js
index e9823ee..99c2ca3 100644
--- a/erpnext/public/js/call_popup/call_summary_dialog.js
+++ b/erpnext/public/js/call_popup/call_popup.js
@@ -1,4 +1,4 @@
-class CallSummaryDialog {
+class CallPopup {
 	constructor({ contact, call_payload, last_communication }) {
 		this.number = call_payload.CallFrom;
 		this.contact = contact;
@@ -8,7 +8,6 @@
 
 	make() {
 		this.dialog = new frappe.ui.Dialog({
-			'title': __(`Incoming call from ${this.contact ? this.contact.name : 'Unknown Number'}`),
 			'static': true,
 			'minimizable': true,
 			'fields': [{
@@ -27,40 +26,21 @@
 				'fieldtype': 'Small Text',
 				'label': 'Call Summary',
 				'fieldname': 'call_communication',
-				'default': 'This is not working please helpppp',
-				"placeholder": __("Select or add new customer")
 			}, {
 				'fieldtype': 'Button',
 				'label': 'Submit',
 				'click': () => {
-					frappe.xcall()
+					this.dialog.get_value();
 				}
 			}]
 		});
+		this.set_call_status();
 		this.make_customer_contact();
 		this.dialog.show();
 		this.dialog.get_close_btn().show();
 		this.dialog.header.find('.indicator').removeClass('hidden').addClass('blue');
 	}
 
-	get_dialog_skeleton() {
-		return `
-			<div class="call-summary-body">
-				<div class="customer-info flex">
-				</div>
-				<div class="flex">
-					<div class="last-communication"></div>
-					<div class="call-summary"></div>
-				</div>
-				<hr>
-				<div class="flex">
-					<div class="section-right"></div>
-					<div class="section-left"></div>
-				</div>
-			</div>
-		`;
-	}
-
 	make_customer_contact() {
 		const wrapper = this.dialog.fields_dict["customer_info"].$wrapper;
 		const contact = this.contact;
@@ -100,10 +80,30 @@
 	make_summary_section() {
 		//
 	}
+
+	set_call_status(status) {
+		let title = '';
+		if (status === 'incoming') {
+			if (this.contact) {
+				title = __('Incoming call from {0}', [this.contact.name]);
+			} else {
+				title = __('Incoming call from unknown number');
+			}
+		}
+		this.dialog.set_title(title);
+	}
+
+	update(data) {
+		// pass
+	}
 }
 
 $(document).on('app_ready', function () {
-	frappe.realtime.on('incoming_call', data => {
-		frappe.call_summary_dialog = new CallSummaryDialog(data);
+	frappe.realtime.on('call_update', data => {
+		if (!erpnext.call_popup) {
+			erpnext.call_popup = new CallPopup(data);
+		} else {
+			erpnext.call_popup.update(data);
+		}
 	});
 });