Printing invoice from creator using writer

Printing invoice from creator using writer

Hello.

I have created my invoices using Zoho Writer and i'm sending data to them from Zoho Creator by selecting a row in a report and then clicking a button which has  workflow connected to it to send the date to the invoice in writer. This is working but it is slow but what happens is it is creating the pdf file and showing this in a popup window, i then have to click on this pdf file which opens yest another window and displays the invoice and then i have to right click on the pdf file which is open and select print from the browser menu (currently only works in Google Chrome) and this then open the browser print window.

There must be a way after clicking the first button "Print" after selecting the row from the report that this will open the invoice from writer directly in the browser print window and cut out all of the steps as this is not user friendly at all.

there is a lot of code used for this but most of it is to populate the fields in the invoice.

  1. if(input.ID != null)
    {
        deliverData = List();
        selectedInvoiceRecords = Invoices[ID == input.ID];
        invoiceNumber = selectedInvoiceRecords.Invoice_Number;
        customerKey = selectedInvoiceRecords.Customer_Key;
        invoiceCompanyName = selectedInvoiceRecords.Invoice_Customer;
        invoiceAddress1 = selectedInvoiceRecords.Invoice_Address;
        invoiceAddress2 = selectedInvoiceRecords.Invoice_Address_2;
        invoiceTown = selectedInvoiceRecords.Invoice_Town;
        invoiceCounty = selectedInvoiceRecords.Invoice_County;
        invoicePostcode = selectedInvoiceRecords.Invoice_Postcode;
        deliverCompanyName = selectedInvoiceRecords.Delivery_Name;
        deliveryAddress1 = selectedInvoiceRecords.Delivery_Address;
        deliveryAddress2 = selectedInvoiceRecords.Delivery_Address_2;
        deliveryTown = selectedInvoiceRecords.Delivery_Town;
        deliveryCounty = selectedInvoiceRecords.Delivery_County;
        deliveryPostcode = selectedInvoiceRecords.Delivery_Postcode;
        invoiceDate = selectedInvoiceRecords.Invoice_Date;
        if(invoiceDate != null)
        {
            formattedDate = toDate(invoiceDate,"dd-MMM-yyyy HH:mm:ss").toString("dd/MM/yyyy");
        }
        else
        {
            formattedDate = "";
        }
        invoiceRef = selectedInvoiceRecords.Invoice_Ref;
        selectedCustomerDeliveryCompanyName = Customer_Delivery_Address[Delivery_Address_Name == deliverCompanyName];
        selectedCustomerInvoiceCompanyName = Customer_Invoice_Addresses[Company_Name == invoiceCompanyName];
        if(selectedCustomerDeliveryCompanyName.count() > 0 && selectedCustomerInvoiceCompanyName.count() > 0)
        {
            selectedSalesOrderEntry = Sales_Order_Entry[Customer_Delivery_Address == selectedCustomerDeliveryCompanyName.ID && Customer_Invoice_Address == selectedCustomerInvoiceCompanyName];
        }
        if(selectedSalesOrderEntry.count() > 0)
        {
            customerKeyID = selectedSalesOrderEntry.Customer_Key;
            if(customerKeyID != null)
            {
                selectedCustomer = customers[ID == customerKeyID];
                if(selectedCustomer.Key != null)
                {
                    CustomerAC = selectedCustomer.Key;
                }
            }
            else
            {
                CustomerAC = "";
            }
        }
        else
        {
            CustomerAC = "";
        }
        if(selectedSalesOrderEntry.count() > 0)
        {
            selectedTotalSalesOrderLines = Sales_Order_Lines[ID == selectedSalesOrderEntry.Sales_Order_Entry];
        }
        if(deliverCompanyName != null)
        {
            selectedDeliveryNoteNumberRecord = Delivery_Notes[Delivery_Name == deliverCompanyName];
            if(selectedSalesOrderEntry.Sales_Order != null)
            {
                salesOrderNumber = selectedSalesOrderEntry.Sales_Order;
            }
            else
            {
                salesOrderNumber = "";
            }
            if(selectedDeliveryNoteNumberRecord.Delivery_note_number != null)
            {
                deliveryNoteNumber = selectedDeliveryNoteNumberRecord.Delivery_note_number;
            }
            else
            {
                deliveryNoteNumber = "";
            }
            orderDescription = "Order:" + salesOrderNumber + "    Delivery Note:" + deliveryNoteNumber;
        }
        else
        {
            orderDescription = "Order:       Delivery Note:";
        }
        //     orderDescription = 
        deliverData.add({"ORDER_TO_COMPANY":invoiceCompanyName,"ORDER_TO_ADDRESS_LINE_1":invoiceAddress1,"ORDER_TO_ADDRESS_LINE_2":invoiceAddress2,"ORDER_TO_TOWN":invoiceTown,"ORDER_TO_COUNTY":invoiceCounty,"ORDER_TO_POSTCODE":invoicePostcode,"DELIVER_TO_COMPANY":deliverCompanyName,"DELIVER_TO_ADDRESS_LINE_1":deliveryAddress1,"DELIVER_TO_ADDRESS_LINE_2":deliveryAddress2,"DELIVER_TO_TOWN":deliveryTown,"DELIVER_TO_COUNTY":deliveryCounty,"DELIVER_TO_POSTCODE":deliveryPostcode,"INVOICE_NO":invoiceNumber,"DATE":formattedDate,"CUSTOMER_AC":CustomerAC,"CONDITION":1,"DESCRIPTION":orderDescription,"SIZE":"Your Ref:","PLANT_PP":invoiceRef});
        sumQTY = 0;
        sumSubTotal = 0;
        sumVat = 0;
        sumTotal = 0;
        for each  item2 in selectedTotalSalesOrderLines
        {
            if(item2.QTY != null)
            {
                sumQTY = sumQTY + item2.QTY.toNumber();
            }
            if(item2.Sub_Total != null)
            {
                sumSubTotal = sumSubTotal + item2.Sub_Total.toNumber();
            }
            if(item2.VAT_Rate != null)
            {
                sumVat = sumVat + item2.VAT_Rate.toNumber();
            }
        }
        sumTotal = sumSubTotal + sumVat;
        for each  item1 in selectedTotalSalesOrderLines
        {
            selectedBatchCode = Batch_Info[Name == item1.Plant_Name && Size == item1.Size];
            if(item1.Sub_Total != null && item1.VAT_Rate != null)
            {
                tTotal = item1.Sub_Total + item1.VAT_Rate;
            }
            else if(item1.Sub_Total != null && item1.VAT_Rate == null)
            {
                tTotal = item1.Sub_Total;
            }
            else if(item1.Sub_Total == null && item1.VAT_Rate != null)
            {
                tTotal = item1.VAT_Rate;
            }
            deliverData.add({"ORDER_TO_COMPANY":invoiceCompanyName,"ORDER_TO_ADDRESS_LINE_1":invoiceAddress1,"ORDER_TO_ADDRESS_LINE_2":invoiceAddress2,"ORDER_TO_TOWN":invoiceTown,"ORDER_TO_COUNTY":invoiceCounty,"ORDER_TO_POSTCODE":invoicePostcode,"DELIVER_TO_COMPANY":deliverCompanyName,"DELIVER_TO_ADDRESS_LINE_1":deliveryAddress1,"DELIVER_TO_ADDRESS_LINE_2":deliveryAddress2,"DELIVER_TO_TOWN":deliveryTown,"DELIVER_TO_COUNTY":deliveryCounty,"DELIVER_TO_POSTCODE":deliveryPostcode,"DATE":formattedDate,"CUSTOMER_AC":CustomerAC,"CONDITION":0,"DESCRIPTION":item1.Plant_Name,"SIZE":item1.Size,"PLANT_PP":selectedBatchCode.Batch_Code,"QTY":item1.QTY,"PRICE":item1.Price,"SUB_TOTAL":item1.Sub_Total,"VAT":item1.VAT_Rate,"TOTAL":tTotal,"SUM_QTY":sumQTY,"SUM_SUB_TOTAL":sumSubTotal,"SUM_VAT":sumVat,"SUM_TOTAL":sumTotal});
        }
        merge_data = {"data":deliverData};
        mergeValues = Map();
        mergeValues.put("merge_data",merge_data);
        mergedPDF2 = zoho.writer.mergeAndDownload("**************************","pdf",mergeValues,"new_zoho_writer_connection");
        mergedPDF2.setFileName("Invoice" + ".pdf");
        //     insert into Credit_Notes
        //     [
        //         Credit_Customer=invoiceCompanyName
        //         Credit_Address=invoiceAddress1
        //         Credit_Address_2=invoiceAddress2
        //         Credit_Town=invoiceTown
        //         Credit_County=invoiceCounty
        //         Credit_Postcode=invoicePostcode
        //         Delivery_Name=deliverCompanyName
        //         Delivery_Address=deliveryAddress1
        //         Delivery_Address_2=deliveryAddress2
        //         Delivery_Town=deliveryTown
        //         Delivery_County=deliveryCounty
        //         Delivery_Postcode=deliveryPostcode
        //         Added_User=zoho.loginuser
        //     ]
        delete from PDF[ID != 0];
        response2 = insert into PDF
        [
            Added_User=zoho.loginuser
            File_upload=mergedPDF2
        ];
        PDFIDs = PDF[ID != 0];
        //     if(PDFIDs.count() > 0)
        //     {
        //         for each  pdfID in PDFIDs
        //         {
        //             //             openUrl("https://creatorapp.zoho.eu/**********/PDF_Report/" + pdfID.ID + "/File_upload/download-file?filepath=/" + pdfID.File_upload + "&digestValue=****************=","new window","successive=true");
        //             openUrl("https://**********.zohocreatorportal.eu/***********/report/PDF_Report/" + pdfID.ID + "/File_upload/download-file?filepath=/" + pdfID.File_upload + "&digestValue=******************=","new window");
        //         }
        //     }
        openUrl("#Report:PDF_Report","popup window","height=1000px,width=1500px");
    }