Here is how you can do it, follow steps below:
Create a file custom/Espo/Custom/Resources/metadata/app/scheduledJobs.json:
Create a file custom/Espo/Custom/Jobs/CalculateToplamBorc.php with the content.
Once you complete the steps above, clean cache and rebuild the system and go to administration > Scheduled Jobs and then create schedule job you should be to find your custom job there and just add (Scheduling) and make sure it is active and that is it the job will be executed based on your Scheduling.
Hope this helps
Create a file custom/Espo/Custom/Resources/metadata/app/scheduledJobs.json:
PHP Code:
{
"CalculateToplamBorc": {
"jobClassName": "Espo\\Custom\\Jobs\\CalculateToplamBorc"
}
}
Create a file custom/Espo/Custom/Jobs/CalculateToplamBorc.php with the content.
PHP Code:
<?php
namespace Espo\Custom\Jobs;
use Espo\Core\Job\JobDataLess;
use Espo\Core\ORM\EntityManager;
use Espo\Custom\Entities\Muhasebe;
class CalculateToplamBorc implements JobDataLess
{
public function __construct(
private EntityManager $entityManager
){}
public function run(): void
{
$muhasebeList = $this->entityManager
->getRDBRepository(Muhasebe::ENTITY_TYPE)
->where([
'accountId!=' => null,
])
->find();
foreach ($muhasebeList as $muhasebe) {
$opportunitiesList = $entityManager
->getRDBRepository(Muhasebe::ENTITY_TYPE)
->getRelation($muhasebe, 'opportunities')
->where([
'accountId' => $muhasebe->get('accountId')
])
->order('createdAt', 'DESC')
->findOne();
$total = 0;
foreach ($opportunitiesList as $opportunity) {
$total = $total + $opportunity->get('amount');
}
$muhasebe->set('toplamBorc', $total);
$this->entityManager->saveEntity($muhasebe);
}
}
}
Once you complete the steps above, clean cache and rebuild the system and go to administration > Scheduled Jobs and then create schedule job you should be to find your custom job there and just add (Scheduling) and make sure it is active and that is it the job will be executed based on your Scheduling.
Hope this helps
Comment