Skip to content

Commit

Permalink
fix: change importdialog in purchase reconciliation tool
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanket322 committed May 17, 2024
1 parent 9c3341c commit 6d6c819
Show file tree
Hide file tree
Showing 3 changed files with 311 additions and 104 deletions.
Original file line number Diff line number Diff line change
@@ -1,37 +1,31 @@
{% if(Object.keys(data).length != 0) { %}
<div class="download_data">
<table class="table table-bordered table-hover">
<thead>
<tr>
{% for(let i=0; i<columns.length; i++) { %} <th class="text-left">{{ columns[i] }}
</th>
<table class="table table-bordered table-hover">
<thead>
<tr>
{% for(let i=0; i<columns.length; i++) { %} <th class="text-left">{{ columns[i] }}
</th>
{% } %}
</tr>
</thead>
<tbody>

{% for(let period in data) { %}
<!-- for first class -->
<tr>
<td rowspan="{{ data[period].length }}" style="width:50%">{{period}}</td>
<td>{{ data[period][0] }}</td>
</tr>

{% for(let i=1;i < data[period].length;i++){ %}
<tr>
<td>{{ data[period][i] }}</td>
</tr>
{% } %}
</tr>
</thead>
<tbody>
{% let previous_period = ''; %}
{% for(let period in data) { %}
<!-- for first class -->
<tr>
{% if(period != previous_period) { %}
<td rowspan="{{data[period].length}}">{{period}}</td>
{% previous_period = period; %}
{% } %}
{% for(let value of Object.values(data[period].shift())) { %}
<td>{{ value }}</td>
{% } %}
</tr>

<!-- for more than one class -->
{% if(data[period].length > 0) { %}
{% for(let category of data[period]) { %}
<tr>
{% for(let value of Object.values(category)) { %}
<td>{{ value }}</td>
{% } %}
</tr>
{% } %}
{% } %}
{% } %}
</tbody>
</table>
</div>

</tbody>
</table>
</div>
{% } %}
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,12 @@ class ImportDialog {
_init_download_dialog() {
this.dialog = new frappe.ui.Dialog({
title: __("Download Data from GSTN"),
fields: [...this.get_gstr_fields(), ...this.get_history_fields()],
fields: [
...this.get_gstr_fields(),
...this.get_gstr2a_checkbox(),
...this.get_pending_fields(),
...this.get_history_fields(),
],
});
}

Expand Down Expand Up @@ -1173,18 +1178,44 @@ class ImportDialog {
if (this.return_type === ReturnType.GSTR2A) {
this.dialog.$wrapper.find(".btn-secondary").removeClass("hidden");
this.dialog.set_primary_action(__("Download All"), () => {
download_gstr(this.frm, this.date_range, this.return_type, this.company_gstin, false);
let gst_categories = this.get_marked_gst_category();

download_gstr(
this.frm,
this.date_range,
this.return_type,
this.company_gstin,
false,
null,
gst_categories
);
this.dialog.hide();
});
this.dialog.set_secondary_action_label(__("Download Missing"));
this.dialog.set_secondary_action(() => {
download_gstr(this.frm, this.date_range, this.return_type, this.company_gstin, true);
let gst_categories = this.get_marked_gst_category();

download_gstr(
this.frm,
this.date_range,
this.return_type,
this.company_gstin,
true,
null,
gst_categories
);
this.dialog.hide();
});
} else if (this.return_type === ReturnType.GSTR2B) {
this.dialog.$wrapper.find(".btn-secondary").addClass("hidden");
this.dialog.set_primary_action(__("Download"), () => {
download_gstr(this.frm, this.date_range, this.return_type, this.company_gstin, true);
download_gstr(
this.frm,
this.date_range,
this.return_type,
this.company_gstin,
true
);
this.dialog.hide();
});
}
Expand All @@ -1205,6 +1236,26 @@ class ImportDialog {
}
}

get_marked_gst_category() {
let gstcategory = [
"B2B",
"B2BA",
"CDNR",
"CDNRA",
"ISD",
"ISDA",
"IMPG",
"IMPGSEZ",
];
let gst_categories = [];
for (let i = 0; i < gstcategory.length; i++) {
if (this.dialog.fields_dict[gstcategory[i]].value == 1) {
gst_categories.push(gstcategory[i]);
}
}
return gst_categories;
}

async fetch_import_history() {
const { message } = await this.frm.call("get_import_history", {
company_gstin: this.company_gstin,
Expand All @@ -1213,8 +1264,55 @@ class ImportDialog {
for_download: this.for_download,
});

// TODO: modify HTML for case: company_gstin == "All"
let html = (!message || this.company_gstin == "All") ? '' : frappe.render_template("gstr_download_history", message)
let pending_download_data = {};
let download_history_data = {};

for (let gst_no in message.data) {
let periods = message.data[gst_no];

for (let period in periods) {
let array = periods[period];

for (let obj of array) {
if (obj["Status"] === "🟠 &nbsp; Not Downloaded") {
if (!pending_download_data[period]) {
pending_download_data[period] = [];
}
pending_download_data[period].push(gst_no);
}
if (
(obj["Status"] === "🟢 &nbsp; Downloaded") &
(this.company_gstin != "All")
) {
if (!download_history_data[period]) {
download_history_data[period] = [];
}
download_history_data[period].push(obj["Downloaded On"]);
}
}
}
}

let pending_download = {
label: "Pending Download",
columns: ["Period", "GSTIN"],
data: pending_download_data,
};
let download_history = {
label: this.for_download ? "Download History" : "Upload History",
columns: ["Period", "Downloded On"],
data: download_history_data,
};

this.dialog.fields_dict.pending_download.html(
frappe.render_template("gstr_download_history", pending_download)
);

let html =
this.company_gstin === "All" ||
Object.keys(download_history_data).length === 0
? ""
: frappe.render_template("gstr_download_history", download_history);
this.dialog.fields_dict.history.html(html);
}

Expand Down Expand Up @@ -1260,9 +1358,9 @@ class ImportDialog {
{ label: "GSTR 2B", value: ReturnType.GSTR2B },
],
onchange: () => {
this.return_type = this.dialog.get_value("return_type");
this.fetch_import_history();
this.setup_dialog_actions();
this.return_type = this.dialog.get_value("return_type");
},
},
{
Expand All @@ -1282,7 +1380,7 @@ class ImportDialog {
onchange: () => {
this.company_gstin = this.dialog.get_value("company_gstin");
this.fetch_import_history();
}
},
},
{
fieldtype: "Column Break",
Expand Down Expand Up @@ -1315,18 +1413,104 @@ class ImportDialog {
this.date_range = this.dialog.get_value("date_range");
this.fetch_import_history();
},
},
}
];
}

get_pending_fields() {
const label = "Pending Download";
return [
{ label, fieldtype: "Section Break" },
{ label, fieldname: "pending_download", fieldtype: "HTML" },
];
}

get_history_fields() {
const label = this.for_download ? "Download History" : "Upload History";

return [
{ label, fieldtype: "Section Break" },
{
label,
fieldtype: "Section Break",
depends_on: "eval:doc.company_gstin != 'All'",
},
{ label, fieldname: "history", fieldtype: "HTML" },
];
}

get_gstr2a_checkbox() {
return [
{
label: "",
fieldtype: "Section Break",
depends_on: "eval:doc.return_type == 'GSTR2a'",
},
{
label: "B2B",
fieldname: "B2B",
fieldtype: "Check",
depends_on: "eval:doc.return_type == 'GSTR2a'",
},
{
label: "B2BA",
fieldname: "B2BA",
fieldtype: "Check",
depends_on: "eval:doc.return_type == 'GSTR2a'",
},
{
label: "",
fieldtype: "Column Break",
depends_on: "eval:doc.return_type == 'GSTR2a'",
},
{
label: "CDNR",
fieldname: "CDNR",
fieldtype: "Check",
depends_on: "eval:doc.return_type == 'GSTR2a'",
},
{
label: "CDNRA",
fieldname: "CDNRA",
fieldtype: "Check",
depends_on: "eval:doc.return_type == 'GSTR2a'",
},
{
label: "",
fieldtype: "Column Break",
depends_on: "eval:doc.return_type == 'GSTR2a'",
},
{
label: "ISD",
fieldname: "ISD",
fieldtype: "Check",
depends_on: "eval:doc.return_type == 'GSTR2a'",
},
{
label: "ISDA",
fieldname: "ISDA",
fieldtype: "Check",
depends_on: "eval:doc.return_type == 'GSTR2a'",
},
{
label: "",
fieldtype: "Column Break",
depends_on: "eval:doc.return_type == 'GSTR2a'",
},
{
label: "IMPG",
fieldname: "IMPG",
fieldtype: "Check",
depends_on: "eval:doc.return_type == 'GSTR2a'",
},
{
label: "IMPGSEZ",
fieldname: "IMPGSEZ",
fieldtype: "Check",
depends_on: "eval:doc.return_type == 'GSTR2a'",
},
{ label: "", fieldtype: "Section Break" },
];
}
}

async function download_gstr(
Expand All @@ -1335,8 +1519,14 @@ async function download_gstr(
return_type,
company_gstin,
only_missing = true,
otp = null
otp = null,
gst_categories = null
) {
//if no category is selected then show error message
if (gst_categories === null || gst_categories.length === 0) {
frappe.throw("Please select at least one Category to Download");
}

const authenticated_company_gstins =
await india_compliance.authenticate_company_gstins(
frm.doc.company,
Expand All @@ -1349,6 +1539,7 @@ async function download_gstr(
date_range: date_range,
force: !only_missing,
otp,
gst_categories,
};
frm.events.show_progress(frm, "download");
await frm.call("download_gstr", args);
Expand Down
Loading

0 comments on commit 6d6c819

Please sign in to comment.