-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #423 from jesusantguerrero/release/alpha-3
Release/alpha 3
- Loading branch information
Showing
51 changed files
with
1,484 additions
and
384 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\DB; | ||
use App\Domains\Loans\Actions\UpdateLatePayments; | ||
use Tests\Feature\CreditCard\Helpers\CreditCardBase; | ||
use App\Domains\Transaction\Services\CreditCardReportService; | ||
|
||
class GenerateBillingCycles extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'bg:generate-billing-cycles {teamId} {date?}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Command description'; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return int | ||
*/ | ||
public function handle(CreditCardReportService $service) | ||
{ | ||
$teamId = $this->argument('teamId'); | ||
$date = $this->argument('date'); | ||
|
||
$monthsWithTransactions = $this->getFirstTransaction($teamId); | ||
return $service->generateBillingCycles($teamId, $date ?? $monthsWithTransactions->date); | ||
} | ||
|
||
private function getFirstTransaction(int $teamId) { | ||
return DB::table('transaction_lines') | ||
->where([ | ||
"team_id" => $teamId | ||
]) | ||
->selectRaw("date_format(transaction_lines.date, '%Y-%m') AS date") | ||
->groupBy(DB::raw("date_format(transaction_lines.date, '%Y-%m')")) | ||
->orderBy('date') | ||
->first(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
<?php | ||
|
||
namespace App\Domains\Integration\Actions\APAP; | ||
|
||
use Exception; | ||
use Illuminate\Support\Facades\Log; | ||
use Symfony\Component\DomCrawler\Crawler; | ||
use App\Domains\Automation\Models\Automation; | ||
use App\Domains\Integration\Actions\GmailReceived; | ||
use App\Domains\Automation\Models\AutomationTaskAction; | ||
use App\Domains\Automation\Concerns\AutomationActionContract; | ||
|
||
class APAP implements AutomationActionContract | ||
{ | ||
const EMAIL_ALERT = '[email protected]'; | ||
const EMAIL_NOTIFICATION = '[email protected]'; | ||
const EMAIL_NOTIFICATION_SUBJECT = "APAP, Notificaciones"; | ||
const EMAIL_BCRD_SUBJECT = "APAP, Pago Al Instante BCRD"; | ||
|
||
public static function handle( | ||
Automation $automation, | ||
mixed $payload, | ||
AutomationTaskAction $task, | ||
AutomationTaskAction $previousTask, | ||
AutomationTaskAction $trigger | ||
) { | ||
$type = self::getMessageType($payload); | ||
try { | ||
$transaction = match ($type) { | ||
'alert' => self::parseAlert($automation, $payload, $task, $previousTask, $trigger), | ||
'notification' => self::parseNotification($automation, $payload, $task, $previousTask, $trigger), | ||
}; | ||
|
||
return $transaction?->toArray(); | ||
} catch (Exception $e) { | ||
dd('hola', $e); | ||
} | ||
|
||
} | ||
|
||
public function getName(): string | ||
{ | ||
return 'APAPMessage'; | ||
} | ||
|
||
public function label(): string | ||
{ | ||
return 'APAP Message'; | ||
} | ||
|
||
public function getDescription(): string | ||
{ | ||
return 'Parse an email alert or notification from Asociacion Popular de Ahorros y Prestamos'; | ||
} | ||
|
||
/** | ||
* Validate and create a new team for the given user. | ||
* | ||
* @param Google_Calendar_Events $calendarEvents | ||
* @return void | ||
*/ | ||
public static function parseAlert( | ||
Automation $automation, | ||
mixed $payload, | ||
AutomationTaskAction $task, | ||
AutomationTaskAction $previousTask, | ||
AutomationTaskAction $trigger | ||
) { | ||
|
||
return (new APAPAlert())->handle($automation, $payload); | ||
} | ||
|
||
/** | ||
* Validate and create a new team for the given user. | ||
* | ||
* @param Google_Calendar_Events $calendarEvents | ||
* @return void | ||
*/ | ||
public static function parseNotification( | ||
Automation $automation, | ||
mixed $payload, | ||
AutomationTaskAction $task, | ||
AutomationTaskAction $previousTask, | ||
AutomationTaskAction $trigger | ||
) { | ||
|
||
return (new APAPAlert())->handle($automation, $payload); | ||
} | ||
|
||
public static function getMessageType($mail) | ||
{ | ||
try { | ||
$body = new Crawler($mail['message']); | ||
$tdValues = $body->filter('[class*=table_trans_body] td')->each(function (Crawler $node) { | ||
return $node->text(); | ||
}); | ||
|
||
return empty($tdValues) ? 'notification' : 'alert'; | ||
} catch (Exception) { | ||
return 'notification'; | ||
} | ||
} | ||
|
||
public static function getConditions() { | ||
return [[ | ||
'conditionType' => GmailReceived::CONDITION_FROM, | ||
'value' => self::EMAIL_ALERT, | ||
], [ | ||
'conditionType' => GmailReceived::CONDITION_SUBJECT, | ||
'value' => self::EMAIL_NOTIFICATION_SUBJECT, | ||
] | ||
]; | ||
} | ||
|
||
public static function parseCurrency($bhdCurrencyCode) | ||
{ | ||
try { | ||
$BHD_CURRENCY_CODES = [ | ||
'USD dólar estadounidense' => 'USD', | ||
'RD' => 'DOP', | ||
]; | ||
|
||
return $BHD_CURRENCY_CODES[$bhdCurrencyCode]; | ||
} catch (Exception $e) { | ||
Log::error($e->getMessage(), [$bhdCurrencyCode]); | ||
} | ||
} | ||
|
||
public static function parseTypes($type) | ||
{ | ||
return 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace App\Domains\Integration\Actions\APAP; | ||
|
||
trait APAPAction | ||
{ | ||
public static function getSchema(): mixed | ||
{ | ||
return [ | ||
'description' => [ | ||
'type' => 'string', | ||
'required' => true, | ||
], | ||
'date' => [ | ||
'type' => 'date', | ||
'label' => 'Date', | ||
|
||
], | ||
'currencyCode' => [ | ||
'type' => 'string', | ||
'label' => 'currencyCode', | ||
'required' => true, | ||
], | ||
'amount' => [ | ||
'type' => 'money', | ||
'label' => 'Amount', | ||
'required' => true, | ||
], | ||
'payee' => [ | ||
'type' => 'string', | ||
'label' => 'Payee', | ||
'required' => true, | ||
], | ||
'categoryGroup' => [ | ||
'type' => 'string', | ||
'label' => 'categoryGroup', | ||
'required' => true, | ||
], | ||
'category' => [ | ||
'type' => 'string', | ||
'label' => 'Category', | ||
'required' => true, | ||
], | ||
]; | ||
} | ||
} |
Oops, something went wrong.