Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
gogl92 committed Nov 21, 2017
1 parent c28c281 commit 1fb0ca1
Show file tree
Hide file tree
Showing 3 changed files with 220 additions and 15 deletions.
18 changes: 18 additions & 0 deletions src/HttpClientV3.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace inquid\facturacom;


use app\models\Configuration;
use inquid\facturacom\models\Error;
use Yii;
use yii\base\Component;
Expand All @@ -33,8 +34,25 @@ class HttpClientV3 extends Component

public $apiKey;
public $secretKey;
public $rfc;
public $isSandbox = false;

public function init()
{
if (!isset($this->apiKey) && isset($this->rfc)) {
$key = Configuration::find()->where(['system_type' => 'facturacom_api_key', 'param' => $this->rfc])->select('system_value')->one();
if (isset($key)){
$this->apiKey = $key->system_value;
}

}
if (!isset($this->secretKey) && isset($this->rfc)) {
$secret = Configuration::find()->where(['system_type' => 'facturacom_api_secret', 'param' => $this->rfc])->select('system_value')->one();
if (isset($secret))
$this->secretKey = $secret->system_value;
}
}

/**
* @param string $method
* @param string $path
Expand Down
104 changes: 101 additions & 3 deletions src/models/Conceptos.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
namespace inquid\facturacom\models;


use yii\base\Model;

use app\modules\Facturacion\models\ActiveQuery\ItemsQuery;
use mootensai\relation\RelationTrait;
use yii\behaviors\BlameableBehavior;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
use yii\db\Expression;
/**
* Class Conceptos
* @package inquid\facturacom\models
*/
class Conceptos extends Model
class Conceptos extends ActiveRecord
{
/**
* @var string
Expand Down Expand Up @@ -77,4 +81,98 @@ class Conceptos extends Model
* @var integer
*/
public $Complemento;

use RelationTrait;

/**
* @inheritdoc
*/
public function rules()
{
return [
[['cantidad', 'unidad', 'concepto', 'precio', 'subtotal', 'inq_facturas_id'], 'required'],
[['cantidad', 'siaduana', 'iva', 'iva_ret', 'isr', 'ish', 'iesp', 'inq_facturas_id', 'status', 'created_by', 'updated_by'], 'integer'],
[['unidad'], 'string'],
[['fecha_aduana', 'created_at', 'updated_at'], 'safe'],
[['precio', 'subtotal', 'discount'], 'number'],
[['concepto'], 'string', 'max' => 100],
[['clave'], 'string', 'max' => 25],
[['pedimento_aduana'], 'string', 'max' => 20],
[['locacion_aduana'], 'string', 'max' => 75]
];
}

/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%items}}';
}

/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'clave' => 'Clave',
'cantidad' => 'Cantidad',
'unidad' => 'Unidad',
'concepto' => 'Concepto',
'siaduana' => 'Aplica aduana',
'pedimento_aduana' => 'Pedimento aduanal',
'locacion_aduana' => 'Localización de la aduana',
'fecha_aduana' => 'Fecha de arribo',
'iva' => 'IVA',
'iva_ret' => 'IVA retenido',
'isr' => 'ISR',
'ish' => 'ISH',
'iesp' => 'IESP',
'discount' => 'Descuento',
'precio' => 'Precio',
'subtotal' => 'Subtotal',
'inq_facturas_id' => 'Inq Facturas ID',
'status' => 'Status',
];
}

/**
* @return \yii\db\ActiveQuery
*/
public function getInqFacturas()
{
return $this->hasOne(Facturas::className(), ['id' => 'inq_facturas_id']);
}

/**
* @inheritdoc
* @return array mixed
*/
public function behaviors()
{
return [
'timestamp' => [
'class' => TimestampBehavior::className(),
'createdAtAttribute' => 'created_at',
'updatedAtAttribute' => 'updated_at',
'value' => new Expression('NOW()'),
],
'blameable' => [
'class' => BlameableBehavior::className(),
'createdByAttribute' => 'created_by',
'updatedByAttribute' => 'updated_by',
],
];
}

/**
* @inheritdoc
* @return ItemsQuery the active query used by this AR class.
*/
public static function find()
{
return new ItemsQuery(get_called_class());
}
}
113 changes: 101 additions & 12 deletions src/models/Factura33.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,20 @@
namespace inquid\facturacom\models;


use yii\base\Model;
use app\modules\Facturacion\components\MexicoUtilities;
use app\modules\Facturacion\models\ActiveQuery\FacturasQuery;
use app\modules\Facturacion\models\Items;
use mootensai\relation\RelationTrait;
use yii\behaviors\BlameableBehavior;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
use yii\db\Expression;

/**
* Class Factura33
* @package inquid\facturacom\models
*/
class Factura33 extends Model
class Factura33 extends ActiveRecord
{

/**
Expand Down Expand Up @@ -154,19 +161,101 @@ class Factura33 extends Model
*/
public $Conceptos = [];

/**
* @return array the validation rules.
use RelationTrait;


/**
* @inheritdoc
*/
public function rules()
{
return [
[['Recpetor', 'TipoDocumento', 'UsoCFDI', 'Serie', 'FormaPago', 'MetodoPago', 'Moneda', 'Conceptos'], 'required'],
[['metodopago'], 'integer'],
['Moneda', 'string', 'max' => 3],
[['TipoDocumento', 'UsoCFDI', 'Serie', 'FormaPago', 'MetodoPago', 'CondicionesDePago', 'Moneda', 'Comentarios'], 'string'],
[['EnviarCorreo'], 'boolean'],
[['TipoCambio', 'Serie', 'NumOrder'], 'number'],
['FechaFromAPI', 'date', 'format' => "yyyy-MM-dd'T'HH:mm:ss"]
[['rfc', 'forma_pago', 'metodo_pago', 'num_orden', 'serie_factura', 'send_email', 'exchange_rate', 'currencie'], 'required'],
[['numero_cuenta', 'send_email', 'status', 'iva', 'retencion', 'created_by', 'updated_by'], 'integer'],
[['metodo_pago', 'serie_factura', 'invoice_comment'], 'string'],
[['fecha_cfdi', 'created_at', 'updated_at'], 'safe'],
[['exchange_rate', 'descuento'], 'number'],
[['rfc'], 'match', 'pattern' => MexicoUtilities::RFC_REGEX],
[['forma_pago'], 'string', 'max' => 100],
[['num_orden'], 'string', 'max' => 25]
];
}

/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%factura}}';
}

/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'rfc' => 'Cliente',
'numero_cuenta' => 'Número de cuenta',
'forma_pago' => 'Forma de pago',
'metodo_pago' => 'Metodo de pago',
'currencie' => 'Moneda',
'num_orden' => 'Num Orden',
'serie_factura' => 'Serie de la factura',
'fecha_cfdi' => 'Fecha de Emisión',
'send_email' => 'Enviar email',
'invoice_comment' => 'Comentarios',
'exchange_rate' => 'Tipo de cambio (Pesos)',
'status' => 'Status',
'iva' => 'IVA'
];
}

/**
* @return \yii\db\ActiveQuery
*/
public function getItems()
{
return $this->hasMany(Items::className(), ['inq_facturas_id' => 'id']);
}

/**
* @inheritdoc
* @return array mixed
*/
public function behaviors()
{
return [
'timestamp' => [
'class' => TimestampBehavior::className(),
'createdAtAttribute' => 'created_at',
'updatedAtAttribute' => 'updated_at',
'value' => new Expression('NOW()'),
],
'blameable' => [
'class' => BlameableBehavior::className(),
'createdByAttribute' => 'created_by',
'updatedByAttribute' => 'updated_by',
],
];
}*/
}

/**
* @inheritdoc
* @return FacturasQuery the active query used by this AR class.
*/
public static function find()
{
return new FacturasQuery(get_called_class());
}

/**
* Returns model name with full namespace
* @return string
*/
public function getModelName()
{
return __CLASS__;
}
}

0 comments on commit 1fb0ca1

Please sign in to comment.