Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sale models #60

Merged
merged 1 commit into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Models/Sale.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,14 @@ public function has_personalization(): int
{
return $this->personalizations()->count();
}

public function periodicities(): HasMany
{
return $this->hasMany(SalePeriodicity::class, 'sale_id');
}

public function crm_credit_process_simulator(): BelongsTo
{
return $this->belongsTo(config('iss-vendas.crm_credit_process_simulator_class'), 'crm_credit_process_simulator_id', 'id');
}
}
153 changes: 153 additions & 0 deletions src/Models/SalePeriodicity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
<?php

namespace Bildvitta\IssVendas\Models;

use Bildvitta\IssVendas\Traits\UsesVendasDB;
use Eloquent;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Carbon;

/**
* App\Models\SalePeriodicity
*
* @property int $id
* @property string $uuid
* @property int $sale_id
* @property string $periodicity
* @property int $installments
* @property float $installment_price
* @property float|null $installment_amount
* @property bool $editable
* @property string|null $payment_method
* @property Carbon $due_at
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
* @property Carbon|null $deleted_at
* @property-read \App\Models\Sale $sale
*
* @method static \Database\Factories\SalePeriodicityFactory factory($count = null, $state = [])
* @method static \Illuminate\Database\Eloquent\Builder|SalePeriodicity newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|SalePeriodicity newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|SalePeriodicity onlyTrashed()
* @method static Builder|BaseModel pagination()
* @method static \Illuminate\Database\Eloquent\Builder|SalePeriodicity query()
* @method static Builder|BaseModel search()
* @method static \Illuminate\Database\Eloquent\Builder|SalePeriodicity whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|SalePeriodicity whereDeletedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|SalePeriodicity whereDueAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|SalePeriodicity whereEditable($value)
* @method static \Illuminate\Database\Eloquent\Builder|SalePeriodicity whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|SalePeriodicity whereInstallmentAmount($value)
* @method static \Illuminate\Database\Eloquent\Builder|SalePeriodicity whereInstallmentPrice($value)
* @method static \Illuminate\Database\Eloquent\Builder|SalePeriodicity whereInstallments($value)
* @method static \Illuminate\Database\Eloquent\Builder|SalePeriodicity wherePaymentMethod($value)
* @method static \Illuminate\Database\Eloquent\Builder|SalePeriodicity wherePeriodicity($value)
* @method static \Illuminate\Database\Eloquent\Builder|SalePeriodicity whereSaleId($value)
* @method static \Illuminate\Database\Eloquent\Builder|SalePeriodicity whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|SalePeriodicity whereUuid($value)
* @method static \Illuminate\Database\Eloquent\Builder|SalePeriodicity withTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|SalePeriodicity withoutTrashed()
*
* @mixin Eloquent
*/
class SalePeriodicity extends Model
{
use SoftDeletes;
use UsesVendasDB;

public const PERIODICITY_LIST = [
// produto
'financing' => 'Financiamento',
'fgts' => 'FGTS',
'subsidy' => 'Subsídio',
'down_payment' => 'Entrada',
'intermediate' => 'Intermediária',
'post_construction' => 'Pós-obra',
'monthly' => 'Mensal',
'bimonthly' => 'Bimestral',
'quarterly' => 'Trimestral',
'semiannual' => 'Semestral',
'yearly' => 'Anual',
'conclusion_balance' => 'Saldo Conclusão',
'conclusion_keys' => 'Conclusão chaves',
//vendas
'signal' => 'Sinal',
'periodicity' => 'Periodicidade',
'final' => 'Final',
'single' => 'Única',
'single_financing' => 'Única - Financiamento',
'vehicle_exchange' => 'Dação em pagamento - Veículo',
'real_estate_development_exchange' => 'Dação em pagamento - Imóvel',
];

/**
* @const array[]
*/
public const PAYMENT_METHOD = [
'bank_slip' => 'Boleto',
'bank' => 'Banco',
'credit_card' => 'Cartão',
];

/*
* 00 - Aguardando Json
* 10 - Processado
* 20 - Baixado
* 30 - Integrado com o Oracle
* 40 - Integrado com o Mega
* 80 - Cancelado
* 99 - Processado com Erro
*/
public const PERIODICITY_STATUS_FROM_MEGA = [
'0' => [
'label' => 'Não gerado',
'value' => 'not-generated',
],
'10' => [
'label' => 'Em aberto',
'value' => 'is-open',
],
'20' => [
'label' => 'Pago',
'value' => 'paid',
],
'80' => [
'label' => 'Cancelado',
'value' => 'canceled',
],
'99' => [
'label' => 'Não gerado',
'value' => 'not-generated',
],
'unknown' => [
'label' => 'Desconhecido',
'value' => 'unknown',
],
];

protected $fillable = [
'uuid',
'proposal_model_id',
'periodicity',
'installments',
'installment_price',
'installment_amount',
'due_at',
'editable',
'payment_method',
];

protected $casts = [
'due_at' => 'date:Y-m-d',
'installment_amount' => 'real',
'editable' => 'boolean',
];

public function sale(): BelongsTo
{
return $this->belongsTo(Sale::class);
}
}
Loading