<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[FrontAccounting forum — Cron Job Module]]></title>
	<link rel="self" href="https://frontaccounting.com/punbb/extern.php?action=feed&amp;tid=6536&amp;type=atom" />
	<updated>2021-03-08T07:43:28Z</updated>
	<generator>PunBB</generator>
	<id>https://frontaccounting.com/punbb/viewtopic.php?id=6536</id>
		<entry>
			<title type="html"><![CDATA[Re: Cron Job Module]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=39238#p39238" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2021-03-08T07:43:28Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=39238#p39238</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Cron Job Module]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=39229#p39229" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[PaulShipley]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=20029</uri>
			</author>
			<updated>2021-03-07T22:43:43Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=39229#p39229</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Cron Job Module]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=39227#p39227" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[kvvaradha]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=19348</uri>
			</author>
			<updated>2021-03-07T14:52:13Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=39227#p39227</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Cron Job Module]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=39223#p39223" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[PaulShipley]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=20029</uri>
			</author>
			<updated>2021-03-07T01:20:49Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=39223#p39223</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Cron Job Module]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=35103#p35103" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[kvvaradha]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=19348</uri>
			</author>
			<updated>2019-06-04T08:10:28Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=35103#p35103</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Cron Job Module]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=35094#p35094" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[Yan Shuang]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=40844</uri>
			</author>
			<updated>2019-06-03T08:35:45Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=35094#p35094</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Cron Job Module]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=28777#p28777" />
			<content type="html"><![CDATA[<p><strong>construct</strong> should be preceded by 2 underscores(_).</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2017-09-29T06:48:50Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=28777#p28777</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Cron Job Module]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=28773#p28773" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[boxygen]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=20175</uri>
			</author>
			<updated>2017-09-29T03:42:27Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=28773#p28773</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Cron Job Module]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=26776#p26776" />
			<content type="html"><![CDATA[<p>Thanks for the feedback.</p><p><a href="https://frontaccounting.com/fawiki/index.php?n=Devel.CronJobSample">Wiki</a>-ed it.</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2016-10-30T16:40:27Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=26776#p26776</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Cron Job Module]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=26775#p26775" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[trecords]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=19435</uri>
			</author>
			<updated>2016-10-30T15:36:50Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=26775#p26775</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Cron Job Module]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=26719#p26719" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2016-10-30T07:26:34Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=26719#p26719</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Cron Job Module]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=26662#p26662" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[trecords]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=19435</uri>
			</author>
			<updated>2016-10-29T13:19:59Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=26662#p26662</id>
		</entry>
</feed>
