Thursday, 20 August 2015

Comparing date in frappe or js

I want to check given date1 is Today or not
I used 
var date2 =get_today();
var result = (date1 == date2); 
It works successfully.


After that, I want to check, given date1 is Today or Yesterday or The day before yesterday. I used <= operator, but its not working properly.
After searching I come up with this solution, before comparing date we need to parse it.
Solution is:

var a = Date.parse(dataContext.ETD);
var b =  Date.parse(get_today());
var d = (a - b)/(1000 * 3600 * 24);
var c = ((d==0)||(d==(-1))||(d==(-2))); //returns true if ETD is today, yesterday or the day before yesterday
 
Please write comment if you have any doubt or suggestion. 

Ability to Color cells based on cell value Reports

Here is my code,
You can put this code in js file of report.
Code:


"formatter":function (row, cell, value, columnDef, dataContext, default_formatter) {
                    value = default_formatter(row, cell, value, columnDef, dataContext);
            if (columnDef.id == "Debit") {
                                   if(dataContext.Debit>1){
                                    value = "<span style='color:blue;font-weight:bold'>" + value + "</span>";
                                    }
                        msgprint(dataContext.Debit)

            }


            if (dataContext.Debit) {
            }

            return value;
        }
 
 
 

Wednesday, 12 August 2015

fetch address using frappe.call

frappe.ui.form.on("Documents Required", "buyer", function(frm, cdt, cdn) {
    var d = frappe.get_doc(cdt, cdn);
    msgprint("hi from ui");
        if(d.buyer) {
        return frm.call({
            method: "erpnext.utilities.doctype.address.address.get_address_display",
            child: d,
            args: {
                "address_dict":  d.buyer
            },
                        callback: function(r) {
            if(r.message)
                                    msgprint("hi from callback"+r.message);
                                frappe.model.set_value(cdt, cdn, "buyer_address", r.message);
        }
        });
     }
})

Script to filter address in child table and document

# Script to filter records in child table

cur_frm.set_query("buyer", "documents_required", function(doc) {
            if(doc.customer) return {filters: { 'address_type': 'Buyer', customer: doc.customer } };
        });


#script to filter records in document

cur_frm.set_query('buyer', function (doc) {
    if(doc.customer){
        return {
            filters: {
                'address_type': 'Buyer',
                'customer' : doc.customer
            }
        }
    }
    else {
        return {
        filters: {
                'address_type': 'Empty',
            }
        }
    }
});