From cf5cb70ab50dd83699b340c142af70b57a5359cb Mon Sep 17 00:00:00 2001 From: Markus Krogh Date: Mon, 15 Dec 2014 13:52:18 +0100 Subject: Adding ibisiticintegration --- ibisticintegration2.1.ms | 1129 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1129 insertions(+) create mode 100644 ibisticintegration2.1.ms diff --git a/ibisticintegration2.1.ms b/ibisticintegration2.1.ms new file mode 100644 index 0000000..afb921d --- /dev/null +++ b/ibisticintegration2.1.ms @@ -0,0 +1,1129 @@ +#version 17 + +/* + * Copyright 2012 by Lars Poulsen, lars@vicit.dk + * Use Maconomy Version W12.0 + * Web service for Ibistic Travel and Invoice System with a collection of + * operations for fetching and pushing data. + */ +package ibisticintegration2(1); +uses mscript::soap2::api(1) as soapAPI; + + + +var logfilename = "IbisticLog.txt"; + +/*============================================================================ + External web services operations +============================================================================*/ + +/*---------------------------------------------------------------------------- + General service description. + Here we specify various meta data about the web service as a whole. +----------------------------------------------------------------------------*/ + +public var serviceDescription = +{ + // The service namespace defines which namespace to put the service data into + // Used among other things as the "target namespace" for the WSDL generator + serviceNamespace: "maconomy.com", + + // A short documentation text inserted as a "" tag in the + // service part of the WSDL + documentation: "A collection of operations for Ibistic integration with Maconomy." +}; + + +/*---------------------------------------------------------------------------- + Operation: getEmployees + + Input: companyNumber + Output: an array of employees information +----------------------------------------------------------------------------*/ + +public var getEmployeesInfo = +{ + requireSchemaValidation: false, + requireUsernameToken: true, + // Here we specify the data type of each of the parameters to the function. + // In this case there is no input parameters + inputTypes: {CompanyNumber: "string"}, + + // Here we specify the output type of the function. In this case it is + // an array of project numbers as strings +outputType: + { + type: "array", + name: "employeeList", + elements: + { + type: "object", + elements: + { + EmployeeNumber: "string", + Name1: "string", + CompanyNumber: "string", + LocationName: "string", + ElectronicMailAddress: "string", + SuperiorEmployee: "string", + SecretaryEmployee: "string", + VendorNumber: "string", + Bank: "string", + RegistrationNumber: "string", + BankAccountNumber: "string", + CreditCardNumber: "string", + SalarySystemNumber: "string", + VersionNumber: "int", + Blocked: "int" + } + } + }, + + // Documentation to be inserted as a "" tag in the operation + // description in the WSDL. + documentation: 'DOC' +This web service returns an array of employees in the Maconomy system for the selected company. +DOC +}; + + +public function getEmployees(CompanyNumber) +{ + // Use a try-finally statement to guarantee that no matter what happens, we + // always ensure the system is logged out after use. + try + { + //Login to the Maconomy server + //login(); + + // Fetch employee data using SQL and insert them in an array + var theSQLRequestEmp=sprint("select EmployeeNumber, Name1, LocationName, ElectronicMailAddress, SuperiorEmployee, SecretaryEmployee, VendorNumber, Bank, RegistrationNumber, BankAccountNumber, Remark1 as CreditCardNumber, Remark2 as SalarySystemNumber, VersionNumber,CompanyNumber, Blocked from employee where CompanyNumber='^1'",CompanyNumber); // + + var theSQLResultEmp = maconomy::sql(theSQLRequestEmp); + + var employeeList = new [sizeof(theSQLResultEmp.result.rows)]; + + + if (sizeof(theSQLResultEmp.result.rows)>0) + { + for (var i in theSQLResultEmp.result.rows) + employeeList[i] = { + EmployeeNumber: theSQLResultEmp.result.rows[i].EmployeeNumber.value, + Name1: theSQLResultEmp.result.rows[i].Name1.value, + CompanyNumber: theSQLResultEmp.result.rows[i].CompanyNumber.value, + LocationName: theSQLResultEmp.result.rows[i].LocationName.value, + ElectronicMailAddress: theSQLResultEmp.result.rows[i].ElectronicMailAddress.value, + SuperiorEmployee: theSQLResultEmp.result.rows[i].SuperiorEmployee.value, + SecretaryEmployee: theSQLResultEmp.result.rows[i].SecretaryEmployee.value, + VendorNumber: theSQLResultEmp.result.rows[i].VendorNumber.value, + Bank: theSQLResultEmp.result.rows[i].Bank.value, + RegistrationNumber: theSQLResultEmp.result.rows[i].RegistrationNumber.value, + BankAccountNumber: theSQLResultEmp.result.rows[i].BankAccountNumber.value, + CreditCardNumber: theSQLResultEmp.result.rows[i].CreditCardNumber.value, + SalarySystemNumber: theSQLResultEmp.result.rows[i].SalarySystemNumber.value, + VersionNumber: theSQLResultEmp.result.rows[i].VersionNumber.value, + Blocked: theSQLResultEmp.result.rows[i].Blocked.value + }; + } else { + var faultName = "NoEmployeesFound"; + var message = sprint("No employees found "); + soapAPI::generateSimpleFault(faultName, message); + }; + return employeeList; + } +finally; + //logout(); +} + +public var getAccountsInfo = +{ + requireSchemaValidation: true, + requireUsernameToken: true, + // Here we specify the data type of each of the parameters to the function. + // In this case there is no input parameters + inputTypes: {CompanyNumber: "string"}, + + // Here we specify the output type of the function. In this case it is + // an array of project numbers as strings +outputType: + { + type: "array", + name: "accountList", + elements: + { + type: "object", + elements: + { + AccountNumber: "string", + AccountText: "string", + FinanceVATCode: "string", + FinanceVATCodeAllowed: "int", + FinanceVATCodeRequired: "int", + ProfitAndLossStatus: "string", + Currency: "string", + LocationAllowed: "int", + LocationRequired: "int", + EntityName: "string", + OverwriteEntity: "int", + EntityAllowed: "int", + EntityRequired: "int", + Spec2Allowed: "string", + Spec2Required: "string", + EmployeeAllowed: "string", + EmployeeRequired: "string", + Blocked: "int", + CompanyNumber: "string", + VersionNumber: "int" + } + } + }, + + // Documentation to be inserted as a "" tag in the operation + // description in the WSDL. + documentation: 'DOC' +This web service returns an array of accounts in the Maconomy system for the selected company. +DOC +}; + + +public function getAccounts(CompanyNumber) +{ + // Use a try-finally statement to guarantee that no matter what happens, we + // always ensure the system is logged out after use. + try + { + //Login to the Maconomy server + //login(); + + // Fetch employee data using SQL and insert them in an array + //var theSQLRequest=sprint("select EmployeeNumber, Name1, Blocked, CompanyNumber, LocationName, ElectronicMailAddress, SuperiorEmployee, SecretaryEmployee, VendorNumber, Bank, RegistrationNumber, BankAccountNumber, Remark1 as CreditCardNumber, Remark2 as SalarySystemNumber, VersionNumber from employee where CompanyNumber='^1'",CompanyNumber); + var theSQLRequest=sprint("select AccountNumber, AccountText, FinanceVATCode, FinanceVATCodeAllowed, FinanceVATCodeRequired, ProfitAndLossStatus, Currency, LocationAllowed, LocationRequired, EntityName, OverwriteEntity, EntityAllowed, EntityRequired, Spec2Allowed, Spec2Required, EmployeeAllowed, EmployeeRequired, Blocked, '^1' as CompanyNumber, VersionNumber from account order by AccountNumber",CompanyNumber); + + var theSQLResult = maconomy::sql(theSQLRequest); + + var accountList = new [sizeof(theSQLResult.result.rows)]; + + if (sizeof(theSQLResult.result.rows)>0) + { + for (var i in theSQLResult.result.rows) + accountList[i] = { + AccountNumber: theSQLResult.result.rows[i].AccountNumber.value, + AccountText: theSQLResult.result.rows[i].AccountText.value, + FinanceVATCode: theSQLResult.result.rows[i].FinanceVATCode.value, + FinanceVATCodeAllowed: theSQLResult.result.rows[i].FinanceVATCodeAllowed.value, + FinanceVATCodeRequired: theSQLResult.result.rows[i].FinanceVATCodeRequired.value, + ProfitAndLossStatus: getPopupDisplay("ProfitAndLossStatusType",theSQLResult.result.rows[i].ProfitAndLossStatus.value), + Currency: getPopupDisplay("CurrencyType",theSQLResult.result.rows[i].Currency.value), + LocationAllowed: theSQLResult.result.rows[i].LocationAllowed.value, + LocationRequired: theSQLResult.result.rows[i].LocationRequired.value, + EntityName: theSQLResult.result.rows[i].EntityName.value, + OverwriteEntity: theSQLResult.result.rows[i].OverwriteEntity.value, + EntityAllowed: theSQLResult.result.rows[i].EntityAllowed.value, + EntityRequired: theSQLResult.result.rows[i].EntityRequired.value, + Spec2Allowed: theSQLResult.result.rows[i].Spec2Allowed.value, + Spec2Required: theSQLResult.result.rows[i].Spec2Required.value, + EmployeeAllowed: theSQLResult.result.rows[i].EmployeeAllowed.value, + EmployeeRequired: theSQLResult.result.rows[i].EmployeeRequired.value, + Blocked: theSQLResult.result.rows[i].Blocked.value, + CompanyNumber: theSQLResult.result.rows[i].CompanyNumber.value, + VersionNumber: theSQLResult.result.rows[i].VersionNumber.value + }; + } else { + var faultName = "NoAccountsFound"; + var message = sprint("No Accounts found."); + soapAPI::generateSimpleFault(faultName, message); + }; + return accountList; + } +finally; + //logout(); +} + +public var getDepartmentsInfo = +{ + requireSchemaValidation: true, + requireUsernameToken: true, + // Here we specify the data type of each of the parameters to the function. + // In this case there is no input parameters + inputTypes: {CompanyNumber: "string"}, + + // Here we specify the output type of the function. In this case it is + // an array of project numbers as strings +outputType: + { + type: "array", + name: "departmentList", + elements: + { + type: "object", + elements: + { + LocationName: "string", + Description: "string", + Blocked: "int", + CompanyNumber: "string", + VersionNumber: "int" + } + } + }, + + // Documentation to be inserted as a "" tag in the operation + // description in the WSDL. + documentation: 'DOC' +This web service returns an array of Departments(Locations) in the Maconomy system for the selected company. +DOC +}; + + +public function getDepartments(CompanyNumber) +{ + // Use a try-finally statement to guarantee that no matter what happens, we + // always ensure the system is logged out after use. + try + { + //Login to the Maconomy server + //login(); + + // Fetch Location data using SQL and insert them in an array + var theSQLRequest=sprint("select LocationName, Description, Blocked, '^1' as CompanyNumber, VersionNumber from Location order by LocationName",CompanyNumber); + + var theSQLResult = maconomy::sql(theSQLRequest); + + var accountList = new [sizeof(theSQLResult.result.rows)]; + + if (sizeof(theSQLResult.result.rows)>0) + { + for (var i in theSQLResult.result.rows) + accountList[i] = { + LocationName: theSQLResult.result.rows[i].LocationName.value, + Description: theSQLResult.result.rows[i].Description.value, + Blocked: theSQLResult.result.rows[i].Blocked.value, + CompanyNumber: theSQLResult.result.rows[i].CompanyNumber.value, + VersionNumber: theSQLResult.result.rows[i].VersionNumber.value + }; + } else { + var faultName = "NoLocationsFound"; + var message = sprint("No Locations found."); + soapAPI::generateSimpleFault(faultName, message); + }; + return accountList; + } +finally; + //logout(); +} + +public var getCostCenterInfo = +{ + requireSchemaValidation: true, + requireUsernameToken: true, + // Here we specify the data type of each of the parameters to the function. + // In this case there is no input parameters + inputTypes: {CompanyNumber: "string"}, + + // Here we specify the output type of the function. In this case it is + // an array of project numbers as strings +outputType: + { + type: "array", + name: "CostCenterList", + elements: + { + type: "object", + elements: + { + CostCenterName: "string", + Description: "string", + Blocked: "int", + CompanyNumber: "string", + VersionNumber: "int" + } + } + }, + + // Documentation to be inserted as a "" tag in the operation + // description in the WSDL. + documentation: 'DOC' +This web service returns an array of Cost Center(Specification2) in the Maconomy system for the selected company. +DOC +}; + + +public function getCostCenter(CompanyNumber) +{ + // Use a try-finally statement to guarantee that no matter what happens, we + // always ensure the system is logged out after use. + try + { + //Login to the Maconomy server + //login(); + + // Fetch Location data using SQL and insert them in an array + var theSQLRequest=sprint("select Specification2Name as CostCenterName, Description, Blocked, '^1' as CompanyNumber, VersionNumber from Specification2 order by Specification2Name",CompanyNumber); + + var theSQLResult = maconomy::sql(theSQLRequest); + + var CostCenterList = new [sizeof(theSQLResult.result.rows)]; + + if (sizeof(theSQLResult.result.rows)>0) + { + for (var i in theSQLResult.result.rows) + CostCenterList[i] = { + CostCenterName: theSQLResult.result.rows[i].CostCenterName.value, + Description: theSQLResult.result.rows[i].Description.value, + Blocked: theSQLResult.result.rows[i].Blocked.value, + CompanyNumber: theSQLResult.result.rows[i].CompanyNumber.value, + VersionNumber: theSQLResult.result.rows[i].VersionNumber.value + }; + } else { + var faultName = "NoCostCenterFound"; + var message = sprint("No Cost Center found."); + soapAPI::generateSimpleFault(faultName, message); + }; + return CostCenterList; + } +finally; + //logout(); +} + +public var getProjectsInfo = +{ + requireSchemaValidation: true, + requireUsernameToken: true, + // Here we specify the data type of each of the parameters to the function. + // In this case there is no input parameters + inputTypes: {CompanyNumber: "string"}, + + // Here we specify the output type of the function. In this case it is + // an array of project numbers as strings +outputType: + { + type: "array", + name: "projectList", + elements: + { + type: "object", + elements: + { + ProjectNumber: "string", + ProjectName: "string", + CompanyNumber: "string", + TaskList: "string", + Blocked: "int", + VersionNumber: "int" + } + } + }, + + // Documentation to be inserted as a "" tag in the operation + // description in the WSDL. + documentation: 'DOC' +This web service returns an array of Projects(Jobs) in the Maconomy system for the selected company. +DOC +}; + + +public function getProjects(CompanyNumber) +{ + // Use a try-finally statement to guarantee that no matter what happens, we + // always ensure the system is logged out after use. + try + { + //Login to the Maconomy server + //login(); + + // Fetch Location data using SQL and insert them in an array + var theSQLRequest=sprint("select concat(concat(j.JobNumber,'-'),tll.linenumber) as ProjectNumber, concat(concat(j.JobName,'-'),tll.DESCRIPTION) as ProjectName, '^1' as CompanyNumber,j.TaskList,j.BLOCKEDFORAMOUNTREGISTRATION as Blocked, j.VersionNumber from JobHeader j, tasklistline tll where tll.tasklist=j.tasklist and tll.CANBEUSEDONEXPENSESHEETS=0 and j.template=0 and j.BLOCKEDFORAMOUNTREGISTRATION=0 and j.closed=0 and j.jobnumber<>'Internal Time' order by j.JobNumber",CompanyNumber); + + var theSQLResult = maconomy::sqlNative(theSQLRequest); + + var projectList = new [sizeof(theSQLResult.result.rows)]; + + if (sizeof(theSQLResult.result.rows)>0) + { + for (var i in theSQLResult.result.rows) + projectList[i] = { + ProjectNumber: theSQLResult.result.rows[i].ProjectNumber.value, + ProjectName: theSQLResult.result.rows[i].ProjectName.value, + CompanyNumber: theSQLResult.result.rows[i].CompanyNumber.value, +// TaskList: theSQLResult.result.rows[i].TaskList.value, + TaskList: "NORDUnet", + Blocked: theSQLResult.result.rows[i].Blocked.value, + VersionNumber: theSQLResult.result.rows[i].VersionNumber.value + }; + } else { + var faultName = "NoProjectsFound"; + var message = sprint("No Projects found."); + soapAPI::generateSimpleFault(faultName, message); + }; + return projectList; + } +finally; + //logout(); +} + + +public var getTaskListInfo = +{ + requireSchemaValidation: true, + requireUsernameToken: true, + // Here we specify the data type of each of the parameters to the function. + // In this case there is no input parameters +// inputTypes: {TaskListName: "string"}, + inputTypes: {}, + + // Here we specify the output type of the function. In this case it is + // an array of project numbers as strings +outputType: + { + type: "array", + name: "taskList", + elements: + { + type: "object", + elements: + { + TaskList: "string", + TaskName: "string", + Description: "string", + Blocked: "int", + VersionNumber: "int" + } + } + }, + + // Documentation to be inserted as a "" tag in the operation + // description in the WSDL. + documentation: 'DOC' +This web service returns an array of Tasks in the Maconomy system for the selected TaskList. +DOC +}; + + +public function getTaskList() +{ + // Use a try-finally statement to guarantee that no matter what happens, we + // always ensure the system is logged out after use. + try + { + //Login to the Maconomy server + //login(); + + // Fetch Location data using SQL and insert them in an array +// var theSQLRequest=sprint("select TL.TaskList, TL.TaskName, TL.Description, TL.Blocked, TH.VersionNumber from TaskListLine TL, TaskListHeader TH where TL.TaskList=TH.TaskList and TL.CanBeUsedOnExpenseSheets=1 and TL.TaskList='^1' order by TL.TaskList,TL.TaskName",TaskListName); + var theSQLRequest=sprint("select TL.TaskList, TL.TaskName, TL.Description, TL.Blocked, TH.VersionNumber from TaskListLine TL, TaskListHeader TH where TL.TaskList=TH.TaskList and TL.CanBeUsedOnExpenseSheets=1 and TL.TaskList='NORDUnet' order by TL.TaskList,TL.TaskName"); + + var theSQLResult = maconomy::sql(theSQLRequest); + + var taskList = new [sizeof(theSQLResult.result.rows)]; + + if (sizeof(theSQLResult.result.rows)>0) + { + for (var i in theSQLResult.result.rows) + taskList[i] = { + TaskList: theSQLResult.result.rows[i].TaskList.value, + TaskName: theSQLResult.result.rows[i].TaskName.value, + Description: theSQLResult.result.rows[i].Description.value, + Blocked: theSQLResult.result.rows[i].Blocked.value, + VersionNumber: theSQLResult.result.rows[i].VersionNumber.value + }; + } else { + var faultName = "NoTaskListsFound"; + var message = sprint("No TaskLists found."); + soapAPI::generateSimpleFault(faultName, message); + }; + return taskList; + } +finally; + //logout(); +} + + +public var getVATCodesInfo = +{ + requireSchemaValidation: true, + requireUsernameToken: true, + // Here we specify the data type of each of the parameters to the function. + // In this case there is no input parameters + inputTypes: {}, + + // Here we specify the output type of the function. In this case it is + // an array of project numbers as strings +outputType: + { + type: "array", + name: "VATCodeList", + elements: + { + type: "object", + elements: + { + Name: "string", + VATRate: "string", + RatioNumber: "string", + VersionNumber: "int" + } + } + }, + + // Documentation to be inserted as a "" tag in the operation + // description in the WSDL. + documentation: 'DOC' +This web service returns an array of VAT Codes in the Maconomy system (only ingoing VAT rates). + +DOC +}; + + +public function getVATCodes() +{ + // Use a try-finally statement to guarantee that no matter what happens, we + // always ensure the system is logged out after use. + try + { + //Login to the Maconomy server + //login(); + + // Fetch Location data using SQL and insert them in an array + var theSQLRequest="select Name, VATRate, RatioNumber, VersionNumber from FinanceVATCode where vatdirection=0"; + + var theSQLResult = maconomy::sql(theSQLRequest); + + var VATCodeList = new [sizeof(theSQLResult.result.rows)]; + + if (sizeof(theSQLResult.result.rows)>0) + { + for (var i in theSQLResult.result.rows) + VATCodeList[i] = { + Name: theSQLResult.result.rows[i].Name.value, + VATRate: theSQLResult.result.rows[i].VATRate.value, + RatioNumber: theSQLResult.result.rows[i].RatioNumber.value, + VersionNumber: theSQLResult.result.rows[i].VersionNumber.value + }; + } else { + var faultName = "NoVATCodesFound"; + var message = sprint("No VAT Codes found."); + soapAPI::generateSimpleFault(faultName, message); + }; + return VATCodeList; + } +finally; + //logout(); +} + + +public var iteImportExpenceInfo = +{ + requireSchemaValidation: true, + requireUsernameToken: true, + // Here we specify the data type of each of the parameters to the function. + // In this case there is no input parameters + inputTypes: + { + iteInput: + { + type: "object", + name: "Header", + elements: + { + IbisticVoucherNo: "string", + EmployeeNumber: "string", + Department: "string", + EntryDate: "date", + CompanyNumber: "string", + Description: "string", + IbisticDocumentLookupURL: "string", + Lines: + { + type: "array", + name: "Details", + elements: + { + type: "object", + name: "LineDetails", + elements: + { + IbisticLineID: "string", + TransType: "string", + LineDescription: "string", + CreditCardDescription: "string", + OriginalCurrency: "string", + OriginalAmount: "amount", + Currency: "string", + Amount: "amount", + VATCode: "string", + VATAmount: "amount", + Project: "string", + Task: "string", + MilageDistanceinKM: "real", + DietAmount: "amount" + } + } + } + } + } + }, + + // Here we specify the output type of the function. In this case it is + // an array of project numbers as strings +outputType: + { + type: "object", + name: "iteOutput", + elements: + { + StatusCode: "string" + ,Messages: "string" + } + }, + + // Documentation to be inserted as a "" tag in the operation + // description in the WSDL. + documentation: 'DOC' +This web service handle input to Maconomy from ibistic. + +header: +IbisticVoucherNo: Ibistic internal number (Used as External Transaction Number in Maconomy) +EmployeeNumber: The EmployeeNumber from getEmployees +Department: The LocationName from getEmployees +EntryDate: The date of the transfer to Maconomy (eg. import date) +CompanyNumber: "1" for Denmark, "40" for Sweden. +Description: user input description in the expencesheet header +TransType: "Cash", "Company Card", "Private Outlay", "Diet","Milage" +CompanyNumber: "1" for Denmark, "40" for Sweden. +IbisticDocumentLookupURL: A url pointing to the expencesheet +line: +IbisticLineID Ibistic internal line number on the expencesheet +LineDescription: The description entered by user on the line of the expence eg. "Hotel" +CreditCardDescription: The text string from the creditcard transaction +OriginalCurrency: Original Currency, the currency of the transaction, always local currency for Diets, Milage +OriginalAmount: do. just the amount eg. 1000,00 +Currency: The company currency, Denmark/Company 1=DKK and Sweden/Company 40=SEK +Amount: The amount in the currency above +VATCode: From the VAT codes export +VATAmount: Calculated VAT amount (Local Currency) +Project: Project Number from export (getProjects) +Task: Task related from (getTasksList(projectNo)) +MilageDistanceinKM: No of kilometers, only for TransType="Milage" otherwise 0.00 +DietAmount Line Amount for Diet, only when TransType="Diet" otherwise 0.00 + +DOC +}; + + +public function iteImportExpence(iteInput) +{ + // Use a try-finally statement to guarantee that no matter what happens, we + // always ensure the system is logged out after use. + format::set({ Date:"E.YYYYMMDD"}); + format::set({ Real:"E.,.1"}); + format::set({ Amount:"E.,"}); + + Log(logfilename, sprint("^1T^2\titeImport started with data:\n^3\n",getdate(),gettime(),Object2String(iteInput))); + var iteOutput = {StatusCode: "OK" + ,Messages: ""}; + var theEntryDate = getdate(); + session var xx; + var newGLJournal = { CompanyNumber : {value: iteInput.CompanyNumber} + //,TransactionNumberSeries: {value: getPopupValue("TransactionNumberSeriesType","General Ledger")} + ,AutomaticVoucherVar : {value: false} + }; + + var journalNumber2Use=0; + var keyFindGLJournal = maconomy::sql(sprint("select JournalNumber, nameofuser,period, periodend, companynumber from journal where Posted=0 and CompanyNumber='^1' and nameofuser='^2' and ((Period<='^3' and PeriodEnd>='^3') or (Period=' ' and PeriodEnd=' '))",newGLJournal.CompanyNumber.value,"ibistic",theEntryDate)); + var index=sizeof(keyFindGLJournal.result.rows); + iteInput.IbisticVoucherNo = int(iteInput.IbisticVoucherNo); //+6000000; + + if (index==0) + { + journalNumber2Use=createNewJournal(newGLJournal); + } else { + journalNumber2Use=keyFindGLJournal.result.rows[0].journalnumber.value; + } + + try + { + var dialogID = maconomy::dialogOpen("GeneralJournal"); + var dialogReturn; + + var journalKey = {JournalNumber: {value:journalNumber2Use}}; + dialogReturn = maconomy::dialogGet(dialogID,journalKey); + for (var i in iteInput.Lines) + { + + + + var recordsToPost1 = {EntryDate : {value: theEntryDate} + ,ExternalTransactionNumber : {value: iteInput.IbisticDocumentLookupURL} + ,TransactionNumber : {value: iteInput.IbisticVoucherNo} + ,ReferenceDate : {value: iteInput.EntryDate} + ,EntryText : {value: iteInput.Lines[i].LineDescription} +// ,EntryText : {value: sprint("^1 : ^2",iteInput.Lines[i].LineDescription,iteInput.Lines[i].CreditCardDescription)} + }; + + var recordsToPost2 = {EntryDate : {value: theEntryDate} + ,ExternalTransactionNumber : {value: iteInput.IbisticDocumentLookupURL} + ,TransactionNumber : {value: iteInput.IbisticVoucherNo} + ,ReferenceDate : {value: iteInput.EntryDate} + ,EntryText : {value: iteInput.Lines[i].LineDescription} +// ,EntryText : {value: sprint("^1 : ^2",iteInput.Lines[i].LineDescription,iteInput.Lines[i].CreditCardDescription)} + // ,FinanceVATCode : {value: iteInput.Lines[i].VATCode} + }; + + + + if (iteInput.Lines[i].Amount < 0.00A) + { + recordsToPost1 += {CreditBase: iteInput.Lines[i].Amount}; + } else { + recordsToPost1 += {DebitBase: iteInput.Lines[i].Amount}; + } + + recordsToPost1 += {Currency: {value: getPopupValue("CurrencyType",iteInput.Lines[i].OriginalCurrency)}}; + recordsToPost1 += {AmountCurrency: iteInput.Lines[i].OriginalAmount}; + if (iteInput.Lines[i].VATCode!="-") + { + recordsToPost1 += {FinanceVATCode : {value: iteInput.Lines[i].VATCode} + ,VAT1Currency : {value: amount(iteInput.Lines[i].VATAmount)} + }; + + } else { + iteInput.Lines[i].VATCode=""; + } + + + + if (sizeof(iteInput.Lines[i].Project)>0) //remove / from project/task + { + var myprojectno =strpos(iteInput.Lines[i].Project,0,"-")-1; + iteInput.Lines[i].Project = iteInput.Lines[i].Project[..myprojectno]; + } + + + switch (iteInput.Lines[i].TransType) + { + case "1xxxx": //Credit Card + { + var GRPType1=maconomy::popup("GRPType",0); //G + var GRPType2=maconomy::popup("GRPType",2); //P + + recordsToPost1 += {TaskName : {value: iteInput.Lines[i].Task} + ,JobNumber : {value :iteInput.Lines[i].Project} + ,EmployeeNumber : {value:iteInput.EmployeeNumber} + ,TypeOfEntry : {value: GRPType1} + }; + + recordsToPost2 += { TypeOfEntry : {value: GRPType2} + ,AccountNumber : {value: iteInput.EmployeeNumber} + }; + recordsToPost2.EntryText= {value:sprint("Ibistic1:^1 - ^2/^3",iteInput.IbisticVoucherNo,iteInput.Lines[i].Task,iteInput.Lines[i].Project)}; + + Log(logfilename,sprint("1=^1\n2=^2\n",Object2String(recordsToPost1),Object2String(recordsToPost2))); + + dialogReturn = maconomy::dialogNewLower(dialogID,-1); + dialogReturn = maconomy::dialogPutLower(dialogID, recordsToPost1); + + dialogReturn = maconomy::dialogNewLower(dialogID, -1); + dialogReturn = maconomy::dialogPutLower(dialogID, recordsToPost2); + + break; + } + case "2": //Company Cash + { + var GRPType1=maconomy::popup("GRPType",1); //R + var GRPType2=maconomy::popup("GRPType",2); //P + + recordsToPost1 += { TypeOfEntry : {value: GRPType1} + ,AccountNumber : {value: iteInput.EmployeeNumber} + + }; + + recordsToPost2 += { TypeOfEntry : {value: GRPType2} + ,AccountNumber : {value: iteInput.EmployeeNumber} + }; + + recordsToPost1.EntryText= {value:sprint("Ibistic:^1 - Cash Withdrawal",iteInput.IbisticVoucherNo)}; + recordsToPost2.EntryText= {value:sprint("Ibistic:^1 - ^2",iteInput.IbisticVoucherNo,iteInput.Lines[i].CreditCardDescription)}; + + Log(logfilename,sprint("Ibistic2:1=^1\n2=^2\n",Object2String(recordsToPost1),Object2String(recordsToPost2))); + + dialogReturn = maconomy::dialogNewLower(dialogID,-1); + dialogReturn = maconomy::dialogPutLower(dialogID, recordsToPost1); + + dialogReturn = maconomy::dialogNewLower(dialogID, -1); + dialogReturn = maconomy::dialogPutLower(dialogID, recordsToPost2); + + break; + } + case "3": //Private outlay + { + var GRPType1=maconomy::popup("GRPType",0); //G + var GRPType2=maconomy::popup("GRPType",1); //R + + recordsToPost1 += {TaskName : {value: iteInput.Lines[i].Task} + ,JobNumber : {value :iteInput.Lines[i].Project} + ,EmployeeNumber : {value:iteInput.EmployeeNumber} + ,TypeOfEntry : {value: GRPType1} + }; + + recordsToPost2 += { TypeOfEntry : {value: GRPType2} + ,AccountNumber : {value: iteInput.EmployeeNumber} + }; + + recordsToPost2.EntryText= {value:sprint("Ibistic:^1 - Outlay ^2/^3",iteInput.IbisticVoucherNo,iteInput.Lines[i].Task,iteInput.Lines[i].Project)}; + + Log(logfilename,sprint("1=^1\n2=^2\n",Object2String(recordsToPost1),Object2String(recordsToPost2))); + + dialogReturn = maconomy::dialogNewLower(dialogID,-1); + dialogReturn = maconomy::dialogPutLower(dialogID, recordsToPost1); + + dialogReturn = maconomy::dialogNewLower(dialogID, -1); + dialogReturn = maconomy::dialogPutLower(dialogID, recordsToPost2); + + break; + + + } + case "4": //Handelsbanken + { + var GRPType1=maconomy::popup("GRPType",0); //G + var GRPType2=maconomy::popup("GRPType",2); //P + + recordsToPost1 += {TaskName : {value: iteInput.Lines[i].Task} + ,JobNumber : {value :iteInput.Lines[i].Project} + ,EmployeeNumber : {value:iteInput.EmployeeNumber} + ,TypeOfEntry : {value: GRPType1} + }; + + recordsToPost2 += { TypeOfEntry : {value: GRPType2} + ,AccountNumber : {value: iteInput.EmployeeNumber} + }; + recordsToPost2.EntryText= {value:sprint("Ibistic:^1 - ^2/^3",iteInput.IbisticVoucherNo,iteInput.Lines[i].Task,iteInput.Lines[i].Project)}; + + Log(logfilename,sprint("1=^1\n2=^2\n",Object2String(recordsToPost1),Object2String(recordsToPost2))); + + dialogReturn = maconomy::dialogNewLower(dialogID,-1); + dialogReturn = maconomy::dialogPutLower(dialogID, recordsToPost1); + + dialogReturn = maconomy::dialogNewLower(dialogID, -1); + dialogReturn = maconomy::dialogPutLower(dialogID, recordsToPost2); + + break; + } + case "5": //Mileage + { + var GRPType1=maconomy::popup("GRPType",0); //G + var GRPType2=maconomy::popup("GRPType",1); //P + + recordsToPost1 += { TaskName : {value: iteInput.Lines[i].Task} + ,JobNumber : {value :iteInput.Lines[i].Project} + ,EmployeeNumber : {value:iteInput.EmployeeNumber} + ,TypeOfEntry : {value: GRPType1} + //,AccountNumber : {value: "5040"} + //,Quantity : {value: real(iteInput.Lines[i].MilageDistanceinKM)} + }; + + + recordsToPost2 += { TypeOfEntry : {value: GRPType2} + ,AccountNumber : {value: iteInput.EmployeeNumber} + ,EntryText : {value: sprint("Ibistic:^1 - Mileage",iteInput.IbisticVoucherNo)} + //,Quantity : {value: real(iteInput.Lines[i].MilageDistanceinKM)} + }; + + + Log(logfilename,sprint("Ibistic5:1=^1\n2=^2\n",Object2String(recordsToPost1),Object2String(recordsToPost2))); + + dialogReturn = maconomy::dialogNewLower(dialogID,-1); + dialogReturn = maconomy::dialogPutLower(dialogID, recordsToPost1); + + dialogReturn = maconomy::dialogNewLower(dialogID, -1); + dialogReturn = maconomy::dialogPutLower(dialogID, recordsToPost2); + + break; + } + case "6": //Diet + { + var GRPType1=maconomy::popup("GRPType",0); //G + var GRPType2=maconomy::popup("GRPType",1); //P + + if (def(recordsToPost1.CreditBase)) + { + delete recordsToPost1.CreditBase; + } + if (def(recordsToPost1.DebitBase)) + { + delete recordsToPost1.DebitBase; + } + + if (iteInput.Lines[i].DietAmount < 0.00A) + { + recordsToPost1 += {CreditBase: iteInput.Lines[i].Amount}; + } else { + recordsToPost1 += {DebitBase: iteInput.Lines[i].Amount}; + } + + recordsToPost1 += { TaskName : {value: iteInput.Lines[i].Task} + ,JobNumber : {value :iteInput.Lines[i].Project} + ,EmployeeNumber : {value:iteInput.EmployeeNumber} + ,TypeOfEntry : {value: GRPType1} + //,AccountNumber : {value: "5030"} + }; + + + recordsToPost2 += { TypeOfEntry : {value: GRPType2} + ,AccountNumber : {value: iteInput.EmployeeNumber} + }; + recordsToPost2.EntryText= {value:sprint("Ibistic:^1 - Travel allowance",iteInput.IbisticVoucherNo)}; + + Log(logfilename,sprint("1=^1\n2=^2\n",Object2String(recordsToPost1),Object2String(recordsToPost2))); + + dialogReturn = maconomy::dialogNewLower(dialogID,-1); + dialogReturn = maconomy::dialogPutLower(dialogID, recordsToPost1); + + dialogReturn = maconomy::dialogNewLower(dialogID, -1); + dialogReturn = maconomy::dialogPutLower(dialogID, recordsToPost2); + + break; + } + + } //end switch + + + Log(logfilename, sprint("^1T^2\Posting this record: - ^3\n^4:\n",getdate(),gettime(),Object2String(recordsToPost1),Object2String(recordsToPost2))); + + }; //end for loop + maconomy::commit(); + maconomy::dialogClose(dialogID); + return iteOutput; + + } //try + + catch createJournalError(e) + { + maconomy::rollback(); + Log( logfilename, sprint("\n***Error in iteImport(createJournalError): ^1\n",Object2String(e)) ); + } + + catch error::stdlib::maconomy::dialog::ApplicationError(e) + { + var message = e.value.status.error.text; + Log( logfilename, sprint("\n***Error in iteImport z dialog: ^1\n",Object2String(e)) ); + maconomy::rollback(); + iteOutput = {StatusCode: "Fault" + ,Messages: message}; + } + catch (e) + { + var message = def(e.value)&&def(e.value.message) ? e.value.message : ""; + Log( logfilename, sprint("\n***Error in iteImport y: ^1\n",Object2String(e)) ); + maconomy::rollback(); + iteOutput = {StatusCode: "Fault" + ,Messages: message}; + } + + catch error::stdlib::maconomy(e) + { + var message = def(e.value)&&def(e.value.message) ? e.value.message : ""; + Log( logfilename, sprint("\n***Error in iteImport: ^1\n",Object2String(message)) ); + maconomy::rollback(); + iteOutput = {StatusCode: "Fault" + ,Messages: message}; + } + catch error::stdlib::maconomy::dialog(e) + { + var message = e.value.status.error.text; + Log( logfilename, sprint("\n***Error in iteImport dialog: ^1\n",Object2String(e)) ); + maconomy::rollback(); + iteOutput = {StatusCode: "Fault" + ,Messages: message}; } + + + finally + { + //maconomy::rollback(); + //maconomy::dialogClose(dialogID); + return iteOutput; + } +} + + + + +function createNewJournal(journalKey) +{ + var journalNumber=0; + var dialogIDX = maconomy::dialogOpen("GeneralJournal"); + var dialogReturn = maconomy::dialogNewAndPutUpper(dialogIDX,journalKey); + maconomy::dialogClose(dialogIDX); + maconomy::commit(); + if (dialogReturn.status.ok) + { + journalNumber=dialogReturn.dialogData.upperPane.rows[0].JournalNumber.value; + } else { + //dialogReturn.messages + throw createJournalError(sprint("^1",Object2String(dialogReturn.messages))); + } + Log(logfilename,sprint("JournalNumber created:^1\n",journalNumber)); + return journalNumber; +} + + +/*============================================================================ + Internal helpers +============================================================================*/ + +procedure login() +{ + newsession(); +} + +procedure logout() +{ + //deletesession(); + true; +} + +function getPopupValue(popupName,popupvalue) + +{ + + var nameArr = maconomy::popupTitles(popupName); + var thepopupType = maconomy::popup(popupName,null); + var index = null; + + for (var i in nameArr) + { + if (nameArr[i]==popupvalue) + { + index = i; + } + } + + if (index==null) + { + return thepopupType=maconomy::popupNull(popupName); + } else { + return thepopupType=maconomy::popup(popupName,index); + } +} + +function getPopupDisplay(popupTypeName,popupOrdValue) + +{ + var theDisplayTitle = maconomy::popupTitle(popupTypeName,popupOrdValue); + return theDisplayTitle; +} + +procedure Log( filename, str ) +{ + var f = file::open( filename, "a" ); + file::print( f, str ); + file::close( f ); +} +/*****************************************************************************************************/ + +function Object2String(obj) +{ + var deviceInfoStream = io::ostring(); + file::dumpvalue(deviceInfoStream, obj,{noWhitespace:false}); + return io::getstring(deviceInfoStream); +} -- cgit v1.1