File: /var/www/wsklad/app/MobileSaleDocument.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class MobileSaleDocument extends Model
{
protected $fillable = [
'dateCreated',
'docNo',
'tipDoc',
'docType',
'vidDoc',
'vidDostavka',
'payment',
'dateDoc',
'datePadej',
'dateReg',
'dateTaxEvent',
'contragentCode',
'contragentName',
'contragentBulstat',
'contragentDdsId',
'contragentMol',
'contragentAddress',
'place',
'dealPlace',
'deliveryPlace',
'hasTrade',
'receiver',
'totalSum',
'totalDo',
'totalDds',
'totalStoinost',
'totalTrade',
'totalSumWithoutTrade',
'sentToAjur',
'sentToEsklad',
'sentSetExped',
'cashDataSent',
'receiverName',
'fiscalized',
'parentDocNumber',
'parentDocDate',
'parentDocFiscalNumber',
'stornoReason',
'fiscNumber',
'hasStorno',
'distributorCode',
'storeDocNumber',
'dateToMilliseconds',
'confirmed',
'eSkladOperator',
];
protected $table = 'mobile_sale_documents';
public function details()
{
return $this->hasMany('App\MobileSaleDocumentDetail', 'mobilesaledocument_id', 'id');
}
public function contragent_price_list()
{
return $this->hasMany('App\ContragentPriceList', 'kontragent_code', 'contragentCode');
}
public function distributor_price_list()
{
return $this->hasMany('App\ContragentPriceList', 'kontragent_code', 'distributorCode');
}
public function distributor()
{
return $this->hasOne('App\Ajurendpointdistributor', 'F_KONTRAGENT', 'distributorCode');
}
public function paymentMethod()
{
return $this->hasOne('App\Ajurendpointpaymentmethod', 'PAYMENT', 'payment');
}
public function distributorDetails()
{
return $this->hasOne('App\Distributordetail', 'F_KONTRAGENT', 'distributorCode');
}
public function receiverData()
{
return $this->hasOne('App\Ajurendpointreceiver', 'F_KONTRAGENT', 'receiver');
}
public function inMaker()
{
return $this->hasOne('App\User', 'id', 'eSkladOperator');
}
public function syncStatus()
{
return $this->hasMany('App\SyncWithAjurStatus', 'saleId', 'id');
}
public function history()
{
return $this->hasMany('App\MobileSaleDocumentHistory', 'original_id', 'id');
}
public function hasSyncError()
{
return $this->syncStatus()->where('status', 0)->exists();
}
public function getDocTypeNameAttribute()
{
$docTypeNames = [
'invoice' => 'Фактура',
'billOfGoods' => 'Стокова разписка',
'creditNote' => 'Кредитно известие',
'debitNote' => 'Дебитно известие',
];
return $docTypeNames[$this->docType] ?? 'Неизвестен';
}
public static function getDocTypeName($docType)
{
$docTypeNames = [
'invoice' => 'Фактура',
'billOfGoods' => 'Стокова разписка',
'creditNote' => 'Кредитно известие',
'debitNote' => 'Дебитно известие',
];
return $docTypeNames[$docType] ?? 'Неизвестен';
}
protected $appends = [
'docTypeName',
];
protected $casts = [
'payment' => 'string',
];
}