void Books.Updated_Create_Journal_entry(Transactions ids)
{
transaction_det = Transactions[ID == input.ids];
info "ids " + ids;
idslist = List:int();
vendordet = Partner_Onboarding_and_KYC[Partner_Entity_Name == transaction_det.Partner_Entity_Name];
branchdet = Branches[Contracting_organisation == transaction_det.Contracting_organisation.Contracting_organisation];
accum_amt = 0;
total_fee = 0;
programfee = 0;
eligblefee = 0;
registrationfee = 0;
loanfee = 0;
examfee = 0;
cnt = 0;
ids.Invoice_status="Close";
// idslist.add(rec.ID);
for each rec in transaction_det
{
idslist.add(rec.ID);
examfee = ifnull(examfee,0) + rec.Exam_fee;
loanfee = ifnull(loanfee,0) + rec.Loan_subvention_charges;
registrationfee = ifnull(registrationfee,0) + rec.Total_receipt_amount;
eligblefee = ifnull(eligblefee,0) + rec.Eligible_fee;
programfee = ifnull(programfee,0) + rec.Program_fee;
total_fee = ifnull(total_fee,0) + rec.Total_Fee;
accum_amt = ifnull(accum_amt,0) + rec.Accumulated_Commission_Amount;
cnt = cnt + 1;
}
if(accum_amt > 0)
{
info accum_amt;
getID = Internal_Invoice[ID != null] sort by Added_Time desc range from 1 to 1;
if(getID.count() == 0)
{
auto = "Int_Inv_ID-001";
}
else
{
var1 = getID.Internal_Invoice_ID.getsuffix("Int_Inv_ID-");
if(var1.isEmpty() || !var1.isNumber())
{
var2 = 1;
}
else
{
var2 = var1.tolong() + 1;
}
autoList = var2.toString().length();
InvoiceList = {1:"Int_Inv_ID-00",2:"Int_Inv_ID-0",3:"Int_Inv_ID-"};
auto = InvoiceList.get(autoList) + var2;
}
new_record = insert into Internal_Invoice
[
Added_User=zoho.loginuser
Internal_Invoice_ID=auto
Tranasaction_ID=transaction_det.Transaction
Accumulated_Commission_Amount=accum_amt
CP_Name=transaction_det.Partner_Entity_Name
Program_fee=programfee
Exam_fee=examfee
Registration_fee=registrationfee
Total_Amount=total_fee
Eligible_fee=eligblefee
Loan_subvention_charges=loanfee
Payout=transaction_det.Payout
Application_No=transaction_det.Application_No1
Enrollment_Date=transaction_det.Enrollment_Date
Status="New"
Contracting_Organisation=transaction_det.Contracting_organisation
Balance_Amount_Backend=accum_amt
Transactions_list=idslist
];
// for each reclis in idslist
// {
// intinvdata = Internal_Invoice[ID == new_record];
// intinvdata.Transactions_list=reclis.toLong();
// }
// Transactions_list=idslist
// info "ids list " + idslist;
// Contracting_Organisation=transaction_det.Contracting_organisation
item_list = List();
hard_lst = {1,2};
for each split in hard_lst
{
if(split == 1)
{
get_creator_amount = accum_amt;
get_credit_debit = "credit";
// get_creator_Description = Comments;
item_map = Map();
item_map.put("amount",get_creator_amount);
item_map.put("debit_or_credit",get_credit_debit);
item_map.put("account_id",2293182000000114065);
item_map.put("customer_id",vendordet.Zoho_Book_vendor_ID);
}
if(split == 2)
{
get_creator_amount = accum_amt;
get_credit_debit = "debit";
// get_creator_Description = Comments;
item_map = Map();
item_map.put("amount",get_creator_amount);
item_map.put("debit_or_credit",get_credit_debit);
item_map.put("account_id",2293182000000114073);
item_map.put("customer_id",vendordet.Zoho_Book_vendor_ID);
}
item_list.add(item_map);
}
cus = List();
custom_field_map = Map();
custom_field_map.put("label","Internal Invoice Number");
custom_field_map.put("value",auto);
cus.add(custom_field_map);
mymap = Map();
mymap.put("journal_date",zoho.currentdate.toString("yyyy-MM-dd"));
mymap.put("reference_number",transaction_det.Transaction);
mymap.put("notes","Testing");
mymap.put("line_items",item_list);
mymap.put("custom_fields",cus);
mymap.put("branch_id",branchdet.Books_Branch_ID);
responseBooks = invokeurl
[
url :"https://www.zohoapis.in/books/v3/journals?organization_id=60036667486"
type :POST
parameters:mymap.toString()
connection:"zoho_books_connection"
];
info responseBooks;
getJournal = responseBooks.get("journal");
Zoho_Books_ID = getJournal.getJson("journal_id");
for each recs1 in transaction_det
{
recs1.Zoho_Books_ID=getJournal.getJson("journal_id");
}
test_inv = Internal_Invoice[ID == new_record];
test_inv.Books_Journal_ID=Zoho_Books_ID;
file = invokeurl
[
url :"https://creatorapp.zohopublic.in/export/centralisedprocurement_usdcglobal/usdc1/pdf/Invoice_Genaration/NAnqSqjre2tGBYC07d79UnSkaCzn074uJYKU0HdTGErCYMTduAs7d2mEGuQ2hmMqnFsBz0V4DEHy1H80h8aZxkYrzsNSBduC5Md1?con=" + transaction_det.ID + "&isc5page=true"
type :GET
connection:"zoho_oauth_connection"
];
file.setparamname("attachment");
response = invokeurl
[
url :"https://www.zohoapis.in/books/v3/journals/" + Zoho_Books_ID + "/attachment?organization_id=60036667486"
type :POST
files:file
connection:"zoho_books_connection"
];
}
else
{
// openUrl("#Page", );
// openUrl("#Page:Alert_Page?id1=Please Request a document before Assign Agent","popup window");
openUrl("#Page:Alert?id1=Total Accumulated ammount is in negative. Invoice cannot be created for this transaction.","popup window");
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter