<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[FrontAccounting forum — Cron Job Module]]></title>
		<link>https://frontaccounting.com/punbb/viewtopic.php?id=6536</link>
		<atom:link href="https://frontaccounting.com/punbb/extern.php?action=feed&amp;tid=6536&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Cron Job Module.]]></description>
		<lastBuildDate>Mon, 08 Mar 2021 07:43:28 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Cron Job Module]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=39238#p39238</link>
			<description><![CDATA[<p>@joe: There must be a better way to do this by calling it based on last timestamp of call taken from some log file in the <strong>index.php</strong> file itself.</p>]]></description>
			<author><![CDATA[null@example.com (apmuthu)]]></author>
			<pubDate>Mon, 08 Mar 2021 07:43:28 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=39238#p39238</guid>
		</item>
		<item>
			<title><![CDATA[Re: Cron Job Module]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=39229#p39229</link>
			<description><![CDATA[<p>@kvvaradha, thanks, you&#039;re welcome.</p><p>It would be possible to wrap a UI around this to configure and activate the cron job, and then package that as a module</p>]]></description>
			<author><![CDATA[null@example.com (PaulShipley)]]></author>
			<pubDate>Sun, 07 Mar 2021 22:43:43 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=39229#p39229</guid>
		</item>
		<item>
			<title><![CDATA[Re: Cron Job Module]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=39227#p39227</link>
			<description><![CDATA[<p>@PaulShipley ,&nbsp; it&#039;s a great work dude. We can make it as module and available in extension repository.&nbsp; The needy people will use it.</p>]]></description>
			<author><![CDATA[null@example.com (kvvaradha)]]></author>
			<pubDate>Sun, 07 Mar 2021 14:52:13 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=39227#p39227</guid>
		</item>
		<item>
			<title><![CDATA[Re: Cron Job Module]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=39223#p39223</link>
			<description><![CDATA[<p>Based on this post and the wiki (https://frontaccounting.com/fawiki/index.php?n=Devel.CronJobSample), I have written a complete script for updating the exchange rates via cron. Be sure to change the &#039;user&#039; &amp; &#039;password&#039; at the end of the script to a valid account that has FA security to access the Exchange Rates function. Creating a cron entry should be trivial.</p><p>The setup in the first part of the script would be a good template for other batch tasks, though it is not possible to call functions that are expecting a display to be present, which does limit what processes can be performed via cron.</p><p>Hope this helps</p><p>xr_load.php (assuming that this is in FA root directory)</p><p>&lt;?php<br />/**********************************************************************<br />* <br />* Load current day Exchange Rates from external provider using cron<br />* <br />* run using:<br />* cd &lt;fa root dir&gt;<br />* php xr_load.php<br />* <br />***********************************************************************/</p><p>// set environment<br />$path_to_root=&quot;.&quot;;<br />$page_security = &#039;SA_EXCHANGERATE&#039;;</p><br /><p>// configure fake server environment for cron<br />$_SERVER = array();<br />$_SERVER[&#039;REMOTE_ADDR&#039;]=&#039;batch&#039;;<br />$_SERVER[&#039;HTTP_USER_AGENT&#039;]=&#039;cron&#039;;<br />$_SERVER[&#039;REQUEST_URI&#039;]=&#039;&#039;;<br />$_SERVER[&#039;HTTPS&#039;]=&#039;&#039;;<br />define(&#039;FA_LOGOUT_PHP_FILE&#039;, &#039;cronjob&#039;);<br />include_once($path_to_root . &quot;/includes/session.inc&quot;);<br />install_hooks();</p><br /><p>// load rates function<br />include_once($path_to_root . &quot;/includes/date_functions.inc&quot;);<br />include_once($path_to_root . &quot;/includes/banking.inc&quot;);</p><p>/**<br />* <br />* Load Exchange Rates from external provider<br />*<br />* @param {object} $company The FA Company to by loaded<br />* @param {object} $usr&nbsp; &nbsp; &nbsp;FA User<br />* @param {object} $pwd&nbsp; &nbsp; &nbsp;FA Password<br />* <br />* @return<br />* <br />*/<br />function xr_load($company, $usr, $pwd)<br />{<br />&nbsp; &nbsp; global $_SESSION;</p><p>&nbsp; &nbsp; $_SESSION[&#039;wa_current_user&#039;]-&gt;login($company,$usr,$pwd);</p><p>&nbsp; &nbsp; $date_ = Today();</p><p>&nbsp; &nbsp; foreach (get_currencies() as $curr) {<br />&nbsp; &nbsp; &nbsp; &nbsp; $curr_abrev = $curr[&#039;curr_abrev&#039;];</p><p>&nbsp; &nbsp; &nbsp; &nbsp; if (!is_company_currency($curr_abrev)) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $BuyRate = maxprec_format(retrieve_exrate($curr_abrev, $date_));</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (get_date_exchange_rate($curr_abrev, $date_) == 0)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; add_exchange_rate($curr_abrev, $date_, $BuyRate, $BuyRate);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; update_exchange_rate($curr_abrev, $date_, $BuyRate, $BuyRate);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; }<br />}</p><p>// load rates<br />xr_load(0,&#039;user&#039;,password&#039;);</p>]]></description>
			<author><![CDATA[null@example.com (PaulShipley)]]></author>
			<pubDate>Sun, 07 Mar 2021 01:20:49 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=39223#p39223</guid>
		</item>
		<item>
			<title><![CDATA[Re: Cron Job Module]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=35103#p35103</link>
			<description><![CDATA[<p>For such kind of non authorised access you can keep session or for auto exchange rate updates. You can write a custom PHP program to update it on cron job link. When you trigger it with cron job to add. If you have more than one company , use config db file and get each company credentials and update it. Don&#039;t go with FA session and login for cron jobs</p>]]></description>
			<author><![CDATA[null@example.com (kvvaradha)]]></author>
			<pubDate>Tue, 04 Jun 2019 08:10:28 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=35103#p35103</guid>
		</item>
		<item>
			<title><![CDATA[Re: Cron Job Module]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=35094#p35094</link>
			<description><![CDATA[<p>Hi, I have create a link to trigger the automatically update exchange rates but i have no idea on how to set as cron job. Everytime i try to access the link from outside, it will bring me back to the login page. <br />Please provide detail guide is possible. Cuz i am total lost here!</p>]]></description>
			<author><![CDATA[null@example.com (Yan Shuang)]]></author>
			<pubDate>Mon, 03 Jun 2019 08:35:45 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=35094#p35094</guid>
		</item>
		<item>
			<title><![CDATA[Re: Cron Job Module]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=28777#p28777</link>
			<description><![CDATA[<p><strong>construct</strong> should be preceded by 2 underscores(_).</p>]]></description>
			<author><![CDATA[null@example.com (apmuthu)]]></author>
			<pubDate>Fri, 29 Sep 2017 06:48:50 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=28777#p28777</guid>
		</item>
		<item>
			<title><![CDATA[Re: Cron Job Module]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=28773#p28773</link>
			<description><![CDATA[<p>I need more help on this. </p><p>I create a module with hooks.php having the above function _construct()</p><p>I have one more file in module cron.php that contains the code to automatically fetch the exchange rate and update the database of the logged in Company if accessed directly.</p><p>Now when this cron.php is called through cron job then how this function in hooks.php creates a session with the defined user login and password. Credentials are hardcoded in hooks.php</p><p>Please give some guidelines</p>]]></description>
			<author><![CDATA[null@example.com (boxygen)]]></author>
			<pubDate>Fri, 29 Sep 2017 03:42:27 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=28773#p28773</guid>
		</item>
		<item>
			<title><![CDATA[Re: Cron Job Module]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=26776#p26776</link>
			<description><![CDATA[<p>Thanks for the feedback.</p><p><a href="https://frontaccounting.com/fawiki/index.php?n=Devel.CronJobSample">Wiki</a>-ed it.</p>]]></description>
			<author><![CDATA[null@example.com (apmuthu)]]></author>
			<pubDate>Sun, 30 Oct 2016 16:40:27 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=26776#p26776</guid>
		</item>
		<item>
			<title><![CDATA[Re: Cron Job Module]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=26775#p26775</link>
			<description><![CDATA[<p>Thanks for hint, these variables are in hooks.php so I have included it inside hooks.php within Class as constructor and it worked <img src="https://frontaccounting.com/punbb/img/smilies/smile.png" width="15" height="15" alt="smile" /> sample code is below:</p><div class="codebox"><pre><code>    public function __construct() {
        global $_SESSION;
        // if _CJ is defined, login user non interactively
        if (@$cron_request) {
            $_SESSION[&#039;wa_current_user&#039;]-&gt;login($comp, $usr, $pwd);
        }
    }</code></pre></div><p>$cron_request is variable within cron.php file which is server cron accesses.</p>]]></description>
			<author><![CDATA[null@example.com (trecords)]]></author>
			<pubDate>Sun, 30 Oct 2016 15:36:50 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=26775#p26775</guid>
		</item>
		<item>
			<title><![CDATA[Re: Cron Job Module]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=26719#p26719</link>
			<description><![CDATA[<p>Make sure that the cron script has the necessary session values or hard code them into it and keep it beyond your webroot and an appropriately set <strong>$page_security</strong> and <strong>$path_to_root</strong>.</p>]]></description>
			<author><![CDATA[null@example.com (apmuthu)]]></author>
			<pubDate>Sun, 30 Oct 2016 07:26:34 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=26719#p26719</guid>
		</item>
		<item>
			<title><![CDATA[Cron Job Module]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=26662#p26662</link>
			<description><![CDATA[<p>Hi,</p><p>I have created cron job module which will automatically update exchange rates and revalue foreign accounts on daily basis. It works when I am logged in but not when I am off or on cron request. I have created new user ex: cron, and tried to process login process with $_SESSION[&#039;wa_current_user&#039;]-&gt;login function without any luck.</p><p>Can someone instruct me how can I write authorization code better without use of password.</p><br /><p>Regards</p>]]></description>
			<author><![CDATA[null@example.com (trecords)]]></author>
			<pubDate>Sat, 29 Oct 2016 13:19:59 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=26662#p26662</guid>
		</item>
	</channel>
</rss>
