Context & Session
Current company, year, branch, user identity and environment.
39 functions. All require apis/main_webservices.php to be included.
On this page: addrHomeFolder · branchAddress · branchContacts · companyAddress · companyBrcode · companyContacts · companyEmail · companyMobile · companyName · companyRegNos · country · currency · finBeg · finEnd · finYear · getAccessToken · getBranchCode · getBranchID · getBranchName · getCompanyGstin · getCompanyID · getLocationFromIP · getUsdRate · getYearCompIDCurrentDate · getYearID · get_client_ip · homeFolder · isBranchHO · isMobileDevice · isProduction · nextCompID · nextYearComp_Info · nextYearID · othMobile · prevCompID · prevYearID · rootPath · userName · whoAmI
addrHomeFolder()
Prototype
addrHomeFolder()
Description
- Returns the URL/path prefix to the project home folder, ready to prepend to a page name.
- Use to build links back into the project (e.g. report 'Go Back' buttons).
Parameters
- none
Returns
- String — full address to the home folder, with trailing slash.
Return example
$back = addrHomeFolder().'oldprogram.php';
// e.g. '/shreeart/oldprogram.php'
Usage example
addrHomeFolder() --> 'https://www.domain.com/cipl';
:material-file-code: Source: apis/core2_a.php
branchAddress()
Prototype
BranchAddress()
Description
- Returns the postal address of the current branch.
- Used on invoices, challans and letterheads to print the issuing branch address.
Parameters
- none
Returns
- String — the branch's full address block.
Return example
$addr = branchAddress();
// e.g. 'Plot 21, GIDC, Surat, Gujarat 395003'
:material-file-code: Source: apis/core2_a.php
branchContacts()
Prototype
BranchContacts()
Description
- Returns the contact details (phone/email) registered for the current branch.
- Printed alongside the branch address on outward documents.
Parameters
- none
Returns
- String — branch contact information.
Return example
$c = branchContacts();
// e.g. 'Ph: 0261-2345678, info@shreeart.com'
:material-file-code: Source: apis/core2_a.php
companyAddress()
Prototype
CompanyAddress()
Description
- Returns the registered address of the active company (head-office level).
- Use for statutory documents where the company (not branch) address is required.
Parameters
- none
Returns
- String — the company's address block.
Return example
$addr = companyAddress();
// e.g. 'Ring Road, Surat, Gujarat'
:material-file-code: Source: apis/core2_a.php
companyBrcode()
Prototype
CompanyBrcode()
Description
- Returns the branch code of the active company/branch context.
- Branch code distinguishes multiple branches operating under one company.
Parameters
- none
Returns
- String — the current branch code.
Return example
$br = companyBrcode();
// e.g. 'HO' or 'SRT01'
:material-file-code: Source: apis/core2_a.php
companyContacts()
Prototype
CompanyContacts()
Description
- Returns the combined contact information of the active company.
- Handy for a single-string contact line in print headers.
Parameters
- none
Returns
- String — company phone/email contact text.
Return example
$c = companyContacts();
// e.g. 'Ph 0261-... | accounts@company.com'
:material-file-code: Source: apis/core2_a.php
companyEmail()
Prototype
CompanyEmail()
Description
- Returns the registered email address of the active company.
- Used as the from/reply address for company-originated mails.
Parameters
- none
Returns
- String — the company email address.
Return example
$em = companyEmail();
// e.g. 'accounts@shreeart.com'
:material-file-code: Source: apis/core2_a.php
companyMobile()
Prototype
CompanyMobile()
Description
- Returns the primary mobile number registered for the active company.
- Often used as the sender identity for transactional SMS.
Parameters
- none
Returns
- String — the company mobile number.
Return example
$mob = companyMobile();
// e.g. '9825099999'
:material-file-code: Source: apis/core2_a.php
companyName()
Prototype
CompanyName()
Description
- Returns the registered name of the currently selected company.
- Commonly used in report headers, print layouts and email signatures.
Parameters
- none
Returns
- String — the active company's name.
Return example
$name = companyName();
// e.g. 'Shree Art Silk Mills Pvt Ltd'
:material-file-code: Source: apis/core2_a.php
companyRegNos()
Prototype
CompanyContacts()
Description
- Returns the company's statutory registration numbers — GSTIN, PAN and TDS/TAN.
- Required on tax invoices and compliance documents.
Parameters
- none
Returns
- String — concatenated GST, PAN and TDS numbers of the company.
Return example
$regs = companyRegNos();
// e.g. 'GSTIN 24ABCDE1234F1Z5 | PAN ABCDE1234F'
:material-file-code: Source: apis/core2_a.php
country()
Prototype
country($ddl=true)
Description
- Returns the master list of countries with their ISO short codes.
- Pass
$ddl=truefor a ready-to-bind dropdown source, orfalsefor the raw associative array.
Parameters
$ddl— True (default)
Returns
- Array (or JSON string when
$ddlis true) of country name → short code pairs.
Return example
$list = country(false);
// ['India'=>'IN', 'United Arab Emirates'=>'AE', ...]
Usage example
$countries = country(false);
:material-file-code: Source: apis/core2_a.php
currency()
Prototype
currency()
Description
- Returns the list of supported standard currencies.
- Use to populate currency selectors in masters and transactions.
Parameters
- none
Returns
- String/array — supported currency codes.
Return example
$cur = currency();
// e.g. 'INR|USD|AED|EUR'
Usage example
$currencies = currency();
:material-file-code: Source: apis/core2_a.php
finBeg()
Prototype
FinBeg()
Description
- Returns the start date of the current financial year.
- Use as the default 'from' date for period filters and opening computations.
Parameters
- none
Returns
- Date string — first day of the financial year.
Return example
$from = finBeg();
// e.g. '2024-04-01'
Usage example
$stdt = FinBeg();
:material-file-code: Source: apis/core2_a.php
finEnd()
Prototype
FinEnd()
Description
- Returns the end date of the current financial year.
- Use as the default 'to' date for period filters and closing computations.
Parameters
- none
Returns
- Date string — last day of the financial year.
Return example
$to = finEnd();
// e.g. '2025-03-31'
Usage example
$enddt = FinEnd();
:material-file-code: Source: apis/core2_a.php
finYear()
Prototype
FinYear()
Description
- Returns the financial year label spanning start and end years.
- Good for display in headers (e.g. 'F.Y. 2024-2025').
Parameters
- none
Returns
- String — financial year in
YYYY-YYYYform.
Return example
$fy = finYear();
// e.g. '2024-2025'
Usage example
$finyr = FinYear();
:material-file-code: Source: apis/core2_a.php
getAccessToken()
Prototype
GetAccessToken()
Description
- Returns the API access token issued to the current project.
- Required when calling Merciglobal web-service/API endpoints on behalf of this project.
Parameters
- none
Returns
- String — the project's access token.
Return example
$tok = getAccessToken();
// e.g. 'a1b2c3d4e5...'
:material-file-code: Source: apis/core2_a.php
getBranchCode()
Prototype
getBranchCode()
Description
- Returns the code of the current branch (short alphanumeric identifier).
- Lighter alternative to the branch id for display and document pref.ixes.
Parameters
- none
Returns
- String — the current branch code.
Return example
$code = getBranchCode();
// e.g. 'SRT01'
:material-file-code: Source: apis/core2_a.php
getBranchID()
Prototype
GetBranchID()
Description
- Returns the numeric id of the current branch.
- Use to filter branch-scoped data or stamp the branch on new entries.
Parameters
- none
Returns
- Integer/string — the current branch id.
Return example
$bid = getBranchID();
// e.g. 2
:material-file-code: Source: apis/core2_a.php
getBranchName()
Prototype
getBranchName()
Description
- Returns the descriptive name of the current branch.
- Used in branch selectors and report sub-headers.
Parameters
- none
Returns
- String — the current branch name.
Return example
$bn = getBranchName();
// e.g. 'Surat Main'
:material-file-code: Source: apis/core2_a.php
getCompanyGstin()
Prototype
getCompanyGstin()
Description
- Returns the GSTIN of the active company.
- Central to all GST computations and e-invoice/e-way generation.
Parameters
- none
Returns
- String — the 15-character GST number of the company.
Return example
$gst = getCompanyGstin();
// e.g. '24ABCDE1234F1Z5'
:material-file-code: Source: apis/core2_a.php
getCompanyID()
Prototype
GetCompanyID()
Description
- Returns the company id currently selected in the session.
- Combined with the year id it scopes nearly every transaction query; inject via
#compid#orstdCond().
Parameters
- none
Returns
- Integer — the active company id.
Return example
$co = getCompanyID();
// e.g. 1
// or inside SQL: WHERE compid = #compid#
:material-file-code: Source: apis/core2_a.php
getLocationFromIP()
Prototype
getLocationFromIP()
Description
- Resolves an approximate physical location for the client's IP address.
- Useful for login geo-tagging and fraud signals.
Returns
- String/array — the resolved city/region/country for the IP.
Return example
$loc = getLocationFromIP();
// e.g. 'Surat, Gujarat, IN'
Usage example
$address = getLocationFromIP();
:material-file-code: Source: apis/core2_a.php
getUsdRate()
Prototype
getUsdRate($currency='INR')
Description
- Returns the USD conversion rate for a given currency, as captured at midnight.
- Use for multi-currency valuation and reporting in a common base.
Parameters
- <$currency>: Valid currency Short Code to check against USD (as per midnight rates from Exchange Rates Computation at midninght)
Returns
- Number — the USD rate for the requested currency code.
Return example
$rate = getUsdRate('INR');
// e.g. 0.012 (1 INR in USD)
Usage example
$usdrate = getUsdRate($currency='INR');
:material-file-code: Source: apis/core2_a.php
getYearCompIDCurrentDate()
Prototype
getYearCompIDCurrentDate()
Description
- Resolves the correct year id and company id for the current calendar date, rather than the session selection.
- Use when posting dated entries that must land in the financial year that owns today's date.
Parameters
- none
Returns
- Object/array exposing
yearidandcompidfor today's date.
Return example
$yc = getYearCompIDCurrentDate();
// $yc->yearid = 3, $yc->compid = 1
:material-file-code: Source: apis/core2_a.php
getYearID()
Prototype
GetYearID()
Description
- Returns the financial-year id currently selected in the session.
- Most transactional tables are partitioned by year+company; pass this into queries via
#yearid#orstdCond().
Parameters
- none
Returns
- Integer — the active year id (e.g. 1 for the first configured year).
Return example
$yr = getYearID();
// e.g. 3
// or inside SQL: WHERE yearid = #yearid#
:material-file-code: Source: apis/core2_a.php
get_client_ip()
Prototype
get_client_ip()
Description
- Returns the public IP address of the client making the request.
- Used for audit trails, geo-lookups and access restrictions.
Parameters
- none
Returns
- String — the client's IP address.
Return example
$ip = get_client_ip();
// e.g. '203.0.113.45'
Usage example
$ipAddr = get_client_ip();
:material-file-code: Source: apis/core2_a.php
homeFolder()
Prototype
HomeFolder()
Description
- Returns the home folder (project keycode) of the active project.
- This is the per-tenant folder under which the project runs.
Parameters
- none
Returns
- String — the project home folder name.
Return example
$hf = homeFolder();
// e.g. 'shreeart'
Usage example
HomeFolder() --> 'cipl'
:material-file-code: Source: apis/core2_a.php
isBranchHO()
Prototype
isBranchHO()
Description
- Tells whether the current branch is the Head Office (HO).
- Some consolidated reports/permissions are only valid at HO level.
Parameters
- none
Returns
- Boolean —
truewhen the active branch is HO, elsefalse.
Return example
if (isBranchHO()) {
// show consolidated all-branch figures
}
// returns: true | false
:material-file-code: Source: apis/core2_a.php
isMobileDevice()
Prototype
isMobileDevice()
Description
- Detects whether the request originates from a mobile device (via user-agent).
- Branch between card/mobile and table/desktop layouts.
Parameters
- none
Returns
- Boolean —
truefor mobile user-agents, elsefalse.
Return example
if (isMobileDevice()) {
// render card layout
}
// returns: true | false
Usage example
$device = isMobileDevice();
:material-file-code: Source: apis/core2_a.php
isProduction()
Prototype
isProduction()
Description
- Detects whether the code is executing on the live production (devx) server or on a test/lite environment.
- Use it to guard environment-specific behaviour — e.g. only send real SMS/emails or hit live payment gateways when on production.
- Decision is based on the server path/host the request is running under.
Returns
- Boolean —
truewhen running on the production server,falseon lite/test servers.
Return example
if (isProduction()) {
// safe to send live SMS / charge gateway
} else {
// sandbox behaviour
}
// returns: true | false
Usage example
if (isProduction()){
...
}
:material-file-code: Source: apis/core2_a.php
nextCompID()
Prototype
NextCompID()
Description
- Returns the company id for the next period mapped to the current company.
- Companion to
nextYearID()for forward carry-forward.
Parameters
- none
Returns
- Integer/string — next company id.
Return example
$nc = nextCompID();
// e.g. 1
:material-file-code: Source: apis/core2_a.php
nextYearComp_Info()
Prototype
NextYearComp_Info()
Description
- Returns combined next-year company information as a single structure.
- Convenience wrapper to fetch the forward year+company context in one call.
Parameters
- none
Returns
- Array — next-year company details (ids and related metadata).
Return example
$info = nextYearComp_Info();
// ['yearid'=>4, 'compid'=>1, ...]
Usage example
$logo = logoFile();
:material-file-code: Source: apis/core2_a.php
nextYearID()
Prototype
NextYearID()
Description
- Returns the financial-year id immediately after the current one.
- Used when rolling balances forward into the next year.
Parameters
- none
Returns
- Integer/string — next year id (blank/0 if not yet created).
Return example
$ny = nextYearID();
// e.g. 4
:material-file-code: Source: apis/core2_a.php
othMobile()
Prototype
othMobile()
Description
- Returns the mobile number of the currently logged-in customer/extranet user (the 'other' party, not a staff user).
- Useful in customer-facing portals to pre-fill or validate the contact number.
Parameters
- none
Returns
- String — the customer's mobile number, or blank when not an extranet/customer session.
Return example
$mob = othMobile();
// e.g. '9825012345'
:material-file-code: Source: apis/core2_a.php
prevCompID()
Prototype
PrevCompID()
Description
- Returns the company id of the previous period mapped to the current company.
- Supports company migrations/renumbering across years.
Parameters
- none
Returns
- Integer/string — previous company id.
Return example
$pc = prevCompID();
// e.g. 1
:material-file-code: Source: apis/core2_a.php
prevYearID()
Prototype
PrevYearID()
Description
- Returns the financial-year id immediately before the current one for this company.
- Use for opening-balance carry-forward and year-on-year comparisons.
Parameters
- none
Returns
- Integer/string — previous year id (blank/0 if none exists).
Return example
$py = prevYearID();
// e.g. 2
:material-file-code: Source: apis/core2_a.php
rootPath()
Prototype
rootPath()
Description
- Returns the absolute filesystem path of the current project's domain root on the server.
- Use it to build absolute include/file paths instead of fragile relative
../paths.
Returns
- String — the server document root for the active domain, with trailing slash.
Return example
$base = rootPath();
// e.g. '/var/www/vhosts/mercicloud2.com/httpdocs/'
require_once $base.'apis/main_webservices.php';
Usage example
$path = rootPath()
:material-file-code: Source: apis/core2_a.php
userName()
Prototype
userName()
Description
- Returns the login name of the current user.
- Use for display, audit messages and log stamping.
Returns
- String — the current user's login name.
Return example
$u = userName();
// e.g. 'rajesh'
Usage example
$user = userName();
:material-file-code: Source: apis/core2_a.php
whoAmI()
Prototype
WhoAmI()
Description
- Returns the numeric user id of the currently logged-in user.
- This is the primary id used for ownership, rights checks and audit stamping across the ERP.
Parameters
- none
Returns
- Integer — the logged-in user's id from the
userstable (0 if not logged in).
Return example
$uid = whoAmI();
// e.g. 42
$res = myExecute("SELECT * FROM #tasks# WHERE assignedto = $uid");
:material-file-code: Source: apis/core2_a.php