Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void sendPaymentRequestViaBot(int id, string type)
- {
- // bot token
- TOKEN = "123456789:XXXXxxXxxxXxx_xxXXxxXxXxXXXXxXXXXX";
- // list of recipients
- // Alex, Dmitry
- users = {111111111, 222222222};
- // text of the message
- text = "";
- // current user
- zohoUser = Telegram_Account[Zoho_Login.equalsIgnoreCase(zoho.loginuser)];
- // future request to get it's ID
- req = null;
- //
- // get object by id and type
- //
- if (type.equalsIgnoreCase("Reservation")) {
- reservationInfo = Reservation_Pay_Info[ID == id];
- if (reservationInfo != null) {
- org = Organizations[Full_Name.equalsIgnoreCase("Altezza Travelling LTD")];
- currency = Currencies[Name.equalsIgnoreCase("USD")];
- cashFlowItem = Cash_Flow_Items[Cash_Flow_Item.equalsIgnoreCase("Accommodations")];
- supplier = Suppliers[ID == reservationInfo.Supplier_ID.toLong()];
- supplierName = ifnull(supplier.Supplier_Name,"");
- res = Reservation[ID == reservationInfo.Accomodation_ID.toLong()];
- client = res.Client_Name;
- checkIn = res.Check_In.toString("dd.MM.yyyy");
- res.Payment_Request_Status = "Sent";
- req = insert into Funds_Expenditure_Request
- [
- Added_User = zoho.loginuser
- Operation = "Payment to Supplier"
- Date_field = zoho.currentdate
- Organization=org
- Payment_Method="Bank Transfer"
- Supplier=supplier
- Status="In Progress"
- Amount=reservationInfo.Amount1
- Currency=currency
- Cash_Flow_Item=cashFlowItem
- Date_of_Payment=reservationInfo.Date_of_Payment
- Accommodation_ID=reservationInfo.Accomodation_ID
- Comment="Client: " + client
- ];
- // build text
- text = "<b>Initiator:</b> " + zohoUser.Name + "\n" +
- "<b>Date:</b> " + zoho.currentdate.toString("dd.MM.yyyy") + "\n" +
- "<b>Organization:</b> " + org.Full_Name + "\n" +
- "<b>Payment Method:</b> Bank Transfer" + "\n" +
- "<b>Supplier:</b> " + supplierName + "\n" +
- "<b>Check-In:</b> " + checkIn + "\n" +
- "<b>Amount:</b> " + reservationInfo.Amount1 + "\n" +
- "<b>Currency:</b> " + currency.Name + "\n" +
- "<b>Cash Flow Item:</b> " + cashFlowItem.Cash_Flow_Item + "\n" +
- "<b>Client:</b> " + client + "\n" +
- "<b>Date of Payment:</b> " + reservationInfo.Date_of_Payment.toString("dd.MM.yyyy");
- }
- } else if (type.equalsIgnoreCase("Fuel")) {
- fuelInfo = Fuel_Top_up[ID == id];
- if (fuelInfo != null) {
- org = Organizations[Full_Name.equalsIgnoreCase("Altezza Travelling LTD")];
- currency = Currencies[Name.equalsIgnoreCase("TZS")];
- cashFlowItem = Cash_Flow_Items[Cash_Flow_Item.equalsIgnoreCase("Fuel")];
- respCenter = Responsibility_Centres[Responsibility_Centre.equalsIgnoreCase("Operations")];
- employeeString = "";
- employee = null;
- if(fuelInfo.Driver.Employee != null)
- {
- employee = Add_Employee[ID == fuelInfo.Driver.Employee];
- if(employee != null)
- {
- employeeString = ("<b>Employee:</b> " + employee.Name) + "\n";
- }
- }
- req = insert into Funds_Expenditure_Request
- [
- Added_User=zoho.loginuser
- Operation="Petty Cash"
- Date_field=zoho.currentdate
- Organization=org
- Payment_Method="Cash"
- Employee=employee
- Status="In Progress"
- Amount=fuelInfo.Amount
- Currency=currency
- Cash_Flow_Item=cashFlowItem
- Date_of_Payment=fuelInfo.Fuel_Top_up_Date
- Responsibility_Centre=respCenter
- Fuel_Top_up_ID=fuelInfo.ID
- ];
- // build text
- text = "<b>Initiator:</b> " + zohoUser.Name + "\n" +
- "<b>Date:</b> " + zoho.currentdate.toString("dd.MM.yyyy") + "\n" +
- "<b>Organization:</b> " + org.Full_Name + "\n" +
- "<b>Payment Method:</b> Cash" + "\n" +
- employeeString +
- "<b>Amount:</b> " + fuelInfo.Amount + "\n" +
- "<b>Currency:</b> " + currency.Name + "\n" +
- "<b>Cash Flow Item:</b> " + cashFlowItem.Cash_Flow_Item + "\n" +
- "<b>Date of Payment:</b> " + fuelInfo.Fuel_Top_up_Date.toString("dd.MM.yyyy") + "\n" +
- "<b>Responsibility Centre:</b> Operations" + "\n" +
- "<b>Comment:</b> Fuel voucher number " + fuelInfo.Fuel_Voucher;
- }
- } else if (type.equalsIgnoreCase("Car Service")) {
- carServiceInfo = Car_Service[ID == id];
- if (carServiceInfo != null) {
- org = Organizations[Full_Name.equalsIgnoreCase("Altezza Travelling LTD")];
- currency = Currencies[Name.equalsIgnoreCase("TZS")];
- cashFlowItem = Cash_Flow_Items[Cash_Flow_Item.equalsIgnoreCase("Car Repair")];
- respCenter = Responsibility_Centres[Responsibility_Centre.equalsIgnoreCase("Operations")];
- odometerString = if(carServiceInfo.Odometer == null,"",carServiceInfo.Odometer + " km. ");
- employeeString = "";
- if(carServiceInfo.Driver.Employee != null)
- {
- employee = Add_Employee[ID == carServiceInfo.Driver.Employee];
- if(employee != null)
- {
- employeeString = ("<b>Employee:</b> " + employee.Name) + "\n";
- }
- }
- req = insert into Funds_Expenditure_Request
- [
- Added_User=zoho.loginuser
- Operation="Petty Cash"
- Date_field=zoho.currentdate
- Organization=org
- Payment_Method="Cash"
- Status="In Progress"
- Amount=carServiceInfo.Amount
- Currency=currency
- Cash_Flow_Item=cashFlowItem
- Date_of_Payment=carServiceInfo.Date_field
- Responsibility_Centre=respCenter
- Car_Service_ID=carServiceInfo.ID
- ];
- // build text
- text = "<b>Initiator:</b> " + zohoUser.Name + "\n" +
- "<b>Date:</b> " + zoho.currentdate.toString("dd.MM.yyyy") + "\n" +
- "<b>Organization:</b> " + org.Full_Name + "\n" +
- "<b>Payment Method:</b> Cash" + "\n" +
- employeeString +
- "<b>Amount:</b> " + carServiceInfo.Amount + "\n" +
- "<b>Currency:</b> " + currency.Name + "\n" +
- "<b>Cash Flow Item:</b> " + cashFlowItem.Cash_Flow_Item + "\n" +
- "<b>Date of Payment:</b> " + carServiceInfo.Date_field.toString("dd.MM.yyyy") + "\n" +
- "<b>Responsibility Centre:</b> Operations" + "\n" +
- "<b>Comment:</b> " + if(carServiceInfo.Normal_Service,"Normal Service. ","") +
- odometerString +
- carServiceInfo.Note;
- }
- } else if (type.equalsIgnoreCase("Flight")) {
- flight = Flights[ID == id];
- if (flight != null) {
- org = Organizations[Full_Name.equalsIgnoreCase("Altezza Travelling LTD")];
- currency = Currencies[Name.equalsIgnoreCase("TZS")];
- cashFlowItem = Cash_Flow_Items[Cash_Flow_Item.equalsIgnoreCase("Flights")];
- req = insert into Funds_Expenditure_Request
- [
- Added_User=zoho.loginuser
- Operation="Payment to Supplier"
- Date_field=zoho.currentdate
- Organization=org
- Payment_Method="Cash"
- Status="In Progress"
- Amount=flight.Total_Price
- Currency=currency
- Cash_Flow_Item=cashFlowItem
- Flight_ID=flight.ID
- Comment=flight.Client + " - " + flight.Departure_Date.toString("dd MMM yyyy")
- ];
- // build text
- text = "<b>Initiator:</b> " + zohoUser.Name + "\n" +
- "<b>Date:</b> " + zoho.currentdate.toString("dd.MM.yyyy") + "\n" +
- "<b>Organization:</b> " + org.Full_Name + "\n" +
- "<b>Payment Method:</b> Cash" + "\n" +
- "<b>Amount:</b> " + flight.Total_Price + "\n" +
- "<b>Currency:</b> " + currency.Name + "\n" +
- "<b>Cash Flow Item:</b> " + cashFlowItem.Cash_Flow_Item + "\n" +
- "<b>Comment:</b> " + flight.Client + " - " + flight.Departure_Date.toString("dd MMM yyyy");
- }
- } else if (type.equalsIgnoreCase("Excursion")) {
- excursion = Excursions[ID == id];
- if (excursion != null) {
- org = Organizations[Full_Name.equalsIgnoreCase("Altezza Travelling LTD")];
- currency = Currencies[Name.equalsIgnoreCase("TZS")];
- cashFlowItem = Cash_Flow_Items[Cash_Flow_Item.equalsIgnoreCase("Excursions")];
- req = insert into Funds_Expenditure_Request
- [
- Added_User=zoho.loginuser
- Operation="Payment to Supplier"
- Date_field=zoho.currentdate
- Organization=org
- Payment_Method="Cash"
- Status="In Progress"
- Amount=excursion.Total_Price
- Currency=currency
- Cash_Flow_Item=cashFlowItem
- Excursion_ID=excursion.ID
- Comment=excursion.Client + " - " + excursion.Pickup_Date_Time.toString("dd MMM yyyy")
- ];
- // build text
- text = "<b>Initiator:</b> " + zohoUser.Name + "\n" +
- "<b>Date:</b> " + zoho.currentdate.toString("dd.MM.yyyy") + "\n" +
- "<b>Organization:</b> " + org.Full_Name + "\n" +
- "<b>Payment Method:</b> Cash" + "\n" +
- "<b>Amount:</b> " + excursion.Total_Price + "\n" +
- "<b>Currency:</b> " + currency.Name + "\n" +
- "<b>Cash Flow Item:</b> " + cashFlowItem.Cash_Flow_Item + "\n" +
- "<b>Comment:</b> " + excursion.Client + " - " + excursion.Pickup_Date_Time.toString("dd MMM yyyy");
- }
- } else if (type.equalsIgnoreCase("Lunch")) {
- lunch = Lunches[ID == id];
- if (lunch != null) {
- org = Organizations[Full_Name.equalsIgnoreCase("Altezza Travelling LTD")];
- currency = Currencies[Name.equalsIgnoreCase("TZS")];
- cashFlowItem = Cash_Flow_Items[Cash_Flow_Item.equalsIgnoreCase("Food & Beverage")];
- comment = lunch.Client + " - ";
- comment = comment + ifnull(lunch.Regular,0) + " Regular / ";
- comment = comment + ifnull(lunch.Vegan,0) + " Vegeterian / ";
- comment = comment + ifnull(lunch.Special,0) + " Special";
- req = insert into Funds_Expenditure_Request
- [
- Added_User=zoho.loginuser
- Operation="Payment to Supplier"
- Date_field=zoho.currentdate
- Organization=org
- Payment_Method="Cash"
- Status="In Progress"
- Amount=lunch.Total_Price
- Currency=currency
- Cash_Flow_Item=cashFlowItem
- Lunch_ID=lunch.ID
- Comment=comment
- ];
- // build text
- text = "<b>Initiator:</b> " + zohoUser.Name + "\n" +
- "<b>Date:</b> " + zoho.currentdate.toString("dd.MM.yyyy") + "\n" +
- "<b>Organization:</b> " + org.Full_Name + "\n" +
- "<b>Payment Method:</b> Cash" + "\n" +
- "<b>Amount:</b> " + lunch.Total_Price + "\n" +
- "<b>Currency:</b> " + currency.Name + "\n" +
- "<b>Cash Flow Item:</b> " + cashFlowItem.Cash_Flow_Item + "\n" +
- "<b>Comment:</b> " + comment;
- }
- } else if (type.equalsIgnoreCase("Storage Order")) {
- order = Storage_Order[ID == id];
- if (order != null) {
- org = Organizations[Full_Name.equalsIgnoreCase("Altezza Travelling LTD")];
- currency = Currencies[Name.equalsIgnoreCase("TZS")];
- cashFlowItem = Cash_Flow_Items[Cash_Flow_Item.equalsIgnoreCase("Food & Beverage")];
- req = insert into Funds_Expenditure_Request
- [
- Added_User=zoho.loginuser
- Operation="Payment to Supplier"
- Date_field=zoho.currentdate
- Organization=org
- Payment_Method="Cash"
- Status="In Progress"
- Amount=order.Total_Amount
- Currency=currency
- Cash_Flow_Item=cashFlowItem
- Storage_Order_ID=order.ID
- ];
- // build text
- text = "%F0%9F%A5%91 <b>PURCHASIN FOR STORAGE</b>" + "\n" +
- "<b>Initiator:</b> " + zohoUser.Name + "\n" +
- "<b>Date:</b> " + zoho.currentdate.toString("dd.MM.yyyy") + "\n" +
- "<b>Organization:</b> " + org.Full_Name + "\n" +
- "<b>Payment Method:</b> Cash" + "\n" +
- "<b>Amount:</b> " + order.Total_Amount + "\n" +
- "<b>Currency:</b> " + currency.Name + "\n" +
- "<b>Cash Flow Item:</b> " + cashFlowItem.Cash_Flow_Item + "\n";
- }
- } else if (type.equalsIgnoreCase("Request")) {
- req = Funds_Expenditure_Request[ID == id];
- if (req != null) {
- req.Status = "In Progress";
- // build text
- text = "<b>Initiaror:</b> " + zohoUser.Name + "\n" +
- "<b>Date:</b> " + req.Date_field.toString("dd.MM.yyyy") + "\n" +
- "<b>Organization:</b> " + req.Organization.Full_Name + "\n" +
- "<b>Payment Method:</b> " + req.Payment_Method + "\n" +
- "<b>Supplier:</b> " + ifnull(req.Supplier.Supplier_Name,"") + "\n" +
- "<b>Employee:</b> " + ifnull(req.Employee.Name,"") + "\n" +
- "<b>Amount:</b> " + req.Amount + "\n" +
- "<b>Currency:</b> " + req.Currency.Name + "\n" +
- "<b>Cash Flow Item:</b> " + req.Cash_Flow_Item.Cash_Flow_Item + "\n" +
- "<b>Date of Payment:</b> " + req.Date_of_Payment.toString("dd.MM.yyyy") + "\n" +
- "<b>Responsibility Centre:</b> " + ifnull(req.Responsibility_Centre.Responsibility_Centre,"") + "\n" +
- "<b>Comment:</b> " + req.Comment;
- }
- }
- if (req != null) {
- // prepare message to send
- text = zoho.encryption.urlEncode(text);
- approveData = "1 " + req.toString() + " " + zohoUser.Telegram_ID;
- rejectData = "0 " + req.toString() + " " + zohoUser.Telegram_ID;
- // send message to all recipients
- for each u in users
- {
- url = "https://api.telegram.org/bot" + TOKEN + "/sendMessage?chat_id=" + u +
- "&text=" + text +
- "&parse_mode=HTML&reply_markup={\"inline_keyboard\":[[{\"text\":\"%E2%9C%85 Approve\",\"callback_data\":\"" + approveData +
- "\"},{\"text\":\"%E2%9B%94 Reject\",\"callback_data\":\"" + rejectData + "\"}]]}";
- postUrl(url,Map());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement