Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2020
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void sendPaymentRequestViaBot(int id, string type)
  2. {
  3.     // bot token
  4.     TOKEN = "916053223:AAFPhxzOgstQhf_nq8PayQeRySW0FkRL5X0";
  5.     // list of recipients
  6.     // Alex, Dmitry
  7.     users = {314757424, 241327103};
  8.     // text of the message
  9.     text = "";
  10.     // current user
  11.     zohoUser = Telegram_Account[Zoho_Login.equalsIgnoreCase(zoho.loginuser)];
  12.     // future request to get it's ID
  13.     req = null;
  14.     //
  15.     // get object by id and type
  16.     //
  17.     if (type.equalsIgnoreCase("Reservation")) {
  18.         reservationInfo = Reservation_Pay_Info[ID == id];
  19.         if (reservationInfo != null) {
  20.             org = Organizations[Full_Name.equalsIgnoreCase("Altezza Travelling LTD")];
  21.             currency = Currencies[Name.equalsIgnoreCase("USD")];
  22.             cashFlowItem = Cash_Flow_Items[Cash_Flow_Item.equalsIgnoreCase("Accommodations")];
  23.             supplier = Suppliers[ID == reservationInfo.Supplier_ID.toLong()];
  24.             supplierName = ifnull(supplier.Supplier_Name,"");
  25.             res = Reservation[ID == reservationInfo.Accomodation_ID.toLong()];
  26.             client = res.Client_Name;
  27.             checkIn = res.Check_In.toString("dd.MM.yyyy");
  28.             res.Payment_Request_Status = "Sent";
  29.             req = insert into Funds_Expenditure_Request
  30.             [
  31.                 Added_User = zoho.loginuser
  32.                 Operation = "Payment to Supplier"
  33.                 Date_field = zoho.currentdate
  34.                 Organization=org
  35.                 Payment_Method="Bank Transfer"
  36.                 Supplier=supplier
  37.                 Status="In Progress"
  38.                 Amount=reservationInfo.Amount1
  39.                 Currency=currency
  40.                 Cash_Flow_Item=cashFlowItem
  41.                 Date_of_Payment=reservationInfo.Date_of_Payment
  42.                 Accommodation_ID=reservationInfo.Accomodation_ID
  43.                 Comment="Client: " + client
  44.             ];
  45.             // build text
  46.             text = "<b>Initiator:</b> " + zohoUser.Name + "\n" +
  47.             "<b>Date:</b> " + zoho.currentdate.toString("dd.MM.yyyy") + "\n" +
  48.             "<b>Organization:</b> " + org.Full_Name + "\n" +
  49.             "<b>Payment Method:</b> Bank Transfer" + "\n" +
  50.             "<b>Supplier:</b> " + supplierName + "\n" +
  51.             "<b>Check-In:</b> " + checkIn + "\n" +
  52.             "<b>Amount:</b> " + reservationInfo.Amount1 + "\n" +
  53.             "<b>Currency:</b> " + currency.Name + "\n" +
  54.             "<b>Cash Flow Item:</b> " + cashFlowItem.Cash_Flow_Item + "\n" +
  55.             "<b>Client:</b> " + client + "\n" +
  56.             "<b>Date of Payment:</b> " + reservationInfo.Date_of_Payment.toString("dd.MM.yyyy");
  57.         }
  58.     } else if (type.equalsIgnoreCase("Fuel")) {
  59.         fuelInfo = Fuel_Top_up[ID == id];
  60.         if (fuelInfo != null) {
  61.             org = Organizations[Full_Name.equalsIgnoreCase("Altezza Travelling LTD")];
  62.             currency = Currencies[Name.equalsIgnoreCase("TZS")];
  63.             cashFlowItem = Cash_Flow_Items[Cash_Flow_Item.equalsIgnoreCase("Fuel")];
  64.             respCenter = Responsibility_Centres[Responsibility_Centre.equalsIgnoreCase("Operations")];
  65.             employeeString = "";
  66.             employee = null;
  67.             if(fuelInfo.Driver.Employee != null)
  68.             {
  69.                 employee = Add_Employee[ID == fuelInfo.Driver.Employee];
  70.                 if(employee != null)
  71.                 {
  72.                     employeeString = ("<b>Employee:</b> " + employee.Name) + "\n";
  73.                 }
  74.             }
  75.             req = insert into Funds_Expenditure_Request
  76.             [
  77.                 Added_User=zoho.loginuser
  78.                 Operation="Petty Cash"
  79.                 Date_field=zoho.currentdate
  80.                 Organization=org
  81.                 Payment_Method="Cash"
  82.                 Employee=employee
  83.                 Status="In Progress"
  84.                 Amount=fuelInfo.Amount
  85.                 Currency=currency
  86.                 Cash_Flow_Item=cashFlowItem
  87.                 Date_of_Payment=fuelInfo.Fuel_Top_up_Date
  88.                 Responsibility_Centre=respCenter
  89.                 Fuel_Top_up_ID=fuelInfo.ID
  90.             ];
  91.             // build text
  92.             text = "<b>Initiator:</b> " + zohoUser.Name + "\n" +
  93.             "<b>Date:</b> " + zoho.currentdate.toString("dd.MM.yyyy") + "\n" +
  94.             "<b>Organization:</b> " + org.Full_Name + "\n" +
  95.             "<b>Payment Method:</b> Cash" + "\n" +
  96.             employeeString +
  97.             "<b>Amount:</b> " + fuelInfo.Amount + "\n" +
  98.             "<b>Currency:</b> " + currency.Name + "\n" +
  99.             "<b>Cash Flow Item:</b> " + cashFlowItem.Cash_Flow_Item + "\n" +
  100.             "<b>Date of Payment:</b> " + fuelInfo.Fuel_Top_up_Date.toString("dd.MM.yyyy") + "\n" +
  101.             "<b>Responsibility Centre:</b> Operations" + "\n" +
  102.             "<b>Comment:</b> Fuel voucher number " + fuelInfo.Fuel_Voucher;
  103.         }
  104.     } else if (type.equalsIgnoreCase("Car Service")) {
  105.         carServiceInfo = Car_Service[ID == id];
  106.         if (carServiceInfo != null) {
  107.             org = Organizations[Full_Name.equalsIgnoreCase("Altezza Travelling LTD")];
  108.             currency = Currencies[Name.equalsIgnoreCase("TZS")];
  109.             cashFlowItem = Cash_Flow_Items[Cash_Flow_Item.equalsIgnoreCase("Car Repair")];
  110.             respCenter = Responsibility_Centres[Responsibility_Centre.equalsIgnoreCase("Operations")];
  111.             odometerString = if(carServiceInfo.Odometer == null,"",carServiceInfo.Odometer + " km. ");
  112.             employeeString = "";
  113.             if(carServiceInfo.Driver.Employee != null)
  114.             {
  115.                 employee = Add_Employee[ID == carServiceInfo.Driver.Employee];
  116.                 if(employee != null)
  117.                 {
  118.                     employeeString = ("<b>Employee:</b> " + employee.Name) + "\n";
  119.                 }
  120.             }
  121.             req = insert into Funds_Expenditure_Request
  122.             [
  123.                 Added_User=zoho.loginuser
  124.                 Operation="Petty Cash"
  125.                 Date_field=zoho.currentdate
  126.                 Organization=org
  127.                 Payment_Method="Cash"
  128.                 Status="In Progress"
  129.                 Amount=carServiceInfo.Amount
  130.                 Currency=currency
  131.                 Cash_Flow_Item=cashFlowItem
  132.                 Date_of_Payment=carServiceInfo.Date_field
  133.                 Responsibility_Centre=respCenter
  134.                 Car_Service_ID=carServiceInfo.ID
  135.             ];
  136.             // build text
  137.             text = "<b>Initiator:</b> " + zohoUser.Name + "\n" +
  138.             "<b>Date:</b> " + zoho.currentdate.toString("dd.MM.yyyy") + "\n" +
  139.             "<b>Organization:</b> " + org.Full_Name + "\n" +
  140.             "<b>Payment Method:</b> Cash" + "\n" +
  141.             employeeString +
  142.             "<b>Amount:</b> " + carServiceInfo.Amount + "\n" +
  143.             "<b>Currency:</b> " + currency.Name + "\n" +
  144.             "<b>Cash Flow Item:</b> " + cashFlowItem.Cash_Flow_Item + "\n" +
  145.             "<b>Date of Payment:</b> " + carServiceInfo.Date_field.toString("dd.MM.yyyy") + "\n" +
  146.             "<b>Responsibility Centre:</b> Operations" + "\n" +
  147.             "<b>Comment:</b> " + if(carServiceInfo.Normal_Service,"Normal Service. ","") +
  148.             odometerString +
  149.             carServiceInfo.Note;
  150.         }
  151.     } else if (type.equalsIgnoreCase("Flight")) {
  152.         flight = Flights[ID == id];
  153.         if (flight != null) {
  154.             org = Organizations[Full_Name.equalsIgnoreCase("Altezza Travelling LTD")];
  155.             currency = Currencies[Name.equalsIgnoreCase("TZS")];
  156.             cashFlowItem = Cash_Flow_Items[Cash_Flow_Item.equalsIgnoreCase("Flights")];
  157.             req = insert into Funds_Expenditure_Request
  158.             [
  159.                 Added_User=zoho.loginuser
  160.                 Operation="Payment to Supplier"
  161.                 Date_field=zoho.currentdate
  162.                 Organization=org
  163.                 Payment_Method="Cash"
  164.                 Status="In Progress"
  165.                 Amount=flight.Total_Price
  166.                 Currency=currency
  167.                 Cash_Flow_Item=cashFlowItem
  168.                 Flight_ID=flight.ID
  169.                 Comment=flight.Client + " - " + flight.Departure_Date.toString("dd MMM yyyy")
  170.             ];
  171.             // build text
  172.             text = "<b>Initiator:</b> " + zohoUser.Name + "\n" +
  173.             "<b>Date:</b> " + zoho.currentdate.toString("dd.MM.yyyy") + "\n" +
  174.             "<b>Organization:</b> " + org.Full_Name + "\n" +
  175.             "<b>Payment Method:</b> Cash" + "\n" +
  176.             "<b>Amount:</b> " + flight.Total_Price + "\n" +
  177.             "<b>Currency:</b> " + currency.Name + "\n" +
  178.             "<b>Cash Flow Item:</b> " + cashFlowItem.Cash_Flow_Item + "\n" +
  179.             "<b>Comment:</b> " + flight.Client + " - " + flight.Departure_Date.toString("dd MMM yyyy");
  180.         }
  181.     } else if (type.equalsIgnoreCase("Excursion")) {
  182.         excursion = Excursions[ID == id];
  183.         if (excursion != null) {
  184.             org = Organizations[Full_Name.equalsIgnoreCase("Altezza Travelling LTD")];
  185.             currency = Currencies[Name.equalsIgnoreCase("TZS")];
  186.             cashFlowItem = Cash_Flow_Items[Cash_Flow_Item.equalsIgnoreCase("Excursions")];
  187.             req = insert into Funds_Expenditure_Request
  188.             [
  189.                 Added_User=zoho.loginuser
  190.                 Operation="Payment to Supplier"
  191.                 Date_field=zoho.currentdate
  192.                 Organization=org
  193.                 Payment_Method="Cash"
  194.                 Status="In Progress"
  195.                 Amount=excursion.Total_Price
  196.                 Currency=currency
  197.                 Cash_Flow_Item=cashFlowItem
  198.                 Excursion_ID=excursion.ID
  199.                 Comment=excursion.Client + " - " + excursion.Pickup_Date_Time.toString("dd MMM yyyy")
  200.             ];
  201.             // build text
  202.             text = "<b>Initiator:</b> " + zohoUser.Name + "\n" +
  203.             "<b>Date:</b> " + zoho.currentdate.toString("dd.MM.yyyy") + "\n" +
  204.             "<b>Organization:</b> " + org.Full_Name + "\n" +
  205.             "<b>Payment Method:</b> Cash" + "\n" +
  206.             "<b>Amount:</b> " + excursion.Total_Price + "\n" +
  207.             "<b>Currency:</b> " + currency.Name + "\n" +
  208.             "<b>Cash Flow Item:</b> " + cashFlowItem.Cash_Flow_Item + "\n" +
  209.             "<b>Comment:</b> " + excursion.Client + " - " + excursion.Pickup_Date_Time.toString("dd MMM yyyy");
  210.         }
  211.     } else if (type.equalsIgnoreCase("Lunch")) {
  212.         lunch = Lunches[ID == id];
  213.         if (lunch != null) {
  214.             org = Organizations[Full_Name.equalsIgnoreCase("Altezza Travelling LTD")];
  215.             currency = Currencies[Name.equalsIgnoreCase("TZS")];
  216.             cashFlowItem = Cash_Flow_Items[Cash_Flow_Item.equalsIgnoreCase("Food & Beverage")];
  217.             comment = lunch.Client + " - ";
  218.             comment = comment + ifnull(lunch.Regular,0) + " Regular / ";
  219.             comment = comment + ifnull(lunch.Vegan,0) + " Vegeterian / ";
  220.             comment = comment + ifnull(lunch.Special,0) + " Special";
  221.             req = insert into Funds_Expenditure_Request
  222.             [
  223.                 Added_User=zoho.loginuser
  224.                 Operation="Payment to Supplier"
  225.                 Date_field=zoho.currentdate
  226.                 Organization=org
  227.                 Payment_Method="Cash"
  228.                 Status="In Progress"
  229.                 Amount=lunch.Total_Price
  230.                 Currency=currency
  231.                 Cash_Flow_Item=cashFlowItem
  232.                 Lunch_ID=lunch.ID
  233.                 Comment=comment
  234.             ];
  235.             // build text
  236.             text = "<b>Initiator:</b> " + zohoUser.Name + "\n" +
  237.             "<b>Date:</b> " + zoho.currentdate.toString("dd.MM.yyyy") + "\n" +
  238.             "<b>Organization:</b> " + org.Full_Name + "\n" +
  239.             "<b>Payment Method:</b> Cash" + "\n" +
  240.             "<b>Amount:</b> " + lunch.Total_Price + "\n" +
  241.             "<b>Currency:</b> " + currency.Name + "\n" +
  242.             "<b>Cash Flow Item:</b> " + cashFlowItem.Cash_Flow_Item + "\n" +
  243.             "<b>Comment:</b> " + comment;
  244.         }
  245.     } else if (type.equalsIgnoreCase("Storage Order")) {
  246.         order = Storage_Order[ID == id];
  247.         if (order != null) {
  248.             org = Organizations[Full_Name.equalsIgnoreCase("Altezza Travelling LTD")];
  249.             currency = Currencies[Name.equalsIgnoreCase("TZS")];
  250.             cashFlowItem = Cash_Flow_Items[Cash_Flow_Item.equalsIgnoreCase("Food & Beverage")];
  251.             req = insert into Funds_Expenditure_Request
  252.             [
  253.                 Added_User=zoho.loginuser
  254.                 Operation="Payment to Supplier"
  255.                 Date_field=zoho.currentdate
  256.                 Organization=org
  257.                 Payment_Method="Cash"
  258.                 Status="In Progress"
  259.                 Amount=order.Total_Amount
  260.                 Currency=currency
  261.                 Cash_Flow_Item=cashFlowItem
  262.                 Storage_Order_ID=order.ID
  263.             ];
  264.             // build text
  265.             text = "%F0%9F%A5%91 <b>PURCHASIN FOR STORAGE</b>" + "\n" +
  266.             "<b>Initiator:</b> " + zohoUser.Name + "\n" +
  267.             "<b>Date:</b> " + zoho.currentdate.toString("dd.MM.yyyy") + "\n" +
  268.             "<b>Organization:</b> " + org.Full_Name + "\n" +
  269.             "<b>Payment Method:</b> Cash" + "\n" +
  270.             "<b>Amount:</b> " + order.Total_Amount + "\n" +
  271.             "<b>Currency:</b> " + currency.Name + "\n" +
  272.             "<b>Cash Flow Item:</b> " + cashFlowItem.Cash_Flow_Item + "\n";
  273.         }
  274.     } else if (type.equalsIgnoreCase("Request")) {
  275.         req = Funds_Expenditure_Request[ID == id];
  276.         if (req != null) {
  277.             req.Status = "In Progress";
  278.             // build text
  279.             text = "<b>Initiaror:</b> " + zohoUser.Name + "\n" +
  280.             "<b>Date:</b> " + req.Date_field.toString("dd.MM.yyyy") + "\n" +
  281.             "<b>Organization:</b> " + req.Organization.Full_Name + "\n" +
  282.             "<b>Payment Method:</b> " + req.Payment_Method + "\n" +
  283.             "<b>Supplier:</b> " + ifnull(req.Supplier.Supplier_Name,"") + "\n" +
  284.             "<b>Employee:</b> " + ifnull(req.Employee.Name,"") + "\n" +
  285.             "<b>Amount:</b> " + req.Amount + "\n" +
  286.             "<b>Currency:</b> " + req.Currency.Name + "\n" +
  287.             "<b>Cash Flow Item:</b> " + req.Cash_Flow_Item.Cash_Flow_Item + "\n" +
  288.             "<b>Date of Payment:</b> " + req.Date_of_Payment.toString("dd.MM.yyyy") + "\n" +
  289.             "<b>Responsibility Centre:</b> " + ifnull(req.Responsibility_Centre.Responsibility_Centre,"") + "\n" +
  290.             "<b>Comment:</b> " + req.Comment;
  291.         }
  292.     }
  293.     if (req != null) {
  294.         // prepare message to send
  295.         text = zoho.encryption.urlEncode(text);
  296.         approveData = "1 " + req.toString() + " " + zohoUser.Telegram_ID;
  297.         rejectData = "0 " + req.toString() + " " + zohoUser.Telegram_ID;
  298.         // send message to all recipients
  299.         for each  u in users
  300.         {
  301.             url = "https://api.telegram.org/bot" + TOKEN + "/sendMessage?chat_id=" + u +
  302.             "&text=" + text +
  303.             "&parse_mode=HTML&reply_markup={\"inline_keyboard\":[[{\"text\":\"%E2%9C%85 Approve\",\"callback_data\":\"" + approveData +
  304.             "\"},{\"text\":\"%E2%9B%94 Reject\",\"callback_data\":\"" + rejectData + "\"}]]}";
  305.             postUrl(url,Map());
  306.         }
  307.     }
  308. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement